Lets say I have an equation - x^2+y^2=100 - obviously开发者_JAVA百科 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...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}]
精彩评论