# [Maxima] solution of quadratic equations -- incorrect solution

Krishna Myneni krishna.myneni at ccreweb.org
Tue Jul 3 12:00:00 CDT 2012

```On 07/03/2012 07:16 AM, Viktor T. Toth wrote:
> If you check your y-solutions, you will find that the differences are due to
> trivial algebra and the solutions are, in fact, identical when you set
> err=0. You have expressions that are formally just like sqrt(A-B)*sqrt(C-D)
> vs. sqrt(B-A)*sqrt(D-C), which may appear different at first but they really
> aren't. You can actually verify this using Maxima itself, as well as verify
> that the solutions that were obtained indeed solve your system of equations:
>
> (%i1) display2d:false\$
> (%i2) e1a: x^2+y^2=r1^2\$
> (%i3) e2a: (x-1)^2+(y-1)^2=r2^2\$
> (%i4) sola: solve([e1a,e1a-e2a],[x,y])\$
> (%o5) [r1^2 = r1^2,r2^2 = r2^2]
> (%o6) [r1^2 = r1^2,r2^2 = r2^2]
> (%i7) e1b: x^2+y^2=(r1-err)^2\$
> (%i8) e2b:(x-1)^2+(y-1)^2=(r2-err)^2\$
> (%i9) solb: solve([e1b,e1b-e2b],[x,y])\$
> (%o10) [r1^2-2*err*r1+err^2 = r1^2-2*err*r1+err^2,
>          r2^2-2*err*r2+err^2 = r2^2-2*err*r2+err^2]
> (%o11) [r1^2-2*err*r1+err^2 = r1^2-2*err*r1+err^2,
>          r2^2-2*err*r2+err^2 = r2^2-2*err*r2+err^2]
> (%o12) [0 = 0,0 = 0]
> (%o13) [0 = 0,0 = 0]
>
>
> Viktor
>
>
>
>
>
>
> -----Original Message-----
> From: maxima-bounces at math.utexas.edu [mailto:maxima-bounces at math.utexas.edu]
> On Behalf Of Krishna Myneni
> Sent: Monday, July 02, 2012 7:39 PM
> To: maxima at math.utexas.edu
> Subject: [Maxima] solution of quadratic equations -- incorrect solution
>
> Previously, I posted that Maxima's solve() was unable to solve a system of
> two quadratic equations directly. Several workarounds were suggested to find
> the solution to the following system of equations:
>
> e1:   (x - a)^2 + (y - b)^2 = r1^2
>
> e2:  (x - c)^2 + (y - d)^2 = r2^2
>
> While the workarounds permit Maxima's solve() to obtain analytic solutions
> to the above equations, we have found that Maxima gives an incorrect
> solution to a slight variant of the above equations. Instead of the general
> equations above, it is simpler to illustrate the problem with the following
> eqns:
>
> e1:  x^2 + y^2 = (r1 - err)^2
>
> e2: (x - 1)^2 + (y - 1)^2 = (r2 - err)^2
>
> If we first find the analytic solutions to the set, [x^2 + y^2 = r1^2,
> (x-1)^2 + (y-1)^2 = r2^2], and then find the solutions to the above
> equations with "err", substituting err=0 into the latter gives solutions
> which are not the same as the former, as shown below. Comparing the
> algebraic expressions with err=0 show that the x-solutions are the same, but
> the y-solutions have a sign error in product terms r1*r2.
>
>
>
> (%i1) e1: x^2 + y^2 = r1^2;
>                                    2    2     2
> (%o1)                            y  + x  = r1
> (%i2) e2: (x-1)^2 + (y-1)^2 = r2^2;
>                                    2          2     2
> (%o2)                      (y - 1)  + (x - 1)  = r2
>
> (%i4) solve([e1,e1-e2],[x,y]);
>
>                         4        2        2     4       2          2     2
>                sqrt(- r2  + (2 r1  + 4) r2  - r1  + 4 r1  - 4) + r2  - r1  -
> 2
> (%o4) [[x = -
> ---------------------------------------------------------------,
>                                               4
>
>                2               2             2               2          2
> 2
> y = (sqrt(- r2  + 2 r1 r2 - r1  + 2) sqrt(r2  + 2 r1 r2 + r1  - 2) - r2  +
> r1 + 2)/4],
>
> [x =
>           4        2        2     4       2          2     2
> sqrt(- r2  + (2 r1  + 4) r2  - r1  + 4 r1  - 4) - r2  + r1  + 2
> ---------------------------------------------------------------,
>                                 4
>
>                  2               2             2               2          2
> y = - (sqrt(- r2  + 2 r1 r2 - r1  + 2) sqrt(r2  + 2 r1 r2 + r1  - 2) + r2
>
>               2
>           - r1  - 2)/4]
>
> ]
>
> Generalizing these equations slightly, and finding the new solutions, we
> have,
>
> (%i15) e1: x^2 + y^2 = (r1-err)^2;
>                                2    2             2
> (%o15)                       y  + x  = (r1 - err)
> (%i16) e2: (x-1)^2 + (y-1)^2 = (r2-err)^2;
>                                2          2             2
> (%o16)                 (y - 1)  + (x - 1)  = (r2 - err)
> (%i17) sol: solve([e1,e1-e2],[x,y]);
>
> (%o17) [[x = - (sqrt(- r2  + 4 err r2  + (2 r1  - 4 err r1 - 4 err  + 4) r2
>                2        2                    4           3             2    2
>   + (- 4 err r1  + 8 err  r1 - 8 err) r2 - r1  + 4 err r1  + (4 - 4 err ) r1
>                     2          2                2
>   - 8 err r1 + 8 err  - 4) + r2  - 2 err r2 - r1  + 2 err r1 - 2)/4,
>
>                2                          2                   2
> y = (sqrt(- r2  - 2 r1 r2 + 4 err r2 - r1  + 4 err r1 - 4 err  + 2)
>          2               2          2                2
>   sqrt(r2  - 2 r1 r2 + r1  - 2) - r2  + 2 err r2 + r1  - 2 err r1 + 2)/4],
>
>                 4           3        2                   2        2
> [x = (sqrt(- r2  + 4 err r2  + (2 r1  - 4 err r1 - 4 err  + 4) r2
>                2        2                    4           3             2    2
>   + (- 4 err r1  + 8 err  r1 - 8 err) r2 - r1  + 4 err r1  + (4 - 4 err ) r1
>                     2          2                2
>   - 8 err r1 + 8 err  - 4) - r2  + 2 err r2 + r1  - 2 err r1 + 2)/4,
>
>                  2                          2                   2
> y = - (sqrt(- r2  - 2 r1 r2 + 4 err r2 - r1  + 4 err r1 - 4 err  + 2)
>          2               2          2                2
>   sqrt(r2  - 2 r1 r2 + r1  - 2) + r2  - 2 err r2 - r1  + 2 err r1 - 2)/4]]
>
>
>
> If we set err = 0, the equations to be solved are identical to the original
> equations. However, setting err = 0 in the solutions does not give the same
> results as before. The x-solutions are the same, but the y-solutions have
> product terms r1*r2 which have a different sign from the solutions of the
> original equations. The solutions to the problem are incorrect.
>
>
> Krishna
>
>
>
>

Victor,

I reproduce your maxima output (Maxima 5.24), but the two solutions,
sola and solb with err=0, are not the same. This can be seen
algebraically and numerically.

(%i16) ev(sola[1],[r1=1,r2=1]);

(%o16) [x = 0,y = 1]
(%i17) ev(solb[1],[r1=1,r2=1,err=0]);

(%o17) [x = 0,y = 0]

The x-solutions are the same, but the y-solutions are not. If you print
the solutions, the comparison is not

sqrt(A-B)*sqrt(C-D) vs. sqrt(B-A)*sqrt(D-C)

but

sqrt(A-B)*sqrt(C-D) vs. sqrt(A+B)*sqrt(C+D)

(%i18) sola[1];

(%o18) [x = -(sqrt(-r2^4+(2*r1^2+4)*r2^2-r1^4+4*r1^2-4)+r2^2-r1^2-2)/4,
y = (sqrt(-r2^2+2*r1*r2-r1^2+2)*sqrt(r2^2+2*r1*r2+r1^2-2)-r2^2+r1^2+2)
/4]

(%i20) ev(solb[1],err=0);

(%o20) [x = -(sqrt(-r2^4+(2*r1^2+4)*r2^2-r1^4+4*r1^2-4)+r2^2-r1^2-2)/4,
y = (sqrt(-r2^2-2*r1*r2-r1^2+2)*sqrt(r2^2-2*r1*r2+r1^2-2)-r2^2+r1^2+2)
/4]

Regards,
Krishna

```