Re: fix for eigenvectors function in eigen.mac

Stavros Macrakis <[email protected]> Sun, 14 Jun 2026 15:37:18 -0400
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CACLVabULC7-1x2-_FWXo4ofNnsBpk6k2h7aRS-BYVUUqryLGgw@mail.gmail.com>
Eric M,

Please make problem reports self-contained and minimal. And please mention
the version of Maxima you're using, as reported at the beginning of your
Maxima session, or by *bug_report()*.

Your report references *qm.mac*, which I am guessing is
*https://github.com/QMeqGR/qm-maxima/blob/master/qm.mac
<https://github.com/QMeqGR/qm-maxima/blob/master/qm.mac>*, which itself
loads 11 more files. It would make life easier for us if you could instead
start with the explicit value of *Sn *in readable form -- you can use
*string(...)
*or *display2d:false*.

Also, as I mentioned before, it makes it easier to track issues if you enter
them into the bug reporting tool at
https://sourceforge.net/p/maxima/bugs/new/.

Thanks,

           -s

On Wed, Jun 10, 2026 at 5:10 PM 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