简体   繁体   中英

How can I solve an equation with two variables where x is maximum?

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 (ie 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}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM