patch for eigenvector to consider



Hello,

I'm pondering the following patch, which attempts to make the
output of the eigenvectors function more comprehensible when
there are multiple eigenvectors for the same eigenvalue.
However, it makes the output somewhat clumsier when there
is just 1 eigenvector per eigenvalue, a common special case.

Examples. (Sorry for the messy output.)

(%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[1]) do disp (val[i] = vals[1][i],
mult[i] =vals[2][i], 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 ([1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]);
                         [ 1  0  0  0 ]
                         [            ]
                         [ 0  2  0  0 ]
(%o4)                    [            ]
                         [ 0  0  3  0 ]
                         [            ]
                         [ 0  0  0  4 ]
(%i5) [vals, vecs] : eigenvectors (M2);
(%o5) [[[1, 2, 3, 4], [1, 1, 1, 1]],
[[[1, 0, 0, 0]], [[0, 1, 0, 0]], [[0, 0, 1, 0]], [[0, 0, 0, 1]]]]
(%i6) for i thru length (vals[1]) do disp (val[i] = vals[1][i],
mult[i] =vals[2][i], vec[i]=vecs[i]);
                            val  = 1
                               1

                            mult  = 1
                                1

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

                            val  = 2
                               2

                            mult  = 1
                                2

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

                            val  = 3
                               3

                            mult  = 1
                                3

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

                            val  = 4
                               4

                            mult  = 1
                                4

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

(%o6)                         done


I'm inclined to apply the patch because without it, the output
is pretty much incomprehensible when there are multiple
eigenvectors per eigenvalue. Yes / no / maybe ??

Thanks for your comments.

Robert Dodier

PS.
diff -u -r1.4 eigen.mac
--- share/matrix/eigen.mac  22 Nov 2007 17:11:14 -0000  1.4
+++ share/matrix/eigen.mac  28 Jul 2009 05:21:34 -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].