Re: fix for eigenvectors function in eigen.mac

Stavros Macrakis <[email protected]> Sun, 14 Jun 2026 12:17:46 -0400
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CACLVabUDFNiUbTdEsXVy=4SLazZOMGcoD2NQZsGNKe1k2roWpQ@mail.gmail.com>
Thanks for the problem report!

May I suggest that in the future you use a fixed-width font for Maxima
transcripts in email?

Or use a Sourceforge bug report (https://sourceforge.net/p/maxima/bugs/new/),
which supports code formatting with the </> command, `inline`, or ~~~ for
multiline.

Those make it easier to read.

Thanks

       -s


On Wed, Jun 10, 2026, 17:10 ehm <[email protected]> wrote:

> Hi all,
>
> The eigenvectors() function in eigen.mac fails for a pretty simple 2x2
> matrix, but there is a fix (see the bottom).
>
> An example is shown below. In intro quantum mechanics a common problem
> is to find the eigenvectors for an arbitrarily oriented Stern-Gerlach
> apparatus. So one constructs:
>
> Sn:[Sx,Sy,Sz].[sin(t)*cos(p),sin(t)*sin(p),cos(t)];
>
> where Sx, etc. are the 2x2 spin matrices, and the angles t and p refer
> to the usual spherical coordinates theta and phi. It is easy to
> diagonalize this by hand.
>
> The output from eigenvectors is
>
> (%i1) display2d_unicode:false;
> (%i2) load(qm);
> (%o2)          /home/ehm/math/Maxima/share/ehm/qm-maxima/qm.mac
> (%i3) Sn:[Sx,Sy,Sz].[sin(t)*cos(p),sin(t)*sin(p),cos(t)];
> (%i4) [evals,evecs]:eigenvectors(Sn);
>
> eigenvectors: the eigenvector(s) for the 1 th eigenvalue will be
> missing.
>                         2       2         2       2         2
>            hbar sqrt(sin (p) sin (t) + cos (p) sin (t) + cos (t))
> (%o4) [[[- ------------------------------------------------------,
>                                      2
>              2       2         2       2         2
> hbar sqrt(sin (p) sin (t) + cos (p) sin (t) + cos (t))
> ------------------------------------------------------], [1, 1]],
>                           2
>              %i p          2         2        2         2
> [[], [[1, (%e     sqrt((sin (p) + cos (p)) sin (t) + cos (t))
>                                        2         2
>  + (- %i sin(p) - cos(p)) cos(t))/((sin (p) + cos (p)) sin(t))]]]]
>
> And the first eigenvector is missing. Let's compare with my hand
> written diagonalization code:
>
> (%i5) [evals,evecs]:diagonalize(Sn)$
>
> The output is a bit of a mess, so simplify it. (this is my fullsimp
> available on github). This is the correct answer.
>
> (%i6) fullsimp(%);
>                             [        1        ]  [       1       ]
>               hbar  hbar    [                 ]  [               ]
> (%o6)     [[- ----, ----], [[     %i p     t  ], [   %i p     t  ]]]
>                2     2      [ - %e     cot(-) ]  [ %e     tan(-) ]
>                             [              2  ]  [            2  ]
>
>
> The FIX:
>
> To fix this in eigenvectors() replace algsys with linsolve.
>
> Change the two lines
>
> solution:algsys(equations,unknowns),
> interm:map('rhs,solution[1]),
>
> to
>
> solution:linsolve(equations,unknowns),
> interm:map('rhs,solution),
>
> There are not many tests for eigenvectors in rtest_eigen.mac. Some more
> tests should probably be added.
>
> -Eric M
>
>
> _______________________________________________
> Maxima-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>

_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss