[Date Index]
[Thread Index]
[Author Index]
Re: Emergent Help: NSolve Problems!
*To*: mathgroup at smc.vnet.net
*Subject*: [mg39781] Re: [mg39753] Emergent Help: NSolve Problems!
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Fri, 7 Mar 2003 03:31:19 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
Let me first explain how you should do this sort of thing, and then why
you got your strange problem.
Here is the natural way to solve your equation and verify solutions:
In[1]:=
temp[s_] = s^10 + 10*s^9 + 10*s^8 + 10*s^7 + 10*s^6 +
10*s^5 + 10*s^4 + 1;
In[2]:=
sols = NSolve[temp[s] == 0, s]
Out[2]=
{{s -> -8.999981180131652}, {s -> -1.0653891185497242},
{s -> -0.4688280614863414 - 0.8862391397094913*I},
{s -> -0.4688280614863414 + 0.8862391397094913*I},
{s -> -0.4096838961924677 - 0.46994830628745526*I},
{s -> -0.4096838961924677 + 0.46994830628745526*I},
{s -> 0.4010475038405945 - 0.3125967760434639*I},
{s -> 0.4010475038405945 + 0.3125967760434639*I},
{s -> 0.5101496031789036 - 0.8786933507160907*I},
{s -> 0.5101496031789036 + 0.8786933507160907*I}}
In[3]:=
Chop[temp[s] /. sols]
Out[3]=
{-9.5367431640625*^-7, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Chop is needed to get rid of tiny imaginary parts that NSolve often
(quite correctly!) produces in such cases. As you see, substituting the
first root returns a small number but not sufficiently close to 0 for
Mathematica to represent it as such. The problem is that the graph of
the function is nearly vertical in the neighbourhood of this root, so
small changes in the value of s will cause big changes in the values of
f[s]. If we use more precision we can get a more satisfactory answer:
In[4]:=
sols = NSolve[temp[s] == 0, s, WorkingPrecision -> 20]
Out[4]=
{{s -> -8.999981180131654099939548143087365`19.5562},
{s -> -1.065389118549724124278194976082666`19.3865},
{s -> -0.46882806148634128751612222287947`19.1653 -
0.886239139709491347132385425552478`19.4418*I},
{s -> -0.46882806148634128751612222287947`19.1653 +
0.886239139709491347132385425552478`19.4418*I},
{s -> -0.409683896192467719586437750959655`19.446 -
0.469948306287455317085959897085235`19.5056*I},
{s -> -0.409683896192467719586437750959655`19.446 +
0.469948306287455317085959897085235`19.5056*I},
{s -> 0.401047503840594510026502154382282`19.8771 -
0.312596776043463878012674759908029`19.7689*I},
{s -> 0.401047503840594510026502154382282`19.8771 +
0.312596776043463878012674759908029`19.7689*I},
{s -> 0.510149603178903609184929379060869`19.5456 -
0.878693350716090655852767849544973`19.7817*I},
{s -> 0.510149603178903609184929379060869`19.5456 +
0.878693350716090655852767849544973`19.7817*I}}
In[5]:=
Chop[temp[s] /. sols]
Out[5]=
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Now what happened in your case? In StandardForm mathemaica displays (by
default) only six digits while the rest are hidden. If you had
displayed your answer in InputForm you woudl have seen the hidden
digits. ALternatively, if you just copied and pasted your answer you
also would have got the correct accuracy. Instead you must have just
re-typed what you saw on the screen: a bad policy in the case of
Mathematica. Because of the sharp slope at the solution point the
difference in the value of the function between the root Mathematica
actually computes and the root it displays in StandardForm is pretty
significant:
In[33]:=
temp[-8.99998]
Out[33]=
-411.4729804992676
In[34]:=
temp[-8.999981180131652]
Out[34]=
-9.5367431640625*^-7
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/
On Thursday, March 6, 2003, at 04:35 pm, 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!
>
> PS: Please reply (cc) to my email. I did not subscribe my email to the
> this email group!
>
> --
> Chengzhou
>
>
>
>
Prev by Date:
**Re: RE: Re: Is Sort stable?**
Next by Date:
**silver-pohlig-hellman**
Previous by thread:
**RE: Emergent Help: NSolve Problems!**
Next by thread:
**Functional differentiation on lattice**
| |