bandv.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. *DECK BANDV
  2. SUBROUTINE BANDV (NM, N, MBW, A, E21, M, W, Z, IERR, NV, RV, RV6)
  3. C***BEGIN PROLOGUE BANDV
  4. C***PURPOSE Form the eigenvectors of a real symmetric band matrix
  5. C associated with a set of ordered approximate eigenvalues
  6. C by inverse iteration.
  7. C***LIBRARY SLATEC (EISPACK)
  8. C***CATEGORY D4C3
  9. C***TYPE SINGLE PRECISION (BANDV-S)
  10. C***KEYWORDS EIGENVECTORS, EISPACK
  11. C***AUTHOR Smith, B. T., et al.
  12. C***DESCRIPTION
  13. C
  14. C This subroutine finds those eigenvectors of a REAL SYMMETRIC
  15. C BAND matrix corresponding to specified eigenvalues, using inverse
  16. C iteration. The subroutine may also be used to solve systems
  17. C of linear equations with a symmetric or non-symmetric band
  18. C coefficient matrix.
  19. C
  20. C On INPUT
  21. C
  22. C NM must be set to the row dimension of the two-dimensional
  23. C array parameters, A and Z, as declared in the calling
  24. C program dimension statement. NM is an INTEGER variable.
  25. C
  26. C N is the order of the matrix A. N is an INTEGER variable.
  27. C N must be less than or equal to NM.
  28. C
  29. C MBW is the number of columns of the array A used to store the
  30. C band matrix. If the matrix is symmetric, MBW is its (half)
  31. C band width, denoted MB and defined as the number of adjacent
  32. C diagonals, including the principal diagonal, required to
  33. C specify the non-zero portion of the lower triangle of the
  34. C matrix. If the subroutine is being used to solve systems
  35. C of linear equations and the coefficient matrix is not
  36. C symmetric, it must however have the same number of adjacent
  37. C diagonals above the main diagonal as below, and in this
  38. C case, MBW=2*MB-1. MBW is an INTEGER variable. MB must not
  39. C be greater than N.
  40. C
  41. C A contains the lower triangle of the symmetric band input
  42. C matrix stored as an N by MB array. Its lowest subdiagonal
  43. C is stored in the last N+1-MB positions of the first column,
  44. C its next subdiagonal in the last N+2-MB positions of the
  45. C second column, further subdiagonals similarly, and finally
  46. C its principal diagonal in the N positions of column MB.
  47. C If the subroutine is being used to solve systems of linear
  48. C equations and the coefficient matrix is not symmetric, A is
  49. C N by 2*MB-1 instead with lower triangle as above and with
  50. C its first superdiagonal stored in the first N-1 positions of
  51. C column MB+1, its second superdiagonal in the first N-2
  52. C positions of column MB+2, further superdiagonals similarly,
  53. C and finally its highest superdiagonal in the first N+1-MB
  54. C positions of the last column. Contents of storage locations
  55. C not part of the matrix are arbitrary. A is a two-dimensional
  56. C REAL array, dimensioned A(NM,MBW).
  57. C
  58. C E21 specifies the ordering of the eigenvalues and contains
  59. C 0.0E0 if the eigenvalues are in ascending order, or
  60. C 2.0E0 if the eigenvalues are in descending order.
  61. C If the subroutine is being used to solve systems of linear
  62. C equations, E21 should be set to 1.0E0 if the coefficient
  63. C matrix is symmetric and to -1.0E0 if not. E21 is a REAL
  64. C variable.
  65. C
  66. C M is the number of specified eigenvalues or the number of
  67. C systems of linear equations. M is an INTEGER variable.
  68. C
  69. C W contains the M eigenvalues in ascending or descending order.
  70. C If the subroutine is being used to solve systems of linear
  71. C equations (A-W(J)*I)*X(J)=B(J), where I is the identity
  72. C matrix, W(J) should be set accordingly, for J=1,2,...,M.
  73. C W is a one-dimensional REAL array, dimensioned W(M).
  74. C
  75. C Z contains the constant matrix columns (B(J),J=1,2,...,M), if
  76. C the subroutine is used to solve systems of linear equations.
  77. C Z is a two-dimensional REAL array, dimensioned Z(NM,M).
  78. C
  79. C NV must be set to the dimension of the array parameter RV
  80. C as declared in the calling program dimension statement.
  81. C NV is an INTEGER variable.
  82. C
  83. C On OUTPUT
  84. C
  85. C A and W are unaltered.
  86. C
  87. C Z contains the associated set of orthogonal eigenvectors.
  88. C Any vector which fails to converge is set to zero. If the
  89. C subroutine is used to solve systems of linear equations,
  90. C Z contains the solution matrix columns (X(J),J=1,2,...,M).
  91. C
  92. C IERR is an INTEGER flag set to
  93. C Zero for normal return,
  94. C -J if the eigenvector corresponding to the J-th
  95. C eigenvalue fails to converge, or if the J-th
  96. C system of linear equations is nearly singular.
  97. C
  98. C RV and RV6 are temporary storage arrays. If the subroutine
  99. C is being used to solve systems of linear equations, the
  100. C determinant (up to sign) of A-W(M)*I is available, upon
  101. C return, as the product of the first N elements of RV.
  102. C RV and RV6 are one-dimensional REAL arrays. Note that RV
  103. C is dimensioned RV(NV), where NV must be at least N*(2*MB-1).
  104. C RV6 is dimensioned RV6(N).
  105. C
  106. C Questions and comments should be directed to B. S. Garbow,
  107. C Applied Mathematics Division, ARGONNE NATIONAL LABORATORY
  108. C ------------------------------------------------------------------
  109. C
  110. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  111. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  112. C system Routines - EISPACK Guide, Springer-Verlag,
  113. C 1976.
  114. C***ROUTINES CALLED (NONE)
  115. C***REVISION HISTORY (YYMMDD)
  116. C 760101 DATE WRITTEN
  117. C 890531 Changed all specific intrinsics to generic. (WRB)
  118. C 890831 Modified array declarations. (WRB)
  119. C 890831 REVISION DATE from Version 3.2
  120. C 891214 Prologue converted to Version 4.0 format. (BAB)
  121. C 920501 Reformatted the REFERENCES section. (WRB)
  122. C***END PROLOGUE BANDV
  123. C
  124. INTEGER I,J,K,M,N,R,II,IJ,JJ,KJ,MB,M1,NM,NV,IJ1,ITS,KJ1,MBW,M21
  125. INTEGER IERR,MAXJ,MAXK,GROUP
  126. REAL A(NM,*),W(*),Z(NM,*),RV(*),RV6(*)
  127. REAL U,V,UK,XU,X0,X1,E21,EPS2,EPS3,EPS4,NORM,ORDER,S
  128. C
  129. C***FIRST EXECUTABLE STATEMENT BANDV
  130. IERR = 0
  131. IF (M .EQ. 0) GO TO 1001
  132. MB = MBW
  133. IF (E21 .LT. 0.0E0) MB = (MBW + 1) / 2
  134. M1 = MB - 1
  135. M21 = M1 + MB
  136. ORDER = 1.0E0 - ABS(E21)
  137. C .......... FIND VECTORS BY INVERSE ITERATION ..........
  138. DO 920 R = 1, M
  139. ITS = 1
  140. X1 = W(R)
  141. IF (R .NE. 1) GO TO 100
  142. C .......... COMPUTE NORM OF MATRIX ..........
  143. NORM = 0.0E0
  144. C
  145. DO 60 J = 1, MB
  146. JJ = MB + 1 - J
  147. KJ = JJ + M1
  148. IJ = 1
  149. S = 0.0E0
  150. C
  151. DO 40 I = JJ, N
  152. S = S + ABS(A(I,J))
  153. IF (E21 .GE. 0.0E0) GO TO 40
  154. S = S + ABS(A(IJ,KJ))
  155. IJ = IJ + 1
  156. 40 CONTINUE
  157. C
  158. NORM = MAX(NORM,S)
  159. 60 CONTINUE
  160. C
  161. IF (E21 .LT. 0.0E0) NORM = 0.5E0 * NORM
  162. C .......... EPS2 IS THE CRITERION FOR GROUPING,
  163. C EPS3 REPLACES ZERO PIVOTS AND EQUAL
  164. C ROOTS ARE MODIFIED BY EPS3,
  165. C EPS4 IS TAKEN VERY SMALL TO AVOID OVERFLOW ..........
  166. IF (NORM .EQ. 0.0E0) NORM = 1.0E0
  167. EPS2 = 1.0E-3 * NORM * ABS(ORDER)
  168. EPS3 = NORM
  169. 70 EPS3 = 0.5E0*EPS3
  170. IF (NORM + EPS3 .GT. NORM) GO TO 70
  171. UK = SQRT(REAL(N))
  172. EPS3 = UK * EPS3
  173. EPS4 = UK * EPS3
  174. 80 GROUP = 0
  175. GO TO 120
  176. C .......... LOOK FOR CLOSE OR COINCIDENT ROOTS ..........
  177. 100 IF (ABS(X1-X0) .GE. EPS2) GO TO 80
  178. GROUP = GROUP + 1
  179. IF (ORDER * (X1 - X0) .LE. 0.0E0) X1 = X0 + ORDER * EPS3
  180. C .......... EXPAND MATRIX, SUBTRACT EIGENVALUE,
  181. C AND INITIALIZE VECTOR ..........
  182. 120 DO 200 I = 1, N
  183. IJ = I + MIN(0,I-M1) * N
  184. KJ = IJ + MB * N
  185. IJ1 = KJ + M1 * N
  186. IF (M1 .EQ. 0) GO TO 180
  187. C
  188. DO 150 J = 1, M1
  189. IF (IJ .GT. M1) GO TO 125
  190. IF (IJ .GT. 0) GO TO 130
  191. RV(IJ1) = 0.0E0
  192. IJ1 = IJ1 + N
  193. GO TO 130
  194. 125 RV(IJ) = A(I,J)
  195. 130 IJ = IJ + N
  196. II = I + J
  197. IF (II .GT. N) GO TO 150
  198. JJ = MB - J
  199. IF (E21 .GE. 0.0E0) GO TO 140
  200. II = I
  201. JJ = MB + J
  202. 140 RV(KJ) = A(II,JJ)
  203. KJ = KJ + N
  204. 150 CONTINUE
  205. C
  206. 180 RV(IJ) = A(I,MB) - X1
  207. RV6(I) = EPS4
  208. IF (ORDER .EQ. 0.0E0) RV6(I) = Z(I,R)
  209. 200 CONTINUE
  210. C
  211. IF (M1 .EQ. 0) GO TO 600
  212. C .......... ELIMINATION WITH INTERCHANGES ..........
  213. DO 580 I = 1, N
  214. II = I + 1
  215. MAXK = MIN(I+M1-1,N)
  216. MAXJ = MIN(N-I,M21-2) * N
  217. C
  218. DO 360 K = I, MAXK
  219. KJ1 = K
  220. J = KJ1 + N
  221. JJ = J + MAXJ
  222. C
  223. DO 340 KJ = J, JJ, N
  224. RV(KJ1) = RV(KJ)
  225. KJ1 = KJ
  226. 340 CONTINUE
  227. C
  228. RV(KJ1) = 0.0E0
  229. 360 CONTINUE
  230. C
  231. IF (I .EQ. N) GO TO 580
  232. U = 0.0E0
  233. MAXK = MIN(I+M1,N)
  234. MAXJ = MIN(N-II,M21-2) * N
  235. C
  236. DO 450 J = I, MAXK
  237. IF (ABS(RV(J)) .LT. ABS(U)) GO TO 450
  238. U = RV(J)
  239. K = J
  240. 450 CONTINUE
  241. C
  242. J = I + N
  243. JJ = J + MAXJ
  244. IF (K .EQ. I) GO TO 520
  245. KJ = K
  246. C
  247. DO 500 IJ = I, JJ, N
  248. V = RV(IJ)
  249. RV(IJ) = RV(KJ)
  250. RV(KJ) = V
  251. KJ = KJ + N
  252. 500 CONTINUE
  253. C
  254. IF (ORDER .NE. 0.0E0) GO TO 520
  255. V = RV6(I)
  256. RV6(I) = RV6(K)
  257. RV6(K) = V
  258. 520 IF (U .EQ. 0.0E0) GO TO 580
  259. C
  260. DO 560 K = II, MAXK
  261. V = RV(K) / U
  262. KJ = K
  263. C
  264. DO 540 IJ = J, JJ, N
  265. KJ = KJ + N
  266. RV(KJ) = RV(KJ) - V * RV(IJ)
  267. 540 CONTINUE
  268. C
  269. IF (ORDER .EQ. 0.0E0) RV6(K) = RV6(K) - V * RV6(I)
  270. 560 CONTINUE
  271. C
  272. 580 CONTINUE
  273. C .......... BACK SUBSTITUTION
  274. C FOR I=N STEP -1 UNTIL 1 DO -- ..........
  275. 600 DO 630 II = 1, N
  276. I = N + 1 - II
  277. MAXJ = MIN(II,M21)
  278. IF (MAXJ .EQ. 1) GO TO 620
  279. IJ1 = I
  280. J = IJ1 + N
  281. JJ = J + (MAXJ - 2) * N
  282. C
  283. DO 610 IJ = J, JJ, N
  284. IJ1 = IJ1 + 1
  285. RV6(I) = RV6(I) - RV(IJ) * RV6(IJ1)
  286. 610 CONTINUE
  287. C
  288. 620 V = RV(I)
  289. IF (ABS(V) .GE. EPS3) GO TO 625
  290. C .......... SET ERROR -- NEARLY SINGULAR LINEAR SYSTEM ..........
  291. IF (ORDER .EQ. 0.0E0) IERR = -R
  292. V = SIGN(EPS3,V)
  293. 625 RV6(I) = RV6(I) / V
  294. 630 CONTINUE
  295. C
  296. XU = 1.0E0
  297. IF (ORDER .EQ. 0.0E0) GO TO 870
  298. C .......... ORTHOGONALIZE WITH RESPECT TO PREVIOUS
  299. C MEMBERS OF GROUP ..........
  300. IF (GROUP .EQ. 0) GO TO 700
  301. C
  302. DO 680 JJ = 1, GROUP
  303. J = R - GROUP - 1 + JJ
  304. XU = 0.0E0
  305. C
  306. DO 640 I = 1, N
  307. 640 XU = XU + RV6(I) * Z(I,J)
  308. C
  309. DO 660 I = 1, N
  310. 660 RV6(I) = RV6(I) - XU * Z(I,J)
  311. C
  312. 680 CONTINUE
  313. C
  314. 700 NORM = 0.0E0
  315. C
  316. DO 720 I = 1, N
  317. 720 NORM = NORM + ABS(RV6(I))
  318. C
  319. IF (NORM .GE. 0.1E0) GO TO 840
  320. C .......... IN-LINE PROCEDURE FOR CHOOSING
  321. C A NEW STARTING VECTOR ..........
  322. IF (ITS .GE. N) GO TO 830
  323. ITS = ITS + 1
  324. XU = EPS4 / (UK + 1.0E0)
  325. RV6(1) = EPS4
  326. C
  327. DO 760 I = 2, N
  328. 760 RV6(I) = XU
  329. C
  330. RV6(ITS) = RV6(ITS) - EPS4 * UK
  331. GO TO 600
  332. C .......... SET ERROR -- NON-CONVERGED EIGENVECTOR ..........
  333. 830 IERR = -R
  334. XU = 0.0E0
  335. GO TO 870
  336. C .......... NORMALIZE SO THAT SUM OF SQUARES IS
  337. C 1 AND EXPAND TO FULL ORDER ..........
  338. 840 U = 0.0E0
  339. C
  340. DO 860 I = 1, N
  341. 860 U = U + RV6(I)**2
  342. C
  343. XU = 1.0E0 / SQRT(U)
  344. C
  345. 870 DO 900 I = 1, N
  346. 900 Z(I,R) = RV6(I) * XU
  347. C
  348. X0 = X1
  349. 920 CONTINUE
  350. C
  351. 1001 RETURN
  352. END