qzvec.f 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. *DECK QZVEC
  2. SUBROUTINE QZVEC (NM, N, A, B, ALFR, ALFI, BETA, Z)
  3. C***BEGIN PROLOGUE QZVEC
  4. C***PURPOSE The optional fourth step of the QZ algorithm for
  5. C generalized eigenproblems. Accepts a matrix in
  6. C quasi-triangular form and another in upper triangular
  7. C and computes the eigenvectors of the triangular problem
  8. C and transforms them back to the original coordinates
  9. C Usually preceded by QZHES, QZIT, and QZVAL.
  10. C***LIBRARY SLATEC (EISPACK)
  11. C***CATEGORY D4C3
  12. C***TYPE SINGLE PRECISION (QZVEC-S)
  13. C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
  14. C***AUTHOR Smith, B. T., et al.
  15. C***DESCRIPTION
  16. C
  17. C This subroutine is the optional fourth step of the QZ algorithm
  18. C for solving generalized matrix eigenvalue problems,
  19. C SIAM J. NUMER. ANAL. 10, 241-256(1973) by MOLER and STEWART.
  20. C
  21. C This subroutine accepts a pair of REAL matrices, one of them in
  22. C quasi-triangular form (in which each 2-by-2 block corresponds to
  23. C a pair of complex eigenvalues) and the other in upper triangular
  24. C form. It computes the eigenvectors of the triangular problem and
  25. C transforms the results back to the original coordinate system.
  26. C It is usually preceded by QZHES, QZIT, and QZVAL.
  27. C
  28. C On Input
  29. C
  30. C NM must be set to the row dimension of the two-dimensional
  31. C array parameters, A, B, and Z, as declared in the calling
  32. C program dimension statement. NM is an INTEGER variable.
  33. C
  34. C N is the order of the matrices A and B. N is an INTEGER
  35. C variable. N must be less than or equal to NM.
  36. C
  37. C A contains a real upper quasi-triangular matrix. A is a two-
  38. C dimensional REAL array, dimensioned A(NM,N).
  39. C
  40. C B contains a real upper triangular matrix. In addition,
  41. C location B(N,1) contains the tolerance quantity (EPSB)
  42. C computed and saved in QZIT. B is a two-dimensional REAL
  43. C array, dimensioned B(NM,N).
  44. C
  45. C ALFR, ALFI, and BETA are one-dimensional REAL arrays with
  46. C components whose ratios ((ALFR+I*ALFI)/BETA) are the
  47. C generalized eigenvalues. They are usually obtained from
  48. C QZVAL. They are dimensioned ALFR(N), ALFI(N), and BETA(N).
  49. C
  50. C Z contains the transformation matrix produced in the reductions
  51. C by QZHES, QZIT, and QZVAL, if performed. If the
  52. C eigenvectors of the triangular problem are desired, Z must
  53. C contain the identity matrix. Z is a two-dimensional REAL
  54. C array, dimensioned Z(NM,N).
  55. C
  56. C On Output
  57. C
  58. C A is unaltered. Its subdiagonal elements provide information
  59. C about the storage of the complex eigenvectors.
  60. C
  61. C B has been destroyed.
  62. C
  63. C ALFR, ALFI, and BETA are unaltered.
  64. C
  65. C Z contains the real and imaginary parts of the eigenvectors.
  66. C If ALFI(J) .EQ. 0.0, the J-th eigenvalue is real and
  67. C the J-th column of Z contains its eigenvector.
  68. C If ALFI(J) .NE. 0.0, the J-th eigenvalue is complex.
  69. C If ALFI(J) .GT. 0.0, the eigenvalue is the first of
  70. C a complex pair and the J-th and (J+1)-th columns
  71. C of Z contain its eigenvector.
  72. C If ALFI(J) .LT. 0.0, the eigenvalue is the second of
  73. C a complex pair and the (J-1)-th and J-th columns
  74. C of Z contain the conjugate of its eigenvector.
  75. C Each eigenvector is normalized so that the modulus
  76. C of its largest component is 1.0 .
  77. C
  78. C Questions and comments should be directed to B. S. Garbow,
  79. C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
  80. C ------------------------------------------------------------------
  81. C
  82. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  83. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  84. C system Routines - EISPACK Guide, Springer-Verlag,
  85. C 1976.
  86. C***ROUTINES CALLED (NONE)
  87. C***REVISION HISTORY (YYMMDD)
  88. C 760101 DATE WRITTEN
  89. C 890831 Modified array declarations. (WRB)
  90. C 890831 REVISION DATE from Version 3.2
  91. C 891214 Prologue converted to Version 4.0 format. (BAB)
  92. C 920501 Reformatted the REFERENCES section. (WRB)
  93. C***END PROLOGUE QZVEC
  94. C
  95. INTEGER I,J,K,M,N,EN,II,JJ,NA,NM,NN,ISW,ENM2
  96. REAL A(NM,*),B(NM,*),ALFR(*),ALFI(*),BETA(*),Z(NM,*)
  97. REAL D,Q,R,S,T,W,X,Y,DI,DR,RA,RR,SA,TI,TR,T1,T2
  98. REAL W1,X1,ZZ,Z1,ALFM,ALMI,ALMR,BETM,EPSB
  99. C
  100. C***FIRST EXECUTABLE STATEMENT QZVEC
  101. EPSB = B(N,1)
  102. ISW = 1
  103. C .......... FOR EN=N STEP -1 UNTIL 1 DO -- ..........
  104. DO 800 NN = 1, N
  105. EN = N + 1 - NN
  106. NA = EN - 1
  107. IF (ISW .EQ. 2) GO TO 795
  108. IF (ALFI(EN) .NE. 0.0E0) GO TO 710
  109. C .......... REAL VECTOR ..........
  110. M = EN
  111. B(EN,EN) = 1.0E0
  112. IF (NA .EQ. 0) GO TO 800
  113. ALFM = ALFR(M)
  114. BETM = BETA(M)
  115. C .......... FOR I=EN-1 STEP -1 UNTIL 1 DO -- ..........
  116. DO 700 II = 1, NA
  117. I = EN - II
  118. W = BETM * A(I,I) - ALFM * B(I,I)
  119. R = 0.0E0
  120. C
  121. DO 610 J = M, EN
  122. 610 R = R + (BETM * A(I,J) - ALFM * B(I,J)) * B(J,EN)
  123. C
  124. IF (I .EQ. 1 .OR. ISW .EQ. 2) GO TO 630
  125. IF (BETM * A(I,I-1) .EQ. 0.0E0) GO TO 630
  126. ZZ = W
  127. S = R
  128. GO TO 690
  129. 630 M = I
  130. IF (ISW .EQ. 2) GO TO 640
  131. C .......... REAL 1-BY-1 BLOCK ..........
  132. T = W
  133. IF (W .EQ. 0.0E0) T = EPSB
  134. B(I,EN) = -R / T
  135. GO TO 700
  136. C .......... REAL 2-BY-2 BLOCK ..........
  137. 640 X = BETM * A(I,I+1) - ALFM * B(I,I+1)
  138. Y = BETM * A(I+1,I)
  139. Q = W * ZZ - X * Y
  140. T = (X * S - ZZ * R) / Q
  141. B(I,EN) = T
  142. IF (ABS(X) .LE. ABS(ZZ)) GO TO 650
  143. B(I+1,EN) = (-R - W * T) / X
  144. GO TO 690
  145. 650 B(I+1,EN) = (-S - Y * T) / ZZ
  146. 690 ISW = 3 - ISW
  147. 700 CONTINUE
  148. C .......... END REAL VECTOR ..........
  149. GO TO 800
  150. C .......... COMPLEX VECTOR ..........
  151. 710 M = NA
  152. ALMR = ALFR(M)
  153. ALMI = ALFI(M)
  154. BETM = BETA(M)
  155. C .......... LAST VECTOR COMPONENT CHOSEN IMAGINARY SO THAT
  156. C EIGENVECTOR MATRIX IS TRIANGULAR ..........
  157. Y = BETM * A(EN,NA)
  158. B(NA,NA) = -ALMI * B(EN,EN) / Y
  159. B(NA,EN) = (ALMR * B(EN,EN) - BETM * A(EN,EN)) / Y
  160. B(EN,NA) = 0.0E0
  161. B(EN,EN) = 1.0E0
  162. ENM2 = NA - 1
  163. IF (ENM2 .EQ. 0) GO TO 795
  164. C .......... FOR I=EN-2 STEP -1 UNTIL 1 DO -- ..........
  165. DO 790 II = 1, ENM2
  166. I = NA - II
  167. W = BETM * A(I,I) - ALMR * B(I,I)
  168. W1 = -ALMI * B(I,I)
  169. RA = 0.0E0
  170. SA = 0.0E0
  171. C
  172. DO 760 J = M, EN
  173. X = BETM * A(I,J) - ALMR * B(I,J)
  174. X1 = -ALMI * B(I,J)
  175. RA = RA + X * B(J,NA) - X1 * B(J,EN)
  176. SA = SA + X * B(J,EN) + X1 * B(J,NA)
  177. 760 CONTINUE
  178. C
  179. IF (I .EQ. 1 .OR. ISW .EQ. 2) GO TO 770
  180. IF (BETM * A(I,I-1) .EQ. 0.0E0) GO TO 770
  181. ZZ = W
  182. Z1 = W1
  183. R = RA
  184. S = SA
  185. ISW = 2
  186. GO TO 790
  187. 770 M = I
  188. IF (ISW .EQ. 2) GO TO 780
  189. C .......... COMPLEX 1-BY-1 BLOCK ..........
  190. TR = -RA
  191. TI = -SA
  192. 773 DR = W
  193. DI = W1
  194. C .......... COMPLEX DIVIDE (T1,T2) = (TR,TI) / (DR,DI) ..........
  195. 775 IF (ABS(DI) .GT. ABS(DR)) GO TO 777
  196. RR = DI / DR
  197. D = DR + DI * RR
  198. T1 = (TR + TI * RR) / D
  199. T2 = (TI - TR * RR) / D
  200. GO TO (787,782), ISW
  201. 777 RR = DR / DI
  202. D = DR * RR + DI
  203. T1 = (TR * RR + TI) / D
  204. T2 = (TI * RR - TR) / D
  205. GO TO (787,782), ISW
  206. C .......... COMPLEX 2-BY-2 BLOCK ..........
  207. 780 X = BETM * A(I,I+1) - ALMR * B(I,I+1)
  208. X1 = -ALMI * B(I,I+1)
  209. Y = BETM * A(I+1,I)
  210. TR = Y * RA - W * R + W1 * S
  211. TI = Y * SA - W * S - W1 * R
  212. DR = W * ZZ - W1 * Z1 - X * Y
  213. DI = W * Z1 + W1 * ZZ - X1 * Y
  214. IF (DR .EQ. 0.0E0 .AND. DI .EQ. 0.0E0) DR = EPSB
  215. GO TO 775
  216. 782 B(I+1,NA) = T1
  217. B(I+1,EN) = T2
  218. ISW = 1
  219. IF (ABS(Y) .GT. ABS(W) + ABS(W1)) GO TO 785
  220. TR = -RA - X * B(I+1,NA) + X1 * B(I+1,EN)
  221. TI = -SA - X * B(I+1,EN) - X1 * B(I+1,NA)
  222. GO TO 773
  223. 785 T1 = (-R - ZZ * B(I+1,NA) + Z1 * B(I+1,EN)) / Y
  224. T2 = (-S - ZZ * B(I+1,EN) - Z1 * B(I+1,NA)) / Y
  225. 787 B(I,NA) = T1
  226. B(I,EN) = T2
  227. 790 CONTINUE
  228. C .......... END COMPLEX VECTOR ..........
  229. 795 ISW = 3 - ISW
  230. 800 CONTINUE
  231. C .......... END BACK SUBSTITUTION.
  232. C TRANSFORM TO ORIGINAL COORDINATE SYSTEM.
  233. C FOR J=N STEP -1 UNTIL 1 DO -- ..........
  234. DO 880 JJ = 1, N
  235. J = N + 1 - JJ
  236. C
  237. DO 880 I = 1, N
  238. ZZ = 0.0E0
  239. C
  240. DO 860 K = 1, J
  241. 860 ZZ = ZZ + Z(I,K) * B(K,J)
  242. C
  243. Z(I,J) = ZZ
  244. 880 CONTINUE
  245. C .......... NORMALIZE SO THAT MODULUS OF LARGEST
  246. C COMPONENT OF EACH VECTOR IS 1.
  247. C (ISW IS 1 INITIALLY FROM BEFORE) ..........
  248. DO 950 J = 1, N
  249. D = 0.0E0
  250. IF (ISW .EQ. 2) GO TO 920
  251. IF (ALFI(J) .NE. 0.0E0) GO TO 945
  252. C
  253. DO 890 I = 1, N
  254. IF (ABS(Z(I,J)) .GT. D) D = ABS(Z(I,J))
  255. 890 CONTINUE
  256. C
  257. DO 900 I = 1, N
  258. 900 Z(I,J) = Z(I,J) / D
  259. C
  260. GO TO 950
  261. C
  262. 920 DO 930 I = 1, N
  263. R = ABS(Z(I,J-1)) + ABS(Z(I,J))
  264. IF (R .NE. 0.0E0) R = R * SQRT((Z(I,J-1)/R)**2
  265. 1 +(Z(I,J)/R)**2)
  266. IF (R .GT. D) D = R
  267. 930 CONTINUE
  268. C
  269. DO 940 I = 1, N
  270. Z(I,J-1) = Z(I,J-1) / D
  271. Z(I,J) = Z(I,J) / D
  272. 940 CONTINUE
  273. C
  274. 945 ISW = 3 - ISW
  275. 950 CONTINUE
  276. C
  277. RETURN
  278. END