MathGroup Archive 2009

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

Search the Archive

Re: NSolve vs. N[Solve ]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103446] Re: [mg103423] NSolve vs. N[Solve ]
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 21 Sep 2009 19:28:11 -0400 (EDT)
  • References: <200909210951.FAA04712@smc.vnet.net>

This is not quite right. NSolve is primarily meant for polynomial and  
algebraic equations and when you give it an algebraic equation it will  
behave as advertised:

x /. NSolve[x^3 - 3 x^2 - 2 x - 11 == 0, x, 3] // Precision

3.


x /. NSolve[x^3 - 3 x^2 - 2 x - 11 == 0, x,
    WorkingPrecision -> 3] // Precision

  3.

I believe that in the first of the above inputs NSolve actually seeks  
an answer with precision 3, while in the second case it uses  
WorkingPrecision 3, so the final answer may well have a lower  
precision. (At least this is how I imagine this ought to work, I can't  
remember anymore if this is indeed so and I do not have the time to  
experiment).

Now, in your case you have a transcendental equation

Exp[x]==10

I think that in this sort of situation NSolve does not have any  
methods of its own that it can use. I believe that it simply asks  
Solve for the answer (which is Log[10], with a warning about inverse  
functions being used) and then it just applies N to the answer it gets  
from Solve. In doing so it simply ignores the precision you asked for.  
This is probably an oversight rather than a bug. Of course the best  
thing to do in such cases is to use N[Solve[Exp[x] == 10, x], 3],  
since really there is absolutely no benefit at all of using NSolve  
unless you are trying to solve an equation on which special methods  
that NSolve is able to use can be used. In other cases NSolve will  
just turn to Solve for the answer so you might as well tell your  
students to do that directly.
(I assume they can tell a polynomial equation from a transcendental  
one. If not, its something worth explaining.)

Andrzej Kozlowski



On 21 Sep 2009, at 18:51, Helen Read wrote:

> A while back (I forget what version), N was modified so that it will
> give output to any number of significant digits that you desire.
> Previously, N[x,k] would output 6 significant digits if k was anything
> less than machine precision. Asking for N[x,3] or N[x,15] or whatever
> would give output to 6 significant digits, while N[x,k] for k>=16  
> would
> give x to k significant digits.
>
> Lately my students have been using NSolve with a third argument (for  
> the
> precision) -- which I hadn't told them about -- to solve a problem  
> that
> I was actually expecting them to do a different way. What they did  
> was a
> reasonable solution, but unfortunately they didn't notice that their
> results from NSolve were not coming out to the number of significant
> digits that they asked for. Evidently NSolve behaves like the old N,  
> and
> differs from N[Solve ]
>
> For example, compare these:
>
> NSolve[E^x==10,x,3]  (* result given to 6 significant digits, despite
> asking for only 3 *)
>
> N[Solve[E^x==10,x],3]  (* result given to the desired precision *)
>
> NSolve[E^x == 10, x, 12]  (* result given to only 6 significant  
> digits,
> despite asking for 12 *)
>
> N[Solve[E^x==10,x],12]  (* result given to the desired precision *)
>
> I hadn't noticed this unfortunate behavior until I started seeing it  
> in
> my students' work.
>
> -- 
> Helen Read
> University of Vermont
>



  • Prev by Date: Re: Modifying Default Stylesheet?
  • Next by Date: Re: NSolve vs. N[Solve ]
  • Previous by thread: NSolve vs. N[Solve ]
  • Next by thread: Re: NSolve vs. N[Solve ]