Group Abstract Group Abstract

Message Boards Message Boards

0
|
5K 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 12 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 12 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
Posted 12 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 12 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 12 years ago
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard