Message Boards Message Boards

0
|
3936 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to Create a Function In Two Variables With a Domain Restriction?

Posted 10 years ago

Hello everybody! I'm a novice Mathematica user, and I have a problem I'd like to get some help plugging into Mathematica. I'm rewriting a function that is in terms of (x, y) coordinates in terms of the angle those coordinates form instead, and I am able to put the function into Mathematica and plug in values one at a time. However, I'd like to be able to view the results of the function when hundreds of values are plugged in, in order to see what value(s) it approaches. The problem is that I don't know how to express in terms Mathematica can understand the fact that, when plugging values into this function, 2y>x and x?y. For neatness' sake, I'd also like to be able to arrange the values plugged into the function and the resulting output values into a table, if that's not impossible as well.

This is what I've come up with so far, but the values of x and y are not restricted as I'd like. Also, the table isn't good at showing what output values correspond to what input values. {Table[ArcTan[(y*Sqrt[3])/(2*x + y)], {x, 10}], {y, 10}}

Any help that you can provide would be fantastic. Thank you so much!

POSTED BY: Griffin Glenn
4 Replies
Posted 10 years ago

Ah, far far more helpful, That Excel sheet was just what was needed to see exactly how you wanted the result presented.

I think this does it

data = Select[Flatten[Table[{x, y}, {x, 1, 10}, {y, 1, 10}], 1], ({x, y} = #; 2*y > x && x >= y)&];
MatrixForm[ Map[{{x, y} = #; x, y, ArcTan[(y*Sqrt[3])/(2*x+y)], N[ArcTan[(y*Sqrt[3])/(2*x+y)]]}&, data]]

If you run that you should see it almost duplicates what you want. It doesn't provide the header across the top. I tried and failed with that.

The first line makes up all possible x,y pairs and then selects only those that satisfy your conditions.

The second line builds each row of your table and then uses MatrixForm to nicely line them up. Be careful if you use MatrixForm in the future, it makes a nice display, but you can't do any calculations with the result of a MatrixForm.

The # and & notation can be confusing, but that is a Mathematica shortcut for defining and using quick little one time functions. Each # in that is going to be an x,y pair. Select and Map go through all the pairs, one at a time.

You can "take that apart" to learn how it works. Just do the Table and look carefully at what it does. Then the Flatten[Table... and see how it changes. Then study the stuff at the end of the Select, try changing it a bit at a time and see if you can understand how to use that in the future for other problems. Look up the functions in the help system and try to figure out how that relates to this example.

POSTED BY: Bill Simpson
Posted 10 years ago

If you can show an example of a couple of your input values, probably best as data={{x1,y1},{x2,y2}}, more if needed to really show the various special cases that need to be handled, and then an example of what you want the output to look like then it might be fairly easy to craft up something to do that. You might also look at the documentation for ArcTan. There is an ArcTan[y/x] form and an ArcTan[y,x] form. The second form can sometimes avoid confusion about angles when one or both of x and y are negative.

So, imagine you are writing up a project proposal for someone who doesn't know all the stuff in your head, hasn't been watching you work on this and who can then take that description away, finish the project without needing to bring it back, find it is wrong, start over, ask more questions, etc, etc, etc, do it once and have it be just what you are looking for.

POSTED BY: Bill Simpson
Posted 10 years ago

data={{1,1},{2,2},{3,2},{3,3},{4,3},{4,4},{5,3},{5,4},{5,5}

Is the above somewhat more clear? x and y are always going to be positive, as well, and the above data points are the type of thing that I'd like to plug in, where 2y>x and x?y. The attached file is also a pretty direct demonstration of the type of table I'd be most interested in seeing. Does this make what I'm looking for a bit more clear? Thank you!

Attachments:
POSTED BY: Griffin Glenn
Posted 10 years ago

This is excellent, and I'll definitely be taking it apart in order to further my own understanding. Thank you so much for taking the time to help this beginner out.

POSTED BY: Griffin Glenn
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract