4

Lets say I have an equation - x^2+y^2=100 - obviously there's more than one solution.
I want to make Mathematica 8 give me the solution (where only natural numbers involved) where x will be maximized (i.e x=10, y=0)
I'm pretty new to Mathematica - and got really confused with whats going on...

Mark Segal
  • 5,427
  • 4
  • 31
  • 69
  • How important is learning the process in Mathematica vs. getting the answer? The people that make Mathematica also make Wolfram Alpha, and if you simply type that equation into Wolfram Alpha, it will list all integer solutions for you (from which the one that maximizes x is obvious). Not sure if that helps or not... – Michael McGowan Jul 20 '11 at 20:26
  • well I got all the solutions using Reduce - what do I do with it ? – Mark Segal Jul 20 '11 at 20:48

1 Answers1

4

Without the Diophantine explicit requierment:

Maximize[{x , x^2 + y^2 == 100}, {x, y}]
(*
-> {10, {x -> 10, y -> 0}}
*)

Edit

As you can see, the result is a two elements list. The first element (10) is the value for x (the function for which the maximization is performed). The second element is {x -> 10, y -> 0}, corresponding to the assignment rules for the variables at the max point.

Note that here we are maximizing x, so the value 10 is repeated in both elements, but that is not always the case, as we usually want to maximize a general function of the variables, and not the vars themselves.

In this particular case, we have two straightforward ways to assign the max value of x to n:

Using the first element of the list:

n = First@Maximize[{x , x^2 + y^2 == 100}, {x, y}]  

Or more general, using the appropriate rule:

n = x /. Last@Maximize[{x, x^2 + y^2 == 100}, {x, y}]
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • Ok - thanks. But how can I convert from - "x==10" to 10? I mean I have n = x==10 && y==0, then I used n = Extract[n, 1] and now n= x==10, how can I convert it to 10 ? – Mark Segal Jul 20 '11 at 21:09
  • 1
    @Quantic `n = x /. Last@Maximize[{x, x^2 + y^2 == 100}, {x, y}]` – Dr. belisarius Jul 20 '11 at 21:29