MathGroup Archive 1999

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

Search the Archive

Re: Repost: Solve: same or new bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17727] Re: Repost: Solve: same or new bug?
  • From: Daniel Lichtblau <danl>
  • Date: Tue, 25 May 1999 02:15:13 -0400
  • Organization: Wolfram Research, Inc.
  • References: <7i37g1$bin@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thomas Gawlick wrote:
> 
> In the following example Mathematica happens to find a "general
> solution'" that does not special to a solution for numerical
> specialization of the paramters a,e.
> 
> m:=Sqrt[1-a^2]
> g:=(x*(a+y)-m*(a+y+e))^2+y^2*(a+y+e)^2-(a+y+e)^2
> gx:=D[g,x]
> gy:=D[g,y]
> Solve[{g==0,gx==0,gy==0},{x,y}]
> {{x -> 0, y -> -a - e},
>   {x -> (a*(1 - a^2)^(1/2)*e)/(-1 + a^2), y -> -a},
>   {x -> (a*(1 - a^2)^(1/2)*e)/(-1 + a^2), y -> -a}}
> % /. {a->.5,e->.1}
> {{x -> 0, y -> -0.6}, {x -> -0.057735, y -> -0.5},
> 
>  {x -> -0.057735, y -> -0.5}}
> a:=.5; e:=.1
> Solve[{g==0,gx==0,gy==0},{x,y}]
> {{x -> 0., y -> -0.6}}
> 
> Is the reason for this that Mathematica checks numerical solutions only?
> 
> Another small question: How do you achieve to clear ALL variables?
> 
> --
> Best regards
> 
> Thomas Gawlick
> ---
> Dr.rer.nat. Thomas Gawlick
> 
> Hochschulassistent fur Didaktik der Mathematik
> 
> Hochschule Vechta, 49364 Vechta

Both symbolic solutions are okay. We see this as below. Note that I am
using version 4 and so there may be differences in Solve results vs.
those previously posted. I will explain why later.

The set-up:

m = Sqrt[1-a^2];
g = (x*(a+y)-m*(a+y+e))^2+y^2*(a+y+e)^2-(a+y+e)^2;
gx = D[g,x];
gy = D[g,y];


Here is the symbolic solution.

In[12]:= InputForm[sol = Solve[{g==0,gx==0,gy==0},{x,y}]]
Out[12]//InputForm= 
{{x -> 0, y -> -a - e}, {x -> (a*Sqrt[1 - a^2]*e)/(-1 + a^2), y -> -a}}


We confirm that both solutions are correct.

In[14]:= FullSimplify[{g,gx,gy} /. sol]
Out[14]= {{0, 0, 0}, {0, 0, 0}}

Evaluate for a = .5 and e = .1:

In[16]:= rools = {a->.5,e->.1};

In[17]:= sol2 = sol /. rools
Out[17]= {{x -> 0, y -> -0.6}, {x -> -0.057735, y -> -0.5}}


Can we obtain this by setting the values of a and e before solving?

In[18]:= sol3 = Solve[{g==0,gx==0,gy==0} /. rools, {x,y}]
Out[18]= {}

Seemingly not. Let's see what happens if we use exact values for the
parameters a and e.

In[20]:= InputForm[sol4 = Solve[{g==0,gx==0,gy==0} /.
Rationalize[rools], {x,y}]]
Out[20]//InputForm= 
{{x -> 0, y -> -3/5}, {x -> -1/(10*Sqrt[3]), y -> -1/2}, 
 {x -> -1/(10*Sqrt[3]), y -> -1/2}}

In[21]:= sol5 = N[sol4]
Out[21]= {{x -> 0., y -> -0.6}, {x -> -0.057735, y -> -0.5}, 
    {x -> -0.057735, y -> -0.5}}

What went wrong in sol3? Simply put, we have an overdetermined system of
equations. Numeric round-off can be disasterous when we try to find the
simultaneous solution set. NSolve is a bit better at handling this.

In[23]:= InputForm[sol6 = NSolve[{g==0,gx==0,gy==0} /. rools, {x,y}]]
Out[23]//InputForm= 
{{x -> -4.624078897563777*^-14, y -> -0.6000000000000006}, 
 {x -> -0.05773502691902965, y -> -0.500000000000005}}


If you want to get fancy, use the exact input in NSolve and increase the
working precision. Then round off to machine precision when finished. Of
course this is in general slower than using NSolve with default
settings, but it improves reliability when handling overdetermined
systems.

In[28]:= sol7 = N[NSolve[{g==0,gx==0,gy==0} /. Rationalize[rools],
{x,y},
        WorkingPrecision->100]]
Out[28]= {{x -> 0., y -> -0.6}, {x -> -0.057735, y -> -0.5}}


Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: Number Formatting
  • Next by Date: Re: MatrixForm
  • Previous by thread: Re: Repost: Solve: same or new bug?
  • Next by thread: mathlink and graphics