Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Solve vs. NSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92815] Re: [mg92796] Solve vs. NSolve
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Tue, 14 Oct 2008 04:56:13 -0400 (EDT)
  • References: <200810131021.GAA14435@smc.vnet.net>

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

NSolve is not meant for problems that have parameters (e.g. t) or are 
not algebraic (e.g. have trigs). That said, it's result for this example 
is pretty much equivalent to that of Solve.

In[1]:= 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];

In[2]:= df[a_, b_, c_, k_, t_] := D[f[a, b, c, k, t], t];

In[3]:= Together[
  Map[First, {f[1, 2, 1/2, 4/5, t], df[1, 2, 1/2, 4/5, t]}] /.
   Solve[{f[1, 2, 1/2, 4/5, t], df[1, 2, 1/2, 4/5, t]}, {x, y}]] 


Out[3]= {{0, 0}, {0, 0}}

In[4]:= Chop[Together[
   Map[First, {f[1, 2, 1/2, 4/5, t], df[1, 2, 1/2, 4/5, t]}] /.
    NSolve[{f[1, 2, 1/2, 4/5, t], df[1, 2, 1/2, 4/5, t]}, {x, y}]]] 


Out[4]= {{0, 0}, {0, 0}}

My guess is the Simplify usage might cause the results to look a bit 
different. Simplify also can have trouble with approximate numbers, 
since it is doing rational function manipulations.


Daniel Lichtblau
WOlfram Research


  • Prev by Date: Re: Solve vs. NSolve
  • Next by Date: Re: Nested If
  • Previous by thread: Re: Solve vs. NSolve
  • Next by thread: Re: Solve vs. NSolve