eigenvectors in maxima



Jason, I looked at the eigenvector code and it appears Maxima
is just smashing all the vectors together, but it is easy to
distinguish them. I've attached a patch so that eigenvectors
returns [vals, vecs] where vals is a list of values and their
multiplicities (just as it was before) and vecs is a list of lists
of vectors (before it was just a list of vectors).

Here is a sample session with the examples you gave.
Sorry, it's probably a little messy. Comments, anyone?

(%i1) M1 : matrix ([0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]);
                         [ 0  1  0  0 ]
                         [            ]
                         [ 0  0  0  0 ]
(%o1)                    [            ]
                         [ 0  0  2  0 ]
                         [            ]
                         [ 0  0  0  2 ]
(%i2) [vals, vecs] : eigenvectors (M1);
(%o2) [[[0, 2], [2, 2]], [[[1, 0, 0, 0]],
                                   [[0, 0, 1, 0], [0, 0, 0, 1]]]]
(%i3) for i thru length (vals) do disp (val[i] = vals[i][1], mult[i] =
vals[i][2], vec[i] = vecs[i]);
                            val  = 0
                               1

                            mult  = 2
                                1

                      vec  = [[1, 0, 0, 0]]
                         1

                            val  = 2
                               2

                            mult  = 2
                                2

               vec  = [[0, 0, 1, 0], [0, 0, 0, 1]]
                  2

(%o3)                         done
(%i4) M2 : matrix ([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 2, 1], [0, 0, 0, 2]);
                         [ 0  0  0  0 ]
                         [            ]
                         [ 0  0  0  0 ]
(%o4)                    [            ]
                         [ 0  0  2  1 ]
                         [            ]
                         [ 0  0  0  2 ]
(%i5) [vals, vecs] : eigenvectors (M2);
(%o5) [[[0, 2], [2, 2]], [[[1, 0, 0, 0], [0, 1, 0, 0]],
                                                 [[0, 0, 1, 0]]]]
(%i6) for i thru length (vals) do disp (val[i] = vals[i][1], mult[i] =
vals[i][2], vec[i] = vecs[i]);
                            val  = 0
                               1

                            mult  = 2
                                1

               vec  = [[1, 0, 0, 0], [0, 1, 0, 0]]
                  1

                            val  = 2
                               2

                            mult  = 2
                                2
(%i1) M1 : matrix ([0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]);
                         [ 0  1  0  0 ]
                         [            ]
                         [ 0  0  0  0 ]
(%o1)                    [            ]
                         [ 0  0  2  0 ]
                         [            ]
                         [ 0  0  0  2 ]
(%i2) [vals, vecs] : eigenvectors (M1);
(%o2) [[[0, 2], [2, 2]], [[[1, 0, 0, 0]],
                                   [[0, 0, 1, 0], [0, 0, 0, 1]]]]
(%i3) for i thru length (vals) do disp (val[i] = vals[i][1], mult[i] =
vals[i][2], vec[i] = vecs[i]);
                            val  = 0
                               1

                            mult  = 2
                                1

                      vec  = [[1, 0, 0, 0]]
                         1

                            val  = 2
                               2

                            mult  = 2
                                2

               vec  = [[0, 0, 1, 0], [0, 0, 0, 1]]
                  2

(%o3)                         done
(%i4) M2 : matrix ([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 2, 1], [0, 0, 0, 2]);
                         [ 0  0  0  0 ]
                         [            ]
                         [ 0  0  0  0 ]
(%o4)                    [            ]
                         [ 0  0  2  1 ]
                         [            ]
                         [ 0  0  0  2 ]
(%i5) [vals, vecs] : eigenvectors (M2);
(%o5) [[[0, 2], [2, 2]], [[[1, 0, 0, 0], [0, 1, 0, 0]],
                                                 [[0, 0, 1, 0]]]]
(%i6) for i thru length (vals) do disp (val[i] = vals[i][1], mult[i] =
vals[i][2], vec[i] = vecs[i]);
                            val  = 0
                               1

                            mult  = 2
                                1

               vec  = [[1, 0, 0, 0], [0, 1, 0, 0]]
                  1

                            val  = 2
                               2

                            mult  = 2
                                2

                      vec  = [[0, 0, 1, 0]]
                         2

(%o6)                         done

                      vec  = [[0, 0, 1, 0]]
                         2

(%o6)                         done


FWIW

Robert Dodier

PS.
--- share/matrix/eigen.mac      22 Nov 2007 17:11:14 -0000      1.4
+++ share/matrix/eigen.mac      28 May 2009 04:09:26 -0000
@@ -114,7 +114,7 @@
                unknowns:endcons(concat(notknwn,index1),unknowns),
                vectr:columnvector(unknowns),matrx:mat.vectr,
                nondiagonalizable:false,
-               listall:[eigvals],realonly:false,algebraic:true,
+               eigvecs:[],realonly:false,algebraic:true,
                for index1 thru count do
                (count:mi(count-part(multiplicities,index1)+1),
                mmatrx:matrx-part(eigvals,1,index1)*vectr,
@@ -132,8 +132,8 @@
                (print(" "),print("algsys failure: the eigenvector(s) for the",
                index1,"th eigenvalue will be missing.")),
                if hermitianmatrix and %rnum>1 then unit:gramschmidt(unit),
-               listall:append(listall,unit)),
-               return(listall)))$
+               eigvecs:append(eigvecs,[unit])),
+               return([eigvals, eigvecs])))$


 /* the first arg is of the form [r1,r2,r3].