[英]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.假设我有一个方程 - x^2+y^2=100 - 显然有不止一个解决方案。
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)我想让 Mathematica 8 给我一个解决方案(只涉及自然数),其中 x 将被最大化(即 x=10,y=0)
I'm pretty new to Mathematica - and got really confused with whats going on...我对 Mathematica 很陌生 - 并且对正在发生的事情感到非常困惑......
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).第一个元素 ( 10
) 是x
的值(对其执行最大化的 function)。 The second element is {x -> 10, y -> 0}
, corresponding to the assignment rules for the variables at the max point.第二个元素是{x -> 10, y -> 0}
,对应于最大值点处变量的赋值规则。
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.请注意,这里我们最大化x
,因此值10
在两个元素中重复,但情况并非总是如此,因为我们通常希望最大化变量的一般 function,而不是变量本身。
In this particular case, we have two straightforward ways to assign the max value of x
to n
:在这种特殊情况下,我们有两种直接的方法将x
的最大值分配给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}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.