imtql2.f 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. *DECK IMTQL2
  2. SUBROUTINE IMTQL2 (NM, N, D, E, Z, IERR)
  3. C***BEGIN PROLOGUE IMTQL2
  4. C***PURPOSE Compute the eigenvalues and eigenvectors of a symmetric
  5. C tridiagonal matrix using the implicit QL method.
  6. C***LIBRARY SLATEC (EISPACK)
  7. C***CATEGORY D4A5, D4C2A
  8. C***TYPE SINGLE PRECISION (IMTQL2-S)
  9. C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
  10. C***AUTHOR Smith, B. T., et al.
  11. C***DESCRIPTION
  12. C
  13. C This subroutine is a translation of the ALGOL procedure IMTQL2,
  14. C NUM. MATH. 12, 377-383(1968) by Martin and Wilkinson,
  15. C as modified in NUM. MATH. 15, 450(1970) by Dubrulle.
  16. C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 241-248(1971).
  17. C
  18. C This subroutine finds the eigenvalues and eigenvectors
  19. C of a SYMMETRIC TRIDIAGONAL matrix by the implicit QL method.
  20. C The eigenvectors of a FULL SYMMETRIC matrix can also
  21. C be found if TRED2 has been used to reduce this
  22. C full matrix to tridiagonal form.
  23. C
  24. C On INPUT
  25. C
  26. C NM must be set to the row dimension of the two-dimensional
  27. C array parameter, Z, as declared in the calling program
  28. C dimension statement. NM is an INTEGER variable.
  29. C
  30. C N is the order of the matrix. N is an INTEGER variable.
  31. C N must be less than or equal to NM.
  32. C
  33. C D contains the diagonal elements of the symmetric tridiagonal
  34. C matrix. D is a one-dimensional REAL array, dimensioned D(N).
  35. C
  36. C E contains the subdiagonal elements of the symmetric
  37. C tridiagonal matrix in its last N-1 positions. E(1) is
  38. C arbitrary. E is a one-dimensional REAL array, dimensioned
  39. C E(N).
  40. C
  41. C Z contains the transformation matrix produced in the reduction
  42. C by TRED2, if performed. This transformation matrix is
  43. C necessary if you want to obtain the eigenvectors of the full
  44. C symmetric matrix. If the eigenvectors of the symmetric
  45. C tridiagonal matrix are desired, Z must contain the identity
  46. C matrix. Z is a two-dimensional REAL array, dimensioned
  47. C Z(NM,N).
  48. C
  49. C On OUTPUT
  50. C
  51. C D contains the eigenvalues in ascending order. If an
  52. C error exit is made, the eigenvalues are correct but
  53. C unordered for indices 1, 2, ..., IERR-1.
  54. C
  55. C E has been destroyed.
  56. C
  57. C Z contains orthonormal eigenvectors of the full symmetric
  58. C or symmetric tridiagonal matrix, depending on what it
  59. C contained on input. If an error exit is made, Z contains
  60. C the eigenvectors associated with the stored eigenvalues.
  61. C
  62. C IERR is an INTEGER flag set to
  63. C Zero for normal return,
  64. C J if the J-th eigenvalue has not been
  65. C determined after 30 iterations.
  66. C The eigenvalues and eigenvectors should be correct
  67. C for indices 1, 2, ..., IERR-1, but the eigenvalues
  68. C are not ordered.
  69. C
  70. C Calls PYTHAG(A,B) for sqrt(A**2 + B**2).
  71. C
  72. C Questions and comments should be directed to B. S. Garbow,
  73. C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
  74. C ------------------------------------------------------------------
  75. C
  76. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  77. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  78. C system Routines - EISPACK Guide, Springer-Verlag,
  79. C 1976.
  80. C***ROUTINES CALLED PYTHAG
  81. C***REVISION HISTORY (YYMMDD)
  82. C 760101 DATE WRITTEN
  83. C 890831 Modified array declarations. (WRB)
  84. C 890831 REVISION DATE from Version 3.2
  85. C 891214 Prologue converted to Version 4.0 format. (BAB)
  86. C 920501 Reformatted the REFERENCES section. (WRB)
  87. C***END PROLOGUE IMTQL2
  88. C
  89. INTEGER I,J,K,L,M,N,II,NM,MML,IERR
  90. REAL D(*),E(*),Z(NM,*)
  91. REAL B,C,F,G,P,R,S,S1,S2
  92. REAL PYTHAG
  93. C
  94. C***FIRST EXECUTABLE STATEMENT IMTQL2
  95. IERR = 0
  96. IF (N .EQ. 1) GO TO 1001
  97. C
  98. DO 100 I = 2, N
  99. 100 E(I-1) = E(I)
  100. C
  101. E(N) = 0.0E0
  102. C
  103. DO 240 L = 1, N
  104. J = 0
  105. C .......... LOOK FOR SMALL SUB-DIAGONAL ELEMENT ..........
  106. 105 DO 110 M = L, N
  107. IF (M .EQ. N) GO TO 120
  108. S1 = ABS(D(M)) + ABS(D(M+1))
  109. S2 = S1 + ABS(E(M))
  110. IF (S2 .EQ. S1) GO TO 120
  111. 110 CONTINUE
  112. C
  113. 120 P = D(L)
  114. IF (M .EQ. L) GO TO 240
  115. IF (J .EQ. 30) GO TO 1000
  116. J = J + 1
  117. C .......... FORM SHIFT ..........
  118. G = (D(L+1) - P) / (2.0E0 * E(L))
  119. R = PYTHAG(G,1.0E0)
  120. G = D(M) - P + E(L) / (G + SIGN(R,G))
  121. S = 1.0E0
  122. C = 1.0E0
  123. P = 0.0E0
  124. MML = M - L
  125. C .......... FOR I=M-1 STEP -1 UNTIL L DO -- ..........
  126. DO 200 II = 1, MML
  127. I = M - II
  128. F = S * E(I)
  129. B = C * E(I)
  130. IF (ABS(F) .LT. ABS(G)) GO TO 150
  131. C = G / F
  132. R = SQRT(C*C+1.0E0)
  133. E(I+1) = F * R
  134. S = 1.0E0 / R
  135. C = C * S
  136. GO TO 160
  137. 150 S = F / G
  138. R = SQRT(S*S+1.0E0)
  139. E(I+1) = G * R
  140. C = 1.0E0 / R
  141. S = S * C
  142. 160 G = D(I+1) - P
  143. R = (D(I) - G) * S + 2.0E0 * C * B
  144. P = S * R
  145. D(I+1) = G + P
  146. G = C * R - B
  147. C .......... FORM VECTOR ..........
  148. DO 180 K = 1, N
  149. F = Z(K,I+1)
  150. Z(K,I+1) = S * Z(K,I) + C * F
  151. Z(K,I) = C * Z(K,I) - S * F
  152. 180 CONTINUE
  153. C
  154. 200 CONTINUE
  155. C
  156. D(L) = D(L) - P
  157. E(L) = G
  158. E(M) = 0.0E0
  159. GO TO 105
  160. 240 CONTINUE
  161. C .......... ORDER EIGENVALUES AND EIGENVECTORS ..........
  162. DO 300 II = 2, N
  163. I = II - 1
  164. K = I
  165. P = D(I)
  166. C
  167. DO 260 J = II, N
  168. IF (D(J) .GE. P) GO TO 260
  169. K = J
  170. P = D(J)
  171. 260 CONTINUE
  172. C
  173. IF (K .EQ. I) GO TO 300
  174. D(K) = D(I)
  175. D(I) = P
  176. C
  177. DO 280 J = 1, N
  178. P = Z(J,I)
  179. Z(J,I) = Z(J,K)
  180. Z(J,K) = P
  181. 280 CONTINUE
  182. C
  183. 300 CONTINUE
  184. C
  185. GO TO 1001
  186. C .......... SET ERROR -- NO CONVERGENCE TO AN
  187. C EIGENVALUE AFTER 30 ITERATIONS ..........
  188. 1000 IERR = L
  189. 1001 RETURN
  190. END