bqr.f 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. *DECK BQR
  2. SUBROUTINE BQR (NM, N, MB, A, T, R, IERR, NV, RV)
  3. C***BEGIN PROLOGUE BQR
  4. C***PURPOSE Compute some of the eigenvalues of a real symmetric
  5. C matrix using the QR method with shifts of origin.
  6. C***LIBRARY SLATEC (EISPACK)
  7. C***CATEGORY D4A6
  8. C***TYPE SINGLE PRECISION (BQR-S)
  9. C***KEYWORDS EIGENVALUES, 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 BQR,
  14. C NUM. MATH. 16, 85-92(1970) by Martin, Reinsch, and Wilkinson.
  15. C HANDBOOK FOR AUTO. COMP., VOL II-LINEAR ALGEBRA, 266-272(1971).
  16. C
  17. C This subroutine finds the eigenvalue of smallest (usually)
  18. C magnitude of a REAL SYMMETRIC BAND matrix using the
  19. C QR algorithm with shifts of origin. Consecutive calls
  20. C can be made to find further eigenvalues.
  21. C
  22. C On INPUT
  23. C
  24. C NM must be set to the row dimension of the two-dimensional
  25. C array parameter, A, as declared in the calling program
  26. C dimension statement. NM is an INTEGER variable.
  27. C
  28. C N is the order of the matrix A. N is an INTEGER variable.
  29. C N must be less than or equal to NM.
  30. C
  31. C MB is the (half) band width of the matrix, defined as the
  32. C number of adjacent diagonals, including the principal
  33. C diagonal, required to specify the non-zero portion of the
  34. C lower triangle of the matrix. MB is an INTEGER variable.
  35. C MB must be less than or equal to N on first call.
  36. C
  37. C A contains the lower triangle of the symmetric band input
  38. C matrix stored as an N by MB array. Its lowest subdiagonal
  39. C is stored in the last N+1-MB positions of the first column,
  40. C its next subdiagonal in the last N+2-MB positions of the
  41. C second column, further subdiagonals similarly, and finally
  42. C its principal diagonal in the N positions of the last column.
  43. C Contents of storages not part of the matrix are arbitrary.
  44. C On a subsequent call, its output contents from the previous
  45. C call should be passed. A is a two-dimensional REAL array,
  46. C dimensioned A(NM,MB).
  47. C
  48. C T specifies the shift (of eigenvalues) applied to the diagonal
  49. C of A in forming the input matrix. What is actually determined
  50. C is the eigenvalue of A+TI (I is the identity matrix) nearest
  51. C to T. On a subsequent call, the output value of T from the
  52. C previous call should be passed if the next nearest eigenvalue
  53. C is sought. T is a REAL variable.
  54. C
  55. C R should be specified as zero on the first call, and as its
  56. C output value from the previous call on a subsequent call.
  57. C It is used to determine when the last row and column of
  58. C the transformed band matrix can be regarded as negligible.
  59. C R is a REAL variable.
  60. C
  61. C NV must be set to the dimension of the array parameter RV
  62. C as declared in the calling program dimension statement.
  63. C NV is an INTEGER variable.
  64. C
  65. C On OUTPUT
  66. C
  67. C A contains the transformed band matrix. The matrix A+TI
  68. C derived from the output parameters is similar to the
  69. C input A+TI to within rounding errors. Its last row and
  70. C column are null (if IERR is zero).
  71. C
  72. C T contains the computed eigenvalue of A+TI (if IERR is zero),
  73. C where I is the identity matrix.
  74. C
  75. C R contains the maximum of its input value and the norm of the
  76. C last column of the input matrix A.
  77. C
  78. C IERR is an INTEGER flag set to
  79. C Zero for normal return,
  80. C J if the J-th eigenvalue has not been
  81. C determined after a total of 30 iterations.
  82. C
  83. C RV is a one-dimensional REAL array of dimension NV which is
  84. C at least (2*MB**2+4*MB-3), used for temporary storage. The
  85. C first (3*MB-2) locations correspond to the ALGOL array B,
  86. C the next (2*MB-1) locations correspond to the ALGOL array H,
  87. C and the final (2*MB**2-MB) locations correspond to the MB
  88. C by (2*MB-1) ALGOL array U.
  89. C
  90. C NOTE. For a subsequent call, N should be replaced by N-1, but
  91. C MB should not be altered even when it exceeds the current N.
  92. C
  93. C Calls PYTHAG(A,B) for SQRT(A**2 + B**2).
  94. C
  95. C Questions and comments should be directed to B. S. Garbow,
  96. C Applied Mathematics Division, ARGONNE NATIONAL LABORATORY
  97. C ------------------------------------------------------------------
  98. C
  99. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  100. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  101. C system Routines - EISPACK Guide, Springer-Verlag,
  102. C 1976.
  103. C***ROUTINES CALLED PYTHAG
  104. C***REVISION HISTORY (YYMMDD)
  105. C 760101 DATE WRITTEN
  106. C 890531 Changed all specific intrinsics to generic. (WRB)
  107. C 890831 Modified array declarations. (WRB)
  108. C 890831 REVISION DATE from Version 3.2
  109. C 891214 Prologue converted to Version 4.0 format. (BAB)
  110. C 920501 Reformatted the REFERENCES section. (WRB)
  111. C***END PROLOGUE BQR
  112. C
  113. INTEGER I,J,K,L,M,N,II,IK,JK,JM,KJ,KK,KM,LL,MB,MK,MN,MZ
  114. INTEGER M1,M2,M3,M4,NI,NM,NV,ITS,KJ1,M21,M31,IERR,IMULT
  115. REAL A(NM,*),RV(*)
  116. REAL F,G,Q,R,S,T,SCALE
  117. REAL PYTHAG
  118. C
  119. C***FIRST EXECUTABLE STATEMENT BQR
  120. IERR = 0
  121. M1 = MIN(MB,N)
  122. M = M1 - 1
  123. M2 = M + M
  124. M21 = M2 + 1
  125. M3 = M21 + M
  126. M31 = M3 + 1
  127. M4 = M31 + M2
  128. MN = M + N
  129. MZ = MB - M1
  130. ITS = 0
  131. C .......... TEST FOR CONVERGENCE ..........
  132. 40 G = A(N,MB)
  133. IF (M .EQ. 0) GO TO 360
  134. F = 0.0E0
  135. C
  136. DO 50 K = 1, M
  137. MK = K + MZ
  138. F = F + ABS(A(N,MK))
  139. 50 CONTINUE
  140. C
  141. IF (ITS .EQ. 0 .AND. F .GT. R) R = F
  142. IF (R + F .LE. R) GO TO 360
  143. IF (ITS .EQ. 30) GO TO 1000
  144. ITS = ITS + 1
  145. C .......... FORM SHIFT FROM BOTTOM 2 BY 2 MINOR ..........
  146. IF (F .GT. 0.25E0 * R .AND. ITS .LT. 5) GO TO 90
  147. F = A(N,MB-1)
  148. IF (F .EQ. 0.0E0) GO TO 70
  149. Q = (A(N-1,MB) - G) / (2.0E0 * F)
  150. S = PYTHAG(Q,1.0E0)
  151. G = G - F / (Q + SIGN(S,Q))
  152. 70 T = T + G
  153. C
  154. DO 80 I = 1, N
  155. 80 A(I,MB) = A(I,MB) - G
  156. C
  157. 90 DO 100 K = M31, M4
  158. 100 RV(K) = 0.0E0
  159. C
  160. DO 350 II = 1, MN
  161. I = II - M
  162. NI = N - II
  163. IF (NI .LT. 0) GO TO 230
  164. C .......... FORM COLUMN OF SHIFTED MATRIX A-G*I ..........
  165. L = MAX(1,2-I)
  166. C
  167. DO 110 K = 1, M3
  168. 110 RV(K) = 0.0E0
  169. C
  170. DO 120 K = L, M1
  171. KM = K + M
  172. MK = K + MZ
  173. RV(KM) = A(II,MK)
  174. 120 CONTINUE
  175. C
  176. LL = MIN(M,NI)
  177. IF (LL .EQ. 0) GO TO 135
  178. C
  179. DO 130 K = 1, LL
  180. KM = K + M21
  181. IK = II + K
  182. MK = MB - K
  183. RV(KM) = A(IK,MK)
  184. 130 CONTINUE
  185. C .......... PRE-MULTIPLY WITH HOUSEHOLDER REFLECTIONS ..........
  186. 135 LL = M2
  187. IMULT = 0
  188. C .......... MULTIPLICATION PROCEDURE ..........
  189. 140 KJ = M4 - M1
  190. C
  191. DO 170 J = 1, LL
  192. KJ = KJ + M1
  193. JM = J + M3
  194. IF (RV(JM) .EQ. 0.0E0) GO TO 170
  195. F = 0.0E0
  196. C
  197. DO 150 K = 1, M1
  198. KJ = KJ + 1
  199. JK = J + K - 1
  200. F = F + RV(KJ) * RV(JK)
  201. 150 CONTINUE
  202. C
  203. F = F / RV(JM)
  204. KJ = KJ - M1
  205. C
  206. DO 160 K = 1, M1
  207. KJ = KJ + 1
  208. JK = J + K - 1
  209. RV(JK) = RV(JK) - RV(KJ) * F
  210. 160 CONTINUE
  211. C
  212. KJ = KJ - M1
  213. 170 CONTINUE
  214. C
  215. IF (IMULT .NE. 0) GO TO 280
  216. C .......... HOUSEHOLDER REFLECTION ..........
  217. F = RV(M21)
  218. S = 0.0E0
  219. RV(M4) = 0.0E0
  220. SCALE = 0.0E0
  221. C
  222. DO 180 K = M21, M3
  223. 180 SCALE = SCALE + ABS(RV(K))
  224. C
  225. IF (SCALE .EQ. 0.0E0) GO TO 210
  226. C
  227. DO 190 K = M21, M3
  228. 190 S = S + (RV(K)/SCALE)**2
  229. C
  230. S = SCALE * SCALE * S
  231. G = -SIGN(SQRT(S),F)
  232. RV(M21) = G
  233. RV(M4) = S - F * G
  234. KJ = M4 + M2 * M1 + 1
  235. RV(KJ) = F - G
  236. C
  237. DO 200 K = 2, M1
  238. KJ = KJ + 1
  239. KM = K + M2
  240. RV(KJ) = RV(KM)
  241. 200 CONTINUE
  242. C .......... SAVE COLUMN OF TRIANGULAR FACTOR R ..........
  243. 210 DO 220 K = L, M1
  244. KM = K + M
  245. MK = K + MZ
  246. A(II,MK) = RV(KM)
  247. 220 CONTINUE
  248. C
  249. 230 L = MAX(1,M1+1-I)
  250. IF (I .LE. 0) GO TO 300
  251. C .......... PERFORM ADDITIONAL STEPS ..........
  252. DO 240 K = 1, M21
  253. 240 RV(K) = 0.0E0
  254. C
  255. LL = MIN(M1,NI+M1)
  256. C .......... GET ROW OF TRIANGULAR FACTOR R ..........
  257. DO 250 KK = 1, LL
  258. K = KK - 1
  259. KM = K + M1
  260. IK = I + K
  261. MK = MB - K
  262. RV(KM) = A(IK,MK)
  263. 250 CONTINUE
  264. C .......... POST-MULTIPLY WITH HOUSEHOLDER REFLECTIONS ..........
  265. LL = M1
  266. IMULT = 1
  267. GO TO 140
  268. C .......... STORE COLUMN OF NEW A MATRIX ..........
  269. 280 DO 290 K = L, M1
  270. MK = K + MZ
  271. A(I,MK) = RV(K)
  272. 290 CONTINUE
  273. C .......... UPDATE HOUSEHOLDER REFLECTIONS ..........
  274. 300 IF (L .GT. 1) L = L - 1
  275. KJ1 = M4 + L * M1
  276. C
  277. DO 320 J = L, M2
  278. JM = J + M3
  279. RV(JM) = RV(JM+1)
  280. C
  281. DO 320 K = 1, M1
  282. KJ1 = KJ1 + 1
  283. KJ = KJ1 - M1
  284. RV(KJ) = RV(KJ1)
  285. 320 CONTINUE
  286. C
  287. 350 CONTINUE
  288. C
  289. GO TO 40
  290. C .......... CONVERGENCE ..........
  291. 360 T = T + G
  292. C
  293. DO 380 I = 1, N
  294. 380 A(I,MB) = A(I,MB) - G
  295. C
  296. DO 400 K = 1, M1
  297. MK = K + MZ
  298. A(N,MK) = 0.0E0
  299. 400 CONTINUE
  300. C
  301. GO TO 1001
  302. C .......... SET ERROR -- NO CONVERGENCE TO
  303. C EIGENVALUE AFTER 30 ITERATIONS ..........
  304. 1000 IERR = N
  305. 1001 RETURN
  306. END