qzhes.f 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. *DECK QZHES
  2. SUBROUTINE QZHES (NM, N, A, B, MATZ, Z)
  3. C***BEGIN PROLOGUE QZHES
  4. C***PURPOSE The first step of the QZ algorithm for solving generalized
  5. C matrix eigenproblems. Accepts a pair of real general
  6. C matrices and reduces one of them to upper Hessenberg
  7. C and the other to upper triangular form using orthogonal
  8. C transformations. Usually followed by QZIT, QZVAL, QZVEC.
  9. C***LIBRARY SLATEC (EISPACK)
  10. C***CATEGORY D4C1B3
  11. C***TYPE SINGLE PRECISION (QZHES-S)
  12. C***KEYWORDS EIGENVALUES, EIGENVECTORS, EISPACK
  13. C***AUTHOR Smith, B. T., et al.
  14. C***DESCRIPTION
  15. C
  16. C This subroutine is the first step of the QZ algorithm
  17. C for solving generalized matrix eigenvalue problems,
  18. C SIAM J. NUMER. ANAL. 10, 241-256(1973) by MOLER and STEWART.
  19. C
  20. C This subroutine accepts a pair of REAL GENERAL matrices and
  21. C reduces one of them to upper Hessenberg form and the other
  22. C to upper triangular form using orthogonal transformations.
  23. C It is usually followed by QZIT, QZVAL and, possibly, QZVEC.
  24. C
  25. C On Input
  26. C
  27. C NM must be set to the row dimension of the two-dimensional
  28. C array parameters, A, B, and Z, as declared in the calling
  29. C program dimension statement. NM is an INTEGER variable.
  30. C
  31. C N is the order of the matrices A and B. N is an INTEGER
  32. C variable. N must be less than or equal to NM.
  33. C
  34. C A contains a real general matrix. A is a two-dimensional
  35. C REAL array, dimensioned A(NM,N).
  36. C
  37. C B contains a real general matrix. B is a two-dimensional
  38. C REAL array, dimensioned B(NM,N).
  39. C
  40. C MATZ should be set to .TRUE. if the right hand transformations
  41. C are to be accumulated for later use in computing
  42. C eigenvectors, and to .FALSE. otherwise. MATZ is a LOGICAL
  43. C variable.
  44. C
  45. C On Output
  46. C
  47. C A has been reduced to upper Hessenberg form. The elements
  48. C below the first subdiagonal have been set to zero.
  49. C
  50. C B has been reduced to upper triangular form. The elements
  51. C below the main diagonal have been set to zero.
  52. C
  53. C Z contains the product of the right hand transformations if
  54. C MATZ has been set to .TRUE. Otherwise, Z is not referenced.
  55. C Z is a two-dimensional REAL array, dimensioned Z(NM,N).
  56. C
  57. C Questions and comments should be directed to B. S. Garbow,
  58. C APPLIED MATHEMATICS DIVISION, ARGONNE NATIONAL LABORATORY
  59. C ------------------------------------------------------------------
  60. C
  61. C***REFERENCES B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow,
  62. C Y. Ikebe, V. C. Klema and C. B. Moler, Matrix Eigen-
  63. C system Routines - EISPACK Guide, Springer-Verlag,
  64. C 1976.
  65. C***ROUTINES CALLED (NONE)
  66. C***REVISION HISTORY (YYMMDD)
  67. C 760101 DATE WRITTEN
  68. C 890831 Modified array declarations. (WRB)
  69. C 890831 REVISION DATE from Version 3.2
  70. C 891214 Prologue converted to Version 4.0 format. (BAB)
  71. C 920501 Reformatted the REFERENCES section. (WRB)
  72. C***END PROLOGUE QZHES
  73. C
  74. INTEGER I,J,K,L,N,LB,L1,NM,NK1,NM1,NM2
  75. REAL A(NM,*),B(NM,*),Z(NM,*)
  76. REAL R,S,T,U1,U2,V1,V2,RHO
  77. LOGICAL MATZ
  78. C
  79. C .......... INITIALIZE Z ..........
  80. C***FIRST EXECUTABLE STATEMENT QZHES
  81. IF (.NOT. MATZ) GO TO 10
  82. C
  83. DO 3 I = 1, N
  84. C
  85. DO 2 J = 1, N
  86. Z(I,J) = 0.0E0
  87. 2 CONTINUE
  88. C
  89. Z(I,I) = 1.0E0
  90. 3 CONTINUE
  91. C .......... REDUCE B TO UPPER TRIANGULAR FORM ..........
  92. 10 IF (N .LE. 1) GO TO 170
  93. NM1 = N - 1
  94. C
  95. DO 100 L = 1, NM1
  96. L1 = L + 1
  97. S = 0.0E0
  98. C
  99. DO 20 I = L1, N
  100. S = S + ABS(B(I,L))
  101. 20 CONTINUE
  102. C
  103. IF (S .EQ. 0.0E0) GO TO 100
  104. S = S + ABS(B(L,L))
  105. R = 0.0E0
  106. C
  107. DO 25 I = L, N
  108. B(I,L) = B(I,L) / S
  109. R = R + B(I,L)**2
  110. 25 CONTINUE
  111. C
  112. R = SIGN(SQRT(R),B(L,L))
  113. B(L,L) = B(L,L) + R
  114. RHO = R * B(L,L)
  115. C
  116. DO 50 J = L1, N
  117. T = 0.0E0
  118. C
  119. DO 30 I = L, N
  120. T = T + B(I,L) * B(I,J)
  121. 30 CONTINUE
  122. C
  123. T = -T / RHO
  124. C
  125. DO 40 I = L, N
  126. B(I,J) = B(I,J) + T * B(I,L)
  127. 40 CONTINUE
  128. C
  129. 50 CONTINUE
  130. C
  131. DO 80 J = 1, N
  132. T = 0.0E0
  133. C
  134. DO 60 I = L, N
  135. T = T + B(I,L) * A(I,J)
  136. 60 CONTINUE
  137. C
  138. T = -T / RHO
  139. C
  140. DO 70 I = L, N
  141. A(I,J) = A(I,J) + T * B(I,L)
  142. 70 CONTINUE
  143. C
  144. 80 CONTINUE
  145. C
  146. B(L,L) = -S * R
  147. C
  148. DO 90 I = L1, N
  149. B(I,L) = 0.0E0
  150. 90 CONTINUE
  151. C
  152. 100 CONTINUE
  153. C .......... REDUCE A TO UPPER HESSENBERG FORM, WHILE
  154. C KEEPING B TRIANGULAR ..........
  155. IF (N .EQ. 2) GO TO 170
  156. NM2 = N - 2
  157. C
  158. DO 160 K = 1, NM2
  159. NK1 = NM1 - K
  160. C .......... FOR L=N-1 STEP -1 UNTIL K+1 DO -- ..........
  161. DO 150 LB = 1, NK1
  162. L = N - LB
  163. L1 = L + 1
  164. C .......... ZERO A(L+1,K) ..........
  165. S = ABS(A(L,K)) + ABS(A(L1,K))
  166. IF (S .EQ. 0.0E0) GO TO 150
  167. U1 = A(L,K) / S
  168. U2 = A(L1,K) / S
  169. R = SIGN(SQRT(U1*U1+U2*U2),U1)
  170. V1 = -(U1 + R) / R
  171. V2 = -U2 / R
  172. U2 = V2 / V1
  173. C
  174. DO 110 J = K, N
  175. T = A(L,J) + U2 * A(L1,J)
  176. A(L,J) = A(L,J) + T * V1
  177. A(L1,J) = A(L1,J) + T * V2
  178. 110 CONTINUE
  179. C
  180. A(L1,K) = 0.0E0
  181. C
  182. DO 120 J = L, N
  183. T = B(L,J) + U2 * B(L1,J)
  184. B(L,J) = B(L,J) + T * V1
  185. B(L1,J) = B(L1,J) + T * V2
  186. 120 CONTINUE
  187. C .......... ZERO B(L+1,L) ..........
  188. S = ABS(B(L1,L1)) + ABS(B(L1,L))
  189. IF (S .EQ. 0.0E0) GO TO 150
  190. U1 = B(L1,L1) / S
  191. U2 = B(L1,L) / S
  192. R = SIGN(SQRT(U1*U1+U2*U2),U1)
  193. V1 = -(U1 + R) / R
  194. V2 = -U2 / R
  195. U2 = V2 / V1
  196. C
  197. DO 130 I = 1, L1
  198. T = B(I,L1) + U2 * B(I,L)
  199. B(I,L1) = B(I,L1) + T * V1
  200. B(I,L) = B(I,L) + T * V2
  201. 130 CONTINUE
  202. C
  203. B(L1,L) = 0.0E0
  204. C
  205. DO 140 I = 1, N
  206. T = A(I,L1) + U2 * A(I,L)
  207. A(I,L1) = A(I,L1) + T * V1
  208. A(I,L) = A(I,L) + T * V2
  209. 140 CONTINUE
  210. C
  211. IF (.NOT. MATZ) GO TO 150
  212. C
  213. DO 145 I = 1, N
  214. T = Z(I,L1) + U2 * Z(I,L)
  215. Z(I,L1) = Z(I,L1) + T * V1
  216. Z(I,L) = Z(I,L) + T * V2
  217. 145 CONTINUE
  218. C
  219. 150 CONTINUE
  220. C
  221. 160 CONTINUE
  222. C
  223. 170 RETURN
  224. END