fix for eigenvectors function in eigen.mac
ehm <[email protected]> Wed, 10 Jun 2026 16:10:04 -0500
| Newsgroups | gmane.comp.mathematics.maxima.general |
|---|---|
| Organization | University of Missouri |
| Message-ID | <[email protected]> |
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