Discussion:
Beware of NSolve
(too old to reply)
Carlos Felippa
2004-08-18 05:39:35 UTC
Permalink
Run v. 4.2 on Mac:

f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 - 108*x]);

Solve[f==0,x] returns 2 real roots:

{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}

NSolve[f==0,x] returns 4 real roots:

{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}

Roots 1 and 4 are incorrect. (Just plot f)

Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Florian Jaccard
2004-08-18 08:35:19 UTC
Permalink
Very interesting... thank you to have taken time to show this.
It is a good example to show some dangers...

In fact, the Help browser says the following :

?NSolve

"NSolve[lhs==rhs, var] gives a list of numerical approximations to the roots
of a polynomial equation...."

Your equation is not polynomial, so NSolve is not really the best way to
solve it.

As the equation is not complicated, Solve should manage...
And it does :

N[Solve[f == 0, x]]

{{x -> -0.014126116704662368},
{x -> 0.0028165928951385567}}


Greetings

F.Jaccard


-----Message d'origine-----
De : Carlos Felippa [mailto:***@colorado.edu]
Envoyé : mercredi, 18. août 2004 07:20
À : ***@smc.vnet.net
Objet : Beware of NSolve

Run v. 4.2 on Mac:

f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 - 108*x]);

Solve[f==0,x] returns 2 real roots:

{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}

NSolve[f==0,x] returns 4 real roots:

{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}

Roots 1 and 4 are incorrect. (Just plot f)

Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Andrzej Kozlowski
2004-08-18 08:36:20 UTC
Permalink
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 -
108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 +
25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
In this case as in many others involving numerical compoutations it is
just the question of the working precision. This is just a "fact of
life" of numerical mathematics


f = 5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) +
x/(2*Sqrt[38/35 - 108*x]);


NSolve[f == 0, x]

Out[25]=
{{x -> -0.1048108296114584},
{x -> -0.014126116704662336},
{x -> 0.0028165928951385585},
{x -> 0.0003796126802330329}}


but


NSolve[f == 0, x, WorkingPrecision -> 100]


{{x -> -0.01412611670466236638824490631656833001879549658\
023713039810018063813686176066910885658666635943993612512\
76942823094`99.69897000433602},
{x -> 0.00281659289513855686443538250704452049498597277\
071332087429065682861305223685958504706285683563041231560\
38847579695`99.69897000433602}}




Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
Carlos Felippa
2004-08-19 10:52:14 UTC
Permalink
Post by Andrzej Kozlowski
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 -
108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 +
25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
In this case as in many others involving numerical compoutations it is
just the question of the working precision. This is just a "fact of
life" of numerical mathematics
f = 5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) +
x/(2*Sqrt[38/35 - 108*x]);
NSolve[f == 0, x]
Out[25]=
{{x -> -0.1048108296114584},
{x -> -0.014126116704662336},
{x -> 0.0028165928951385585},
{x -> 0.0003796126802330329}}
but
NSolve[f == 0, x, WorkingPrecision -> 100]
{{x -> -0.01412611670466236638824490631656833001879549658\
023713039810018063813686176066910885658666635943993612512\
76942823094`99.69897000433602},
{x -> 0.00281659289513855686443538250704452049498597277\
071332087429065682861305223685958504706285683563041231560\
38847579695`99.69897000433602}}
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
Yes, precision is the evil of all roots. Here is a tiny variation on my
example:

f=5/432-11/(27*Sqrt[70]*Sqrt[19-1890*x])+x/(2*Sqrt[38/35-(108+1/100)*x]);
Print[NSolve[f,x,16]]; (* gives 6 roots *)
Print[NSolve[f,x,24]]; (* gives 4 roots *)
Print[NSolve[f,x,32]]; (* gives 2 roots *)
Print[NSolve[f,x,64]]; (* gives 3 roots *)

(Please DONT e-mail to my address)
paul
2004-08-19 10:53:26 UTC
Permalink
excellent point, by the way, only 31 units of precision would have been
sufficient too:
In[12]:=
NSolve[f == 0, x, WorkingPrecision -> 31]

Out[12]=
{{x -> -0.01412611670466236638824490631657}, {x ->
0.002816592895138556864435382507045}}

thanks,
Post by Andrzej Kozlowski
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 -
108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 +
25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
In this case as in many others involving numerical compoutations it is
just the question of the working precision. This is just a "fact of
life" of numerical mathematics
f = 5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) +
x/(2*Sqrt[38/35 - 108*x]);
NSolve[f == 0, x]
Out[25]=
{{x -> -0.1048108296114584},
{x -> -0.014126116704662336},
{x -> 0.0028165928951385585},
{x -> 0.0003796126802330329}}
but
NSolve[f == 0, x, WorkingPrecision -> 100]
{{x -> -0.01412611670466236638824490631656833001879549658\
023713039810018063813686176066910885658666635943993612512\
76942823094`99.69897000433602},
{x -> 0.00281659289513855686443538250704452049498597277\
071332087429065682861305223685958504706285683563041231560\
38847579695`99.69897000433602}}
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
Kevin J. McCann
2004-08-19 10:36:13 UTC
Permalink
It is not clear to me why the extraneous roots are found. However, if
you set WorkingPrecision->40 in NSolve, you only get the two correct roots.

Kevin
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 - 108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Bob Hanlon
2004-08-19 10:38:15 UTC
Permalink
Same results with version 5.0.1 on a Mac; however, using higher precision
corrected this:

NSolve[f==0,x,WorkingPrecision->35]

{
{x ->
-0.014126116704662366388244906316568330018795496579`3\
4.69897000433602},
{x -> 0.00281659289513855686443538250704452049498597276\
8`34.69897000433602}}


Bob Hanlon
Date: 2004/08/18 Wed AM 01:20:19 EDT
Subject: Beware of NSolve
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 -
108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Murray Eisenberg
2004-08-19 10:43:53 UTC
Permalink
But:

NSolve[f == 0, x, WorkingPrecision -> 32]
{{x -> -0.014126116704662366388244906316568},
{x -> 0.0028165928951385568644353825070445}}
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 - 108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
--
Murray Eisenberg ***@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
Janos D. Pinter
2004-08-20 08:59:27 UTC
Permalink
Optimization tools (NMInimize, MathOptimizer /Pro,...) can be used to
sequentially find numerical solutions in pre-set boxes for the vars. I just
checked this using MathOptimizer Pro that finds the correct solns in [-1,
1], and reports no feas solns after that.

Janos D. Pinter
Post by Bob Hanlon
Same results with version 5.0.1 on a Mac; however, using higher precision
NSolve[f==0,x,WorkingPrecision->35]
{
{x ->
-0.014126116704662366388244906316568330018795496579`3\
4.69897000433602},
{x -> 0.00281659289513855686443538250704452049498597276\
8`34.69897000433602}}
Bob Hanlon
Date: 2004/08/18 Wed AM 01:20:19 EDT
Subject: Beware of NSolve
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 -
108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Narasimham G.L.
2004-08-23 10:42:01 UTC
Permalink
Old version 2.2 does not report roots 1 and 4 by NSolve. May be later
on improvements (complex roots) have associated problems, may be
elimination of extraneous roots by plotting is a necessary check.
Post by Carlos Felippa
f=5/432 - 11/(27*Sqrt[70]*Sqrt[19 - 1890*x]) + x/(2*Sqrt[38/35 - 108*x]);
{{x -> (-171 - 25*Sqrt[105])/30240}, {x -> (-171 + 25*Sqrt[105])/30240}}
{{x -> -0.10481082961146104}, {x -> -0.014126116704662378},
{x -> 0.002816592895138556}, {x -> 0.0003796126802330315}}
Roots 1 and 4 are incorrect. (Just plot f)
Had a similar problem with a quartic 3 months ago. This is a
simpler example.
Loading...