| 68 | |
| 69 | |
| 70 | Vector LovelyEig( const Matrix &M ) |
| 71 | { |
| 72 | //.... compute eigenvalues and vectors for a 3 x 3 symmetric matrix |
| 73 | // |
| 74 | //.... INPUTS: |
| 75 | // M(3,3) - matrix with initial values (only upper half used) |
| 76 | // |
| 77 | //.... OUTPUTS |
| 78 | // v(3,3) - matrix of eigenvectors (by column) |
| 79 | // d(3) - eigenvalues associated with columns of v |
| 80 | // rot - number of rotations to diagonalize |
| 81 | // |
| 82 | //---------------------------------------------------------------eig3== |
| 83 | |
| 84 | //.... Storage done as follows: |
| 85 | // |
| 86 | // | v(1,1) v(1,2) v(1,3) | | d(1) a(1) a(3) | |
| 87 | // | v(2,1) v(2,2) v(2,3) | = | a(1) d(2) a(2) | |
| 88 | // | v(3,1) v(3,2) v(3,3) | | a(3) a(2) d(3) | |
| 89 | // |
| 90 | // Transformations performed on d(i) and a(i) and v(i,j) become |
| 91 | // the eigenvectors. |
| 92 | // |
| 93 | //---------------------------------------------------------------eig3== |
| 94 | |
| 95 | int rot, its, i, j , k ; |
| 96 | double g, h, aij, sm, thresh, t, c, s, tau ; |
| 97 | |
| 98 | static Matrix v(3,3) ; |
| 99 | static Vector d(3) ; |
| 100 | static Vector a(3) ; |
| 101 | static Vector b(3) ; |
| 102 | static Vector z(3) ; |
| 103 | |
| 104 | static const double tol = 1.0e-08 ; |
| 105 | |
| 106 | // set v = M |
| 107 | v = M ; |
| 108 | |
| 109 | //.... move array into one-d arrays |
| 110 | |
| 111 | a(0) = v(0,1) ; |
| 112 | a(1) = v(1,2) ; |
| 113 | a(2) = v(2,0) ; |
| 114 | |
| 115 | |
| 116 | for ( i = 0; i < 3; i++ ) { |
| 117 | d(i) = v(i,i) ; |
| 118 | b(i) = v(i,i) ; |
| 119 | z(i) = 0.0 ; |
| 120 | |
| 121 | for ( j = 0; j < 3; j++ ) |
| 122 | v(i,j) = 0.0 ; |
| 123 | |
| 124 | v(i,i) = 1.0 ; |
| 125 | |
| 126 | } //end for i |
| 127 | |