bandr.f 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. *DECK BANDR
  2. SUBROUTINE BANDR (NM, N, MB, A, D, E, E2, MATZ, Z)
  3. C***BEGIN PROLOGUE BANDR
  4. C***PURPOSE Reduce a real symmetric band matrix to symmetric
  5. C tridiagonal matrix and, optionally, accumulate
  6. C orthogonal similarity transformations.
  7. C***LIBRARY SLATEC (EISPACK)
  8. C***CATEGORY D4C1B1
  9. C***TYPE SINGLE PRECISION (BANDR-S)
  10. C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
  11. C***AUTHOR Smith, B. T., et al.
  12. C***DESCRIPTION
  13. C
  14. C This subroutine is a translation of the ALGOL procedure BANDRD,
  15. C NUM. MATH. 12, 231-241(1968) by Schwarz.
  16. C HANDBOOK FOR AUTO. COMP., VOL.II-LINEAR ALGEBRA, 273-283(1971).
  17. C
  18. C This subroutine reduces a REAL SYMMETRIC BAND matrix
  19. C to a symmetric tridiagonal matrix using and optionally
  20. C accumulating orthogonal similarity transformations.
  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 parameters, A and Z, as declared in the calling
  26. C program 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 less than or equal
  35. C to N. MB is an INTEGER variable.
  36. C
  37. C A contains the lower triangle of the real symmetric band
  38. C matrix. Its lowest subdiagonal is stored in the last
  39. C N+1-MB positions of the first column, its next subdiagonal
  40. C in the last N+2-MB positions of the second column, further
  41. C subdiagonals similarly, and finally its principal diagonal
  42. C in the N positions of the last column. Contents of storage
  43. C locations not part of the matrix are arbitrary. A is a
  44. C two-dimensional REAL array, dimensioned A(NM,MB).
  45. C
  46. C MATZ should be set to .TRUE. if the transformation matrix is
  47. C to be accumulated, and to .FALSE. otherwise. MATZ is a
  48. C LOGICAL variable.
  49. C
  50. C On OUTPUT
  51. C
  52. C A has been destroyed, except for its last two columns which
  53. C contain a copy of the tridiagonal matrix.
  54. C
  55. C D contains the diagonal elements of the tridiagonal matrix.
  56. C D is a one-dimensional REAL array, dimensioned D(N).
  57. C
  58. C E contains the subdiagonal elements of the tridiagonal
  59. C matrix in its last N-1 positions. E(1) is set to zero.
  60. C E is a one-dimensional REAL array, dimensioned E(N).
  61. C
  62. C E2 contains the squares of the corresponding elements of E.
  63. C E2 may coincide with E if the squares are not needed.
  64. C E2 is a one-dimensional REAL array, dimensioned E2(N).
  65. C
  66. C Z contains the orthogonal transformation matrix produced in
  67. C the reduction if MATZ has been set to .TRUE. Otherwise, Z
  68. C is not referenced. Z is a two-dimensional REAL array,
  69. C dimensioned Z(NM,N).
  70. C
  71. C Questions and comments should be directed to B. S. Garbow,
  72. C Applied Mathematics Division, ARGONNE NATIONAL LABORATORY
  73. C ------------------------------------------------------------------
  74. C
  75. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  76. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  77. C system Routines - EISPACK Guide, Springer-Verlag,
  78. C 1976.
  79. C***ROUTINES CALLED (NONE)
  80. C***REVISION HISTORY (YYMMDD)
  81. C 760101 DATE WRITTEN
  82. C 890531 Changed all specific intrinsics to generic. (WRB)
  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 BANDR
  88. C
  89. INTEGER J,K,L,N,R,I1,I2,J1,J2,KR,MB,MR,M1,NM,N2,R1,UGL,MAXL,MAXR
  90. REAL A(NM,*),D(*),E(*),E2(*),Z(NM,*)
  91. REAL G,U,B1,B2,C2,F1,F2,S2,DMIN,DMINRT
  92. LOGICAL MATZ
  93. C
  94. C***FIRST EXECUTABLE STATEMENT BANDR
  95. DMIN = 2.0E0**(-64)
  96. DMINRT = 2.0E0**(-32)
  97. C .......... INITIALIZE DIAGONAL SCALING MATRIX ..........
  98. DO 30 J = 1, N
  99. 30 D(J) = 1.0E0
  100. C
  101. IF (.NOT. MATZ) GO TO 60
  102. C
  103. DO 50 J = 1, N
  104. C
  105. DO 40 K = 1, N
  106. 40 Z(J,K) = 0.0E0
  107. C
  108. Z(J,J) = 1.0E0
  109. 50 CONTINUE
  110. C
  111. 60 M1 = MB - 1
  112. IF (M1 - 1) 900, 800, 70
  113. 70 N2 = N - 2
  114. C
  115. DO 700 K = 1, N2
  116. MAXR = MIN(M1,N-K)
  117. C .......... FOR R=MAXR STEP -1 UNTIL 2 DO -- ..........
  118. DO 600 R1 = 2, MAXR
  119. R = MAXR + 2 - R1
  120. KR = K + R
  121. MR = MB - R
  122. G = A(KR,MR)
  123. A(KR-1,1) = A(KR-1,MR+1)
  124. UGL = K
  125. C
  126. DO 500 J = KR, N, M1
  127. J1 = J - 1
  128. J2 = J1 - 1
  129. IF (G .EQ. 0.0E0) GO TO 600
  130. B1 = A(J1,1) / G
  131. B2 = B1 * D(J1) / D(J)
  132. S2 = 1.0E0 / (1.0E0 + B1 * B2)
  133. IF (S2 .GE. 0.5E0 ) GO TO 450
  134. B1 = G / A(J1,1)
  135. B2 = B1 * D(J) / D(J1)
  136. C2 = 1.0E0 - S2
  137. D(J1) = C2 * D(J1)
  138. D(J) = C2 * D(J)
  139. F1 = 2.0E0 * A(J,M1)
  140. F2 = B1 * A(J1,MB)
  141. A(J,M1) = -B2 * (B1 * A(J,M1) - A(J,MB)) - F2 + A(J,M1)
  142. A(J1,MB) = B2 * (B2 * A(J,MB) + F1) + A(J1,MB)
  143. A(J,MB) = B1 * (F2 - F1) + A(J,MB)
  144. C
  145. DO 200 L = UGL, J2
  146. I2 = MB - J + L
  147. U = A(J1,I2+1) + B2 * A(J,I2)
  148. A(J,I2) = -B1 * A(J1,I2+1) + A(J,I2)
  149. A(J1,I2+1) = U
  150. 200 CONTINUE
  151. C
  152. UGL = J
  153. A(J1,1) = A(J1,1) + B2 * G
  154. IF (J .EQ. N) GO TO 350
  155. MAXL = MIN(M1,N-J1)
  156. C
  157. DO 300 L = 2, MAXL
  158. I1 = J1 + L
  159. I2 = MB - L
  160. U = A(I1,I2) + B2 * A(I1,I2+1)
  161. A(I1,I2+1) = -B1 * A(I1,I2) + A(I1,I2+1)
  162. A(I1,I2) = U
  163. 300 CONTINUE
  164. C
  165. I1 = J + M1
  166. IF (I1 .GT. N) GO TO 350
  167. G = B2 * A(I1,1)
  168. 350 IF (.NOT. MATZ) GO TO 500
  169. C
  170. DO 400 L = 1, N
  171. U = Z(L,J1) + B2 * Z(L,J)
  172. Z(L,J) = -B1 * Z(L,J1) + Z(L,J)
  173. Z(L,J1) = U
  174. 400 CONTINUE
  175. C
  176. GO TO 500
  177. C
  178. 450 U = D(J1)
  179. D(J1) = S2 * D(J)
  180. D(J) = S2 * U
  181. F1 = 2.0E0 * A(J,M1)
  182. F2 = B1 * A(J,MB)
  183. U = B1 * (F2 - F1) + A(J1,MB)
  184. A(J,M1) = B2 * (B1 * A(J,M1) - A(J1,MB)) + F2 - A(J,M1)
  185. A(J1,MB) = B2 * (B2 * A(J1,MB) + F1) + A(J,MB)
  186. A(J,MB) = U
  187. C
  188. DO 460 L = UGL, J2
  189. I2 = MB - J + L
  190. U = B2 * A(J1,I2+1) + A(J,I2)
  191. A(J,I2) = -A(J1,I2+1) + B1 * A(J,I2)
  192. A(J1,I2+1) = U
  193. 460 CONTINUE
  194. C
  195. UGL = J
  196. A(J1,1) = B2 * A(J1,1) + G
  197. IF (J .EQ. N) GO TO 480
  198. MAXL = MIN(M1,N-J1)
  199. C
  200. DO 470 L = 2, MAXL
  201. I1 = J1 + L
  202. I2 = MB - L
  203. U = B2 * A(I1,I2) + A(I1,I2+1)
  204. A(I1,I2+1) = -A(I1,I2) + B1 * A(I1,I2+1)
  205. A(I1,I2) = U
  206. 470 CONTINUE
  207. C
  208. I1 = J + M1
  209. IF (I1 .GT. N) GO TO 480
  210. G = A(I1,1)
  211. A(I1,1) = B1 * A(I1,1)
  212. 480 IF (.NOT. MATZ) GO TO 500
  213. C
  214. DO 490 L = 1, N
  215. U = B2 * Z(L,J1) + Z(L,J)
  216. Z(L,J) = -Z(L,J1) + B1 * Z(L,J)
  217. Z(L,J1) = U
  218. 490 CONTINUE
  219. C
  220. 500 CONTINUE
  221. C
  222. 600 CONTINUE
  223. C
  224. IF (MOD(K,64) .NE. 0) GO TO 700
  225. C .......... RESCALE TO AVOID UNDERFLOW OR OVERFLOW ..........
  226. DO 650 J = K, N
  227. IF (D(J) .GE. DMIN) GO TO 650
  228. MAXL = MAX(1,MB+1-J)
  229. C
  230. DO 610 L = MAXL, M1
  231. 610 A(J,L) = DMINRT * A(J,L)
  232. C
  233. IF (J .EQ. N) GO TO 630
  234. MAXL = MIN(M1,N-J)
  235. C
  236. DO 620 L = 1, MAXL
  237. I1 = J + L
  238. I2 = MB - L
  239. A(I1,I2) = DMINRT * A(I1,I2)
  240. 620 CONTINUE
  241. C
  242. 630 IF (.NOT. MATZ) GO TO 645
  243. C
  244. DO 640 L = 1, N
  245. 640 Z(L,J) = DMINRT * Z(L,J)
  246. C
  247. 645 A(J,MB) = DMIN * A(J,MB)
  248. D(J) = D(J) / DMIN
  249. 650 CONTINUE
  250. C
  251. 700 CONTINUE
  252. C .......... FORM SQUARE ROOT OF SCALING MATRIX ..........
  253. 800 DO 810 J = 2, N
  254. 810 E(J) = SQRT(D(J))
  255. C
  256. IF (.NOT. MATZ) GO TO 840
  257. C
  258. DO 830 J = 1, N
  259. C
  260. DO 820 K = 2, N
  261. 820 Z(J,K) = E(K) * Z(J,K)
  262. C
  263. 830 CONTINUE
  264. C
  265. 840 U = 1.0E0
  266. C
  267. DO 850 J = 2, N
  268. A(J,M1) = U * E(J) * A(J,M1)
  269. U = E(J)
  270. E2(J) = A(J,M1) ** 2
  271. A(J,MB) = D(J) * A(J,MB)
  272. D(J) = A(J,MB)
  273. E(J) = A(J,M1)
  274. 850 CONTINUE
  275. C
  276. D(1) = A(1,MB)
  277. E(1) = 0.0E0
  278. E2(1) = 0.0E0
  279. GO TO 1001
  280. C
  281. 900 DO 950 J = 1, N
  282. D(J) = A(J,MB)
  283. E(J) = 0.0E0
  284. E2(J) = 0.0E0
  285. 950 CONTINUE
  286. C
  287. 1001 RETURN
  288. END