MathGroup Archive 2008

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

Search the Archive

Re: Solve vs. NSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92832] Re: [mg92796] Solve vs. NSolve
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 14 Oct 2008 04:59:25 -0400 (EDT)
  • References: <200810131021.GAA14435@smc.vnet.net>

On 13 Oct 2008, at 19:21, SigmundV wrote:

> Dear group members,
>
> Consider
>
> f[a_, b_, c_, k_, t_] :=
>  With[{\[Alpha] = a k, \[Beta] = b k}, (x - \[Alpha] Cos[t])^2/a^2 +
> (y - (\[Beta] Sin[t] + c) - c)^2/b^2 - 1 == 0];
> df[a_, b_, c_, k_, t_] := D[f[a, b, c, k, t], t];
>
> and execute
>
> {x, y} /. Simplify@PowerExpand@Simplify@Solve[{f[1, 2, 1/2, 4/5, t],
> df[1, 2, 1/2, 4/5, t]}, {x, y}] // Chop // N
>
> and
>
> {x, y} /. Simplify@PowerExpand@Simplify@NSolve[{f[1, 2, 1/2, 4/5, t],
> df[1, 2, 1/2, 4/5, t]}, {x, y}] // Chop
> Simplify@PowerExpand@Chop@Simplify[% /. Cos[2 t] -> (1 - 2 Sin[t]^2)]
>
> respectively.
>
> As you see, Solve and NSolve yield two different solutions, with the
> solution from Solve being the correct one, as can be verified by
> plugging in to the equations -- the solution from NSolve does not
> satisfy the second equation, but only the first. Can anyone explain
> this behaviour to me?
>
> Best wishes,
> Sigmund Vestergaard
>


The reason is that Solve solves the equations symbolically so it has  
no problems with numerical stability while NSolve with machine  
precision does. If you use NSolve with high extended precision you  
will get (essentially) the same answer.

first =
     N[Chop[{x, y} /.
      Simplify[PowerExpand[Simplify[Solve[{f[1, 2, 1/2, 4/5, t],
                     df[1, 2, 1/2, 4/5, t]}, {x, y}]]]]]];

second = Chop[{x, y} /. FullSimplify[PowerExpand[
              Simplify[NSolve[{f[1, 2, 1/2, 4/5, t], df[1, 2, 1/2,  
4/5, t]},
                  {x, y}, WorkingPrecision -> 100]]]]];


Simplify[Rationalize[first - second, 0]]

{{0, 2*(Sqrt[Sin[t]^2] - Sin[t])}, {0, 2*Sin[t] - 2*Sqrt[Sin[t]^2]}}


The fact that we do not get 0 is due to the use of PowerExpand. So

PowerExpand[%]
( {{0, 0},{0, 0}} )


Andrzej Kozlowski






  • Prev by Date: Re: loops?
  • Next by Date: Re: Solve vs. NSolve
  • Previous by thread: Solve vs. NSolve
  • Next by thread: Re: Solve vs. NSolve