[Date Index]
[Thread Index]
[Author Index]
Re: How can I make the NSolve output the roots meeting
*To*: mathgroup at smc.vnet.net
*Subject*: [mg86462] Re: [mg86446] How can I make the NSolve output the roots meeting
*From*: Daniel Lichtblau <danl at wolfram.com>
*Date*: Wed, 12 Mar 2008 00:09:58 -0500 (EST)
*References*: <200803110801.DAA25007@smc.vnet.net>
Elements wrote:
> Hi everyone,
> I'm dealing with an equation with NSolve, and there are many roots
> of this equation, but I only need the roots which a real and positive.
> So which function or option should I choose?
> Thanks!
Most reliable would be to post process using, say, Select or maybe Cases.
NSolve has a built in capability, entirely undocumented, that can also
be used. But there is no guarantee it will remain from one version to
another. It lives in Internal` context.
SelectCriterion::usage =
"SelectCriterion is an option for NSolve that determines whether
to keep or discard a root in any variable. The value provided
should be a pure function. It will be applied to the pair
{var, candidate value} to determine whether to keep or discard
that value. Hence one can use different criteria for different
variables, provided these criteria are independent of one another."
Quick example:
In[8]:= NSolve[{x^3-2*x*y-4==0,y^3-3*x*y^2-4*x^2+7==0}, {x,y}]
Out[8]= {{x -> 6.23339, y -> 19.1067},
{x -> -1.35984 - 1.14053 I, y -> 1.13758 + 0.826794 I},
{x -> -1.35984 + 1.14053 I, y -> 1.13758 - 0.826794 I},
{x -> -0.18174 + 0.678448 I, y -> 0.52317 + 2.62723 I},
{x -> -0.18174 - 0.678448 I, y -> 0.52317 - 2.62723 I},
{x -> 0.0492886 - 1.83995 I, y -> -1.72058 - 1.1769 I},
{x -> 0.0492886 + 1.83995 I, y -> -1.72058 + 1.1769 I},
{x -> 1.3756 + 0.240822 I, y -> -0.493535 + 0.578238 I},
{x -> 1.3756 - 0.240822 I, y -> -0.493535 - 0.578238 I}}
In[9]:= NSolve[{x^3-2*x*y-4==0,y^3-3*x*y^2-4*x^2+7==0}, {x,y},
Internal`SelectCriterion->(Im[#[[2]]]==0 && Re[#[[2]]]>=0&)]
Out[9]= {{x -> 6.23339, y -> 19.1067}}
From the way NSolve works, there is almost never any speed advantage to
be had by using this option. It's just a convenience.
Daniel Lichtblau
Wolfram Research
Prev by Date:
**Re: Update 6.0.2**
Next by Date:
**Re: Path to *.m file**
Previous by thread:
**How can I make the NSolve output the roots meeting the constraint conditions?**
Next by thread:
**Update 6.0.2**
| |