MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to choose real positive solutions?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74326] Re: How to choose real positive solutions?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 18 Mar 2007 00:55:00 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <etg46h$ijg$1@smc.vnet.net>

mandix wrote:
> Hi,
> suppose I want to solve a system of 3 equations and 3 unknowns
> (polynomial of degree whatever, say n). Is there a way to tell NSolve
> to return only real and positive solutions (and ignore the rest)?

You cannot. However, you case use Mathematica pattern matching 
capabilities to extract whatever you want from the solutions returned by 
NSolve. For instance,

In[1]:=
eqns = {x^5 + y^2 + z == 1, 2*x + y - z == 2, x - 3*y + z == 3};
sols = NSolve[eqns, {x, y, z}]

Out[2]=
{{x\[Rule]-1.69511, y\[Rule]-5.04267,z\[Rule]-10.4329},
{x\[Rule]0.24097 + 1.42038 I, y\[Rule] -2.13854 + 2.13058 I, z\[Rule] 
-3.6566 + 4.97134 I},
{x\[Rule] 0.24097 - 1.42038 I, y\[Rule] -2.13854 - 2.13058 I, z\[Rule] 
-3.6566 - 4.97134 I},
{x\[Rule] 1., y\[Rule] -1., z\[Rule] -1.},
{x\[Rule] 0.213171, y\[Rule] -2.18024, z\[Rule] -3.7539}}

In[3]:=
(* We want the three variables negative *)
Cases[sols, {x_ -> xval_Real /; xval < 0, y_ -> yval_Real /; yval < 0,
    z_ -> zval_Real /; zval < 0}]

Out[4]=
{{x\[Rule]-1.69511, y\[Rule]-5.04267, z\[Rule]-10.4329}}

In[5]:=
(* We want the first variable positive and the other two negative *)
Cases[sols, {x_ -> xval_Real /; xval > 0, y_ -> yval_Real /; yval < 0,
    z_ -> zval_Real /; zval < 0}]

Out[6]=
{{x\[Rule]1., y\[Rule]-1., z\[Rule]-1.},
{x\[Rule]0.213171, y\[Rule]-2.18024, z\[Rule]-3.7539}}

HTH,
Jean-Marc


  • Prev by Date: Re: Mathematica 4.0
  • Next by Date: RE: Re: Animate command on ListPlot:
  • Previous by thread: Re: How to choose real positive solutions?
  • Next by thread: (more in) Integrate