rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

Various problems with a sustem of linear equations #2272

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-05 22:39:48 Created by charpent on 2016-11-12 10:49:06 Original: https://sourceforge.net/p/maxima/bugs/3239


Maxima version: "5.38.1" Maxima build date: "2016-11-01 13:12:23" Host type: "x86_64-pc-linux-gnu" Lisp implementation type: "GNU Common Lisp (GCL)" Lisp implementation version: "GCL 2.6.12"

I found Maxima unable to search the axis of a rotation in R^3.

Annotated transcript follows ;

Maxima 5.38.1 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.12
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) display2d:false;

(%o1) false

/* Matrix of a rotation about the x axis, angle theta */

(%i2) M_x:matrix([1,0,0],[0,cos(theta),-sin(theta)],[0,sin(theta),cos(theta)]);

(%o2) matrix([1,0,0],[0,cos(theta),-sin(theta)],[0,sin(theta),cos(theta)])

/* Matrix of a rotation about the y axis, angle phi */

(%i3) M_y:matrix([cos(phi),0,-sin(phi)],[0,1,0],[sin(phi),0,cos(phi)]);

(%o3) matrix([cos(phi),0,-sin(phi)],[0,1,0],[sin(phi),0,cos(phi)])

/* A vector */

(%i4) V:[x,y,z];

(%o4) [x,y,z]

/* Check that we can finf the invariant vector of the rotation described by M_x */

(%i5) solve(maplist(lambda([u,v],u[1]=v),M_x.V,V),V);

solve: dependent equations eliminated: (1)
(%o5) [[x = %r1,y = 0,z = 0]]

/* So far, so good. Let's try to finf=d the invariant vector of the composition of the rotations about the x and y axes :
 Compute the matrix representing the composition */

(%i6) M_2:M_x.M_y;

(%o6) matrix([cos(phi),0,-sin(phi)],
             [-sin(phi)*sin(theta),cos(theta),-cos(phi)*sin(theta)],
             [sin(phi)*cos(theta),sin(theta),cos(phi)*cos(theta)])

/* Try the simple option firs : ask maxima to olve the system : */

(%i7) solve(maplist(lambda([u,v],u[1]=v),M_2.V,V),V);

(%o7) [[x = 0,y = 0,z = 0]]

/* An axis-less rotation ? Really ?? 
Create the equation system explicity : */

(%i8) S_2:maplist(lambda([u,v],v=u[1]),M_2.V,V);

(%o8) [x = cos(phi)*x-sin(phi)*z,
       y = (-cos(phi)*sin(theta)*z)+cos(theta)*y-sin(phi)*sin(theta)*x,
       z = cos(phi)*cos(theta)*z+sin(theta)*y+sin(phi)*cos(theta)*x]

/* Try to solve that "like in high  school : solve for one variable in each equation, and substitute in further equations.
Start with an empty list : */

(%i9) IS:[];

(%o9) []

/* Solve the first equation, add that to the list of partial solutions : */

(%i10) IS:append(IS,solve(subst(IS,S_2[1]),lhs(S_2[1])));

(%o10) [x = (sin(phi)*z)/(cos(phi)-1)]

/* Second equation, second variable */

(%i11) IS:append(IS,solve(subst(IS,S_2[2]),lhs(S_2[2])));

(%o11) [x = (sin(phi)*z)/(cos(phi)-1),
        y = ((sin(phi)^2+cos(phi)^2-cos(phi))*sin(theta)*z)
          /((cos(phi)-1)*cos(theta)-cos(phi)+1)]

/* Third equation, third variable */
(%i12) IS:append(IS,solve(subst(IS,S_2[3]),lhs(S_2[3])));

(%o12) [x = (sin(phi)*z)/(cos(phi)-1),
        y = ((sin(phi)^2+cos(phi)^2-cos(phi))*sin(theta)*z)
          /((cos(phi)-1)*cos(theta)-cos(phi)+1),z = 0]

    /* This is wrong, wrong, wrong ! Maxima gets it wrong on a linear system...
It can be shown by enforcing simplifications of each partial solution
Start with a new empty list of partial solutions : */

(%i13) IS2:[];

(%o13) []
(%i14) IS2:append(IS2,solve(trigsimp(expand(factor(ratsimp(subst(IS2,S_2[1]))))),
    lhs(S_2[1])));

(%o14) [x = (sin(phi)*z)/(cos(phi)-1)]

/* Okay... */

(%i15) IS2:append(IS2,solve(trigsimp(expand(factor(ratsimp(subst(IS2,S_2[2]))))),
    lhs(S_2[2])));

(%o15) [x = (sin(phi)*z)/(cos(phi)-1),y = -(sin(theta)*z)/(cos(theta)-1)]

/* Okay also... */

(%i16) IS2:append(IS2,solve(trigsimp(expand(factor(ratsimp(subst(IS2,S_2[3]))))),
    lhs(S_2[3])));

append: argument must be a non-atomic expression; found all
 -- an error. To debug this try: debugmode(true);

 /* Second problem : I expected a solution of the form z=%r1, as usual. I know that this is possible, since it is the way Maxima usually reports indeterminacies. Why do I get this ? And how to control this ? I found no relevant flag in the documentatin... */

So we have one minor and one major problem : The minor one : Maxima reports an undeterminacy in an unexpected (and seemingly unncontrollable) way ; The major one : Maxima is unable to solve correcly a linear equation (the fact that the coefficients are expressed as trigonometric functions of constants is irrelevant).

I tried to peruse the open bugs list, and it seems that this one is novel...

One more info : this was obtained with Maxima compiled with GCL as packaged in Debian Testing. Maxima compiled with ECL as packaged in Sagemath (née Sage), which is at 5.35.1, gives the same error

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-05 22:39:49 Created by charpent on 2016-11-13 19:16:09 Original: https://sourceforge.net/p/maxima/bugs/3239/#304d


Also filed as Sage's ticket 21873, Maxima's ticket referenced.