Re: Re: Possible bug in NSolve[equation, variable, precission]

• To: mathgroup at smc.vnet.net
• Subject: [mg74339] Re: [mg74308] Re: Possible bug in NSolve[equation, variable, precission]
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Mon, 19 Mar 2007 02:02:07 -0500 (EST)
• References: <etg4m9\$ioi\$1@smc.vnet.net> <200703180545.AAA19388@smc.vnet.net>

```On 18 Mar 2007, at 06:45, dimitris wrote:

> Why use NSolve in your equation? Use Solve instead!

If you mean only this particular equation your advice is reasonable.
But for all polynomial equations it is not; for polynomial equations
of large degree you will significant difference in performance
between NSolve and Solve. Try for example this (random) exmple.

eq = x^201 + 245*x^100 - 77*x^50 - 23*x^17 +
11*x^16 - 7*x^4 + x^3 - 2*x^2 - 25 == 0;

On my 1 gigahertz PowerBook NSolve[eq,20] takes under 23 seconds but N
[Solve[eq==0,x],20] takes over 72. The difference in perfomance
should be even more striking for systems of polynomial equations
involving polynomials of high degree. For equations and systems of
small(ish) degree I think Solve is is preferable.

Andrzej Kozlowski

>
>
> In[1]:=
> Clear["Global`*"]
> Print[StyleForm["working version", FontColor -> Blue]]
> \$Version
> Print[StyleForm["your polynomial", FontColor -> Blue]]
> poly = 171142046150220198693105489 - 16023210221608713837587916*x -
> 2020825892011586434364754*x^2 +
>    190894692033395024364972*x^3 + 6039743423966949379761*x^4 -
> 568929229651998950400*x^5 - 470066550477520896*x^6 +
>    2821109907456*x^7
> Print[StyleForm["your second polynomial", FontColor -> Blue]]
> poly2 = Expand[poly/9]
> Print[StyleForm["solution of the equation poly=0", FontColor -> Blue]]
> Timing[sols = Solve[poly == 0, x]]
> Print[StyleForm["solution of the equation poly2=0", FontColor ->
> Blue]]
> Timing[sols2 = Solve[poly == 0, x]]
> Print[StyleForm["numerical approximation with 20 digits precision",
> FontColor -> Blue]]
> (N[#1, 20] & )[x /. sols]
> (N[#1, 20] & )[x /. sols2]
> Print[StyleForm["numerical approximation with 100 digits precision",
> FontColor -> Blue]]
> (N[#1, 100] & )[x /. sols]
> (N[#1, 100] & )[x /. sols2]
>
>
> Regards
> Dimitris
>
>
> Julian Aguirre wrote:
>> Dear group,
>>
>> Mathematica 5.2 chokes solving numerically a polynomial equation.
>>
>> In[1] := \$Version
>> Out[1]= 5.2 for Mac OS X (64 bit) (June 20, 2005)
>>
>> In[2]:= poly=171142046150220198693105489-16023210221608713837587916
>> x-2020825892011586434364754 x^2+190894692033395024364972
>> x^3+6039743423966949379761 x^4-568929229651998950400
>> x^5-470066550477520896 x^6+2821109907456 x^7;
>>
>> In[3]:= poly2=Expand[poly/9];
>>
>> In[4]:= NSolve[poly==0,x]
>> Out[4]= {-1211.83, -13.0015, -13.0014, 11.923, 12.0809, 12.2509,
>> 167826.}
>>
>> (* Up to this moment, everything is O.K. But *)
>>
>> In[5]:= NSolve[poly==0,x,20]
>> Out[5]= \$Aborted (* after a loooong time *)
>>
>> (* However, the following works as expected*)
>>
>> In[6]:= x/.NSolve[poly2==0,x,20]
>> Out[6]= {-1211.8267955098487289, -13.001455891126, -13.001441554521,
>> 11.92303189062617, 12.08089051352363, 12.25087466630727,
>> 167826.26017849924816}
>>
>> Let me say that I have used Mathematica to solve thousands (probably
>> millions) of equations like the one above. There must be some
>> magic in
>> the coefficients!
>>
>> Julian Aguirre
>> University of the Basque Country
>
>

```

• Prev by Date: Re: Possible bug in NSolve[equation, variable, precission]
• Next by Date: computing total[ragged array] fast
• Previous by thread: Re: Possible bug in NSolve[equation, variable, precission]
• Next by thread: Re: Possible bug in NSolve[equation, variable, precission]