MathGroup Archive 2003

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

Search the Archive

Re: Emergent Help: NSolve Problems!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg39787] Re: [mg39753] Emergent Help: NSolve Problems!
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Fri, 7 Mar 2003 03:32:05 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On Thursday, March 6, 2003, at 02:35 AM, Chengzhou Wang wrote:

> Hi, guys
>
> I have some complicated polynomials, and I want to calculate its roots.
> HOwever, when I use NSolve, it creates some problems. Say a simple
> example:
>
> temp[s_]=s^10+10 s^9+ 10 s^8 +10 s^7 +10 s^6+ 10 s^5 +10 s^4 +1;
> NSolve[temp[s]==0, s]
>
> It will give:
>
> Out[4]= {{s -> -8.99998}, {s -> -1.06539}, {s -> -0.468828 - 0.886239 
> I},
>
>>    {s -> -0.468828 + 0.886239 I}, {s -> -0.409684 - 0.469948 I},
>
>>    {s -> -0.409684 + 0.469948 I}, {s -> 0.401048 - 0.312597 I},
>
>>    {s -> 0.401048 + 0.312597 I}, {s -> 0.51015 - 0.878693 I},
>
>>    {s -> 0.51015 + 0.878693 I}}
>
> But when I plug in the first number, which is "-8.99998", it should 
> give a
> value close to zero. However, it gives:
>
> In[5]:= temp[-8.99998]
> Out[5]= -411.473
>
> The other roots seems OK. Does anyone know why? This is just a simple
> example. I have some more complicated polynomials to deal with.
>
> Thanks in advance!
>
>

You are running into machine precisions problems, the output formatting 
that Mathematica does means that {s->-8.99998} does not necessarily 
equal the value when you enter -8.99998.  If you save the result from 
NSolve and use Replace you'll get:

In[91]:=
f[s_]:=s^10+10 s^9+ 10 s^8 +10 s^7 +10 s^6+ 10 s^5 +10 s^4 +1
sols=NSolve[f[s]==0,s]
f[s]/.sols
Out[92]=
{{s->-8.99998},{s->-1.06539},{s->-0.468828-0.886239
I},{s->-0.468828+0.886239
I},{s->-0.409684-0.469948
I},{s->-0.409684+0.469948 I},{s->0.401048
-0.312597
I},{s->0.401048+0.312597 I},{s
->0.51015-0.878693 I},{s->0.51015
+0.878693 I}}
Out[93]=
({-9.5367431640625`*^-7, -2.886579864025407`*^-15,
     7.216449660063518`*^-16 + 1.7763568394002505`*^-15 I,
     7.216449660063518`*^-16 - 1.7763568394002505`*^-15 I,
     1.682681771697503`*^-16 + 1.214306433183765`*^-16 I,
     1.682681771697503`*^-16 -
       1.214306433183765`*^-16 I, -2.398255205537936`*^-16 +
       3.3832528792410166`*^-16 I, -2.398255205537936`*^-16 -
       3.3832528792410166`*^-16 I, -5.218048215738236`*^-15 +
       4.218847493575595`*^-15 I, -5.218048215738236`*^-15 -
       4.218847493575595`*^-15 I}

If you want to see more digits in the result from NSolce use 
NSolve[f[s]==0,s,n] where n is the number of digits you wish to use.  
At any rate you are probably going to have problems with machine 
precision values if you work with polynomials of high degree.

Regards,

Ssezi



  • Prev by Date: Re: Mathlink problem with binary.tm in Linux
  • Next by Date: Re: Emergent Help: NSolve Problems!
  • Previous by thread: Re: Emergent Help: NSolve Problems!
  • Next by thread: Re: Emergent Help: NSolve Problems!