| 1 |
subroutine tql2(nm,n,d,e,z,ierr) |
| 2 |
c |
| 3 |
integer i,j,k,l,m,n,ii,l1,l2,nm,mml,ierr |
| 4 |
double precision d(n),e(n),z(nm,n) |
| 5 |
double precision c,c2,c3,dl1,el1,f,g,h,p,r,s,s2,tst1,tst2,pythag |
| 6 |
c |
| 7 |
c this subroutine is a translation of the algol procedure tql2, |
| 8 |
c num. math. 11, 293-306(1968) by bowdler, martin, reinsch, and |
| 9 |
c wilkinson. |
| 10 |
c handbook for auto. comp., vol.ii-linear algebra, 227-240(1971). |
| 11 |
c |
| 12 |
c this subroutine finds the eigenvalues and eigenvectors |
| 13 |
c of a symmetric tridiagonal matrix by the ql method. |
| 14 |
c the eigenvectors of a full symmetric matrix can also |
| 15 |
c be found if tred2 has been used to reduce this |
| 16 |
c full matrix to tridiagonal form. |
| 17 |
c |
| 18 |
c on input |
| 19 |
c |
| 20 |
c nm must be set to the row dimension of two-dimensional |
| 21 |
c array parameters as declared in the calling program |
| 22 |
c dimension statement. |
| 23 |
c |
| 24 |
c n is the order of the matrix. |
| 25 |
c |
| 26 |
c d contains the diagonal elements of the input matrix. |
| 27 |
c |
| 28 |
c e contains the subdiagonal elements of the input matrix |
| 29 |
c in its last n-1 positions. e(1) is arbitrary. |
| 30 |
c |
| 31 |
c z contains the transformation matrix produced in the |
| 32 |
c reduction by tred2, if performed. if the eigenvectors |
| 33 |
c of the tridiagonal matrix are desired, z must contain |
| 34 |
c the identity matrix. |
| 35 |
c |
| 36 |
c on output |
| 37 |
c |
| 38 |
c d contains the eigenvalues in ascending order. if an |
| 39 |
c error exit is made, the eigenvalues are correct but |
| 40 |
c unordered for indices 1,2,...,ierr-1. |
| 41 |
c |
| 42 |
c e has been destroyed. |
| 43 |
c |
| 44 |
c z contains orthonormal eigenvectors of the symmetric |
| 45 |
c tridiagonal (or full) matrix. if an error exit is made, |
| 46 |
c z contains the eigenvectors associated with the stored |
| 47 |
c eigenvalues. |
| 48 |
c |
| 49 |
c ierr is set to |
| 50 |
c zero for normal return, |
| 51 |
c j if the j-th eigenvalue has not been |
| 52 |
c determined after 30 iterations. |
| 53 |
c |
| 54 |
c calls pythag for dsqrt(a*a + b*b) . |
| 55 |
c |
| 56 |
c questions and comments should be directed to burton s. garbow, |
| 57 |
c mathematics and computer science div, argonne national laboratory |
| 58 |
c |
| 59 |
c this version dated august 1983. |
| 60 |
c |
| 61 |
c ------------------------------------------------------------------ |
| 62 |
c |
| 63 |
ierr = 0 |
| 64 |
if (n .eq. 1) go to 1001 |
| 65 |
c |
| 66 |
do 100 i = 2, n |
| 67 |
100 e(i-1) = e(i) |
| 68 |
c |
| 69 |
f = 0.0d0 |
| 70 |
tst1 = 0.0d0 |
| 71 |
e(n) = 0.0d0 |
| 72 |
c |
| 73 |
do 240 l = 1, n |
| 74 |
j = 0 |
| 75 |
h = dabs(d(l)) + dabs(e(l)) |
| 76 |
if (tst1 .lt. h) tst1 = h |
| 77 |
c .......... look for small sub-diagonal element .......... |
| 78 |
do 110 m = l, n |
| 79 |
tst2 = tst1 + dabs(e(m)) |
| 80 |
if (tst2 .eq. tst1) go to 120 |
| 81 |
c .......... e(n) is always zero, so there is no exit |
| 82 |
c through the bottom of the loop .......... |
| 83 |
110 continue |
| 84 |
c |
| 85 |
120 if (m .eq. l) go to 220 |
| 86 |
130 if (j .eq. 30) go to 1000 |
| 87 |
j = j + 1 |
| 88 |
c .......... form shift .......... |
| 89 |
l1 = l + 1 |
| 90 |
l2 = l1 + 1 |
| 91 |
g = d(l) |
| 92 |
p = (d(l1) - g) / (2.0d0 * e(l)) |
| 93 |
r = pythag(p,1.0d0) |
| 94 |
d(l) = e(l) / (p + dsign(r,p)) |
| 95 |
d(l1) = e(l) * (p + dsign(r,p)) |
| 96 |
dl1 = d(l1) |
| 97 |
h = g - d(l) |
| 98 |
if (l2 .gt. n) go to 145 |
| 99 |
c |
| 100 |
do 140 i = l2, n |
| 101 |
140 d(i) = d(i) - h |
| 102 |
c |
| 103 |
145 f = f + h |
| 104 |
c .......... ql transformation .......... |
| 105 |
p = d(m) |
| 106 |
c = 1.0d0 |
| 107 |
c2 = c |
| 108 |
el1 = e(l1) |
| 109 |
s = 0.0d0 |
| 110 |
mml = m - l |
| 111 |
c .......... for i=m-1 step -1 until l do -- .......... |
| 112 |
do 200 ii = 1, mml |
| 113 |
c3 = c2 |
| 114 |
c2 = c |
| 115 |
s2 = s |
| 116 |
i = m - ii |
| 117 |
g = c * e(i) |
| 118 |
h = c * p |
| 119 |
r = pythag(p,e(i)) |
| 120 |
e(i+1) = s * r |
| 121 |
s = e(i) / r |
| 122 |
c = p / r |
| 123 |
p = c * d(i) - s * g |
| 124 |
d(i+1) = h + s * (c * g + s * d(i)) |
| 125 |
c .......... form vector .......... |
| 126 |
do 180 k = 1, n |
| 127 |
h = z(k,i+1) |
| 128 |
z(k,i+1) = s * z(k,i) + c * h |
| 129 |
z(k,i) = c * z(k,i) - s * h |
| 130 |
180 continue |
| 131 |
c |
| 132 |
200 continue |
| 133 |
c |
| 134 |
p = -s * s2 * c3 * el1 * e(l) / dl1 |
| 135 |
e(l) = s * p |
| 136 |
d(l) = c * p |
| 137 |
tst2 = tst1 + dabs(e(l)) |
| 138 |
if (tst2 .gt. tst1) go to 130 |
| 139 |
220 d(l) = d(l) + f |
| 140 |
240 continue |
| 141 |
c .......... order eigenvalues and eigenvectors .......... |
| 142 |
do 300 ii = 2, n |
| 143 |
i = ii - 1 |
| 144 |
k = i |
| 145 |
p = d(i) |
| 146 |
c |
| 147 |
do 260 j = ii, n |
| 148 |
if (d(j) .ge. p) go to 260 |
| 149 |
k = j |
| 150 |
p = d(j) |
| 151 |
260 continue |
| 152 |
c |
| 153 |
if (k .eq. i) go to 300 |
| 154 |
d(k) = d(i) |
| 155 |
d(i) = p |
| 156 |
c |
| 157 |
do 280 j = 1, n |
| 158 |
p = z(j,i) |
| 159 |
z(j,i) = z(j,k) |
| 160 |
z(j,k) = p |
| 161 |
280 continue |
| 162 |
c |
| 163 |
300 continue |
| 164 |
c |
| 165 |
go to 1001 |
| 166 |
c .......... set error -- no convergence to an |
| 167 |
c eigenvalue after 30 iterations .......... |
| 168 |
1000 ierr = l |
| 169 |
1001 return |
| 170 |
end |