You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

chgeqz.f 29 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. *> \brief \b CHGEQZ
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHGEQZ + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chgeqz.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chgeqz.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chgeqz.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
  22. * ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK,
  23. * RWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER COMPQ, COMPZ, JOB
  27. * INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
  28. * ..
  29. * .. Array Arguments ..
  30. * REAL RWORK( * )
  31. * COMPLEX ALPHA( * ), BETA( * ), H( LDH, * ),
  32. * $ Q( LDQ, * ), T( LDT, * ), WORK( * ),
  33. * $ Z( LDZ, * )
  34. * ..
  35. *
  36. *
  37. *> \par Purpose:
  38. * =============
  39. *>
  40. *> \verbatim
  41. *>
  42. *> CHGEQZ computes the eigenvalues of a complex matrix pair (H,T),
  43. *> where H is an upper Hessenberg matrix and T is upper triangular,
  44. *> using the single-shift QZ method.
  45. *> Matrix pairs of this type are produced by the reduction to
  46. *> generalized upper Hessenberg form of a complex matrix pair (A,B):
  47. *>
  48. *> A = Q1*H*Z1**H, B = Q1*T*Z1**H,
  49. *>
  50. *> as computed by CGGHRD.
  51. *>
  52. *> If JOB='S', then the Hessenberg-triangular pair (H,T) is
  53. *> also reduced to generalized Schur form,
  54. *>
  55. *> H = Q*S*Z**H, T = Q*P*Z**H,
  56. *>
  57. *> where Q and Z are unitary matrices and S and P are upper triangular.
  58. *>
  59. *> Optionally, the unitary matrix Q from the generalized Schur
  60. *> factorization may be postmultiplied into an input matrix Q1, and the
  61. *> unitary matrix Z may be postmultiplied into an input matrix Z1.
  62. *> If Q1 and Z1 are the unitary matrices from CGGHRD that reduced
  63. *> the matrix pair (A,B) to generalized Hessenberg form, then the output
  64. *> matrices Q1*Q and Z1*Z are the unitary factors from the generalized
  65. *> Schur factorization of (A,B):
  66. *>
  67. *> A = (Q1*Q)*S*(Z1*Z)**H, B = (Q1*Q)*P*(Z1*Z)**H.
  68. *>
  69. *> To avoid overflow, eigenvalues of the matrix pair (H,T)
  70. *> (equivalently, of (A,B)) are computed as a pair of complex values
  71. *> (alpha,beta). If beta is nonzero, lambda = alpha / beta is an
  72. *> eigenvalue of the generalized nonsymmetric eigenvalue problem (GNEP)
  73. *> A*x = lambda*B*x
  74. *> and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the
  75. *> alternate form of the GNEP
  76. *> mu*A*y = B*y.
  77. *> The values of alpha and beta for the i-th eigenvalue can be read
  78. *> directly from the generalized Schur form: alpha = S(i,i),
  79. *> beta = P(i,i).
  80. *>
  81. *> Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix
  82. *> Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973),
  83. *> pp. 241--256.
  84. *> \endverbatim
  85. *
  86. * Arguments:
  87. * ==========
  88. *
  89. *> \param[in] JOB
  90. *> \verbatim
  91. *> JOB is CHARACTER*1
  92. *> = 'E': Compute eigenvalues only;
  93. *> = 'S': Computer eigenvalues and the Schur form.
  94. *> \endverbatim
  95. *>
  96. *> \param[in] COMPQ
  97. *> \verbatim
  98. *> COMPQ is CHARACTER*1
  99. *> = 'N': Left Schur vectors (Q) are not computed;
  100. *> = 'I': Q is initialized to the unit matrix and the matrix Q
  101. *> of left Schur vectors of (H,T) is returned;
  102. *> = 'V': Q must contain a unitary matrix Q1 on entry and
  103. *> the product Q1*Q is returned.
  104. *> \endverbatim
  105. *>
  106. *> \param[in] COMPZ
  107. *> \verbatim
  108. *> COMPZ is CHARACTER*1
  109. *> = 'N': Right Schur vectors (Z) are not computed;
  110. *> = 'I': Q is initialized to the unit matrix and the matrix Z
  111. *> of right Schur vectors of (H,T) is returned;
  112. *> = 'V': Z must contain a unitary matrix Z1 on entry and
  113. *> the product Z1*Z is returned.
  114. *> \endverbatim
  115. *>
  116. *> \param[in] N
  117. *> \verbatim
  118. *> N is INTEGER
  119. *> The order of the matrices H, T, Q, and Z. N >= 0.
  120. *> \endverbatim
  121. *>
  122. *> \param[in] ILO
  123. *> \verbatim
  124. *> ILO is INTEGER
  125. *> \endverbatim
  126. *>
  127. *> \param[in] IHI
  128. *> \verbatim
  129. *> IHI is INTEGER
  130. *> ILO and IHI mark the rows and columns of H which are in
  131. *> Hessenberg form. It is assumed that A is already upper
  132. *> triangular in rows and columns 1:ILO-1 and IHI+1:N.
  133. *> If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0.
  134. *> \endverbatim
  135. *>
  136. *> \param[in,out] H
  137. *> \verbatim
  138. *> H is COMPLEX array, dimension (LDH, N)
  139. *> On entry, the N-by-N upper Hessenberg matrix H.
  140. *> On exit, if JOB = 'S', H contains the upper triangular
  141. *> matrix S from the generalized Schur factorization.
  142. *> If JOB = 'E', the diagonal of H matches that of S, but
  143. *> the rest of H is unspecified.
  144. *> \endverbatim
  145. *>
  146. *> \param[in] LDH
  147. *> \verbatim
  148. *> LDH is INTEGER
  149. *> The leading dimension of the array H. LDH >= max( 1, N ).
  150. *> \endverbatim
  151. *>
  152. *> \param[in,out] T
  153. *> \verbatim
  154. *> T is COMPLEX array, dimension (LDT, N)
  155. *> On entry, the N-by-N upper triangular matrix T.
  156. *> On exit, if JOB = 'S', T contains the upper triangular
  157. *> matrix P from the generalized Schur factorization.
  158. *> If JOB = 'E', the diagonal of T matches that of P, but
  159. *> the rest of T is unspecified.
  160. *> \endverbatim
  161. *>
  162. *> \param[in] LDT
  163. *> \verbatim
  164. *> LDT is INTEGER
  165. *> The leading dimension of the array T. LDT >= max( 1, N ).
  166. *> \endverbatim
  167. *>
  168. *> \param[out] ALPHA
  169. *> \verbatim
  170. *> ALPHA is COMPLEX array, dimension (N)
  171. *> The complex scalars alpha that define the eigenvalues of
  172. *> GNEP. ALPHA(i) = S(i,i) in the generalized Schur
  173. *> factorization.
  174. *> \endverbatim
  175. *>
  176. *> \param[out] BETA
  177. *> \verbatim
  178. *> BETA is COMPLEX array, dimension (N)
  179. *> The real non-negative scalars beta that define the
  180. *> eigenvalues of GNEP. BETA(i) = P(i,i) in the generalized
  181. *> Schur factorization.
  182. *>
  183. *> Together, the quantities alpha = ALPHA(j) and beta = BETA(j)
  184. *> represent the j-th eigenvalue of the matrix pair (A,B), in
  185. *> one of the forms lambda = alpha/beta or mu = beta/alpha.
  186. *> Since either lambda or mu may overflow, they should not,
  187. *> in general, be computed.
  188. *> \endverbatim
  189. *>
  190. *> \param[in,out] Q
  191. *> \verbatim
  192. *> Q is COMPLEX array, dimension (LDQ, N)
  193. *> On entry, if COMPQ = 'V', the unitary matrix Q1 used in the
  194. *> reduction of (A,B) to generalized Hessenberg form.
  195. *> On exit, if COMPQ = 'I', the unitary matrix of left Schur
  196. *> vectors of (H,T), and if COMPQ = 'V', the unitary matrix of
  197. *> left Schur vectors of (A,B).
  198. *> Not referenced if COMPQ = 'N'.
  199. *> \endverbatim
  200. *>
  201. *> \param[in] LDQ
  202. *> \verbatim
  203. *> LDQ is INTEGER
  204. *> The leading dimension of the array Q. LDQ >= 1.
  205. *> If COMPQ='V' or 'I', then LDQ >= N.
  206. *> \endverbatim
  207. *>
  208. *> \param[in,out] Z
  209. *> \verbatim
  210. *> Z is COMPLEX array, dimension (LDZ, N)
  211. *> On entry, if COMPZ = 'V', the unitary matrix Z1 used in the
  212. *> reduction of (A,B) to generalized Hessenberg form.
  213. *> On exit, if COMPZ = 'I', the unitary matrix of right Schur
  214. *> vectors of (H,T), and if COMPZ = 'V', the unitary matrix of
  215. *> right Schur vectors of (A,B).
  216. *> Not referenced if COMPZ = 'N'.
  217. *> \endverbatim
  218. *>
  219. *> \param[in] LDZ
  220. *> \verbatim
  221. *> LDZ is INTEGER
  222. *> The leading dimension of the array Z. LDZ >= 1.
  223. *> If COMPZ='V' or 'I', then LDZ >= N.
  224. *> \endverbatim
  225. *>
  226. *> \param[out] WORK
  227. *> \verbatim
  228. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  229. *> On exit, if INFO >= 0, WORK(1) returns the optimal LWORK.
  230. *> \endverbatim
  231. *>
  232. *> \param[in] LWORK
  233. *> \verbatim
  234. *> LWORK is INTEGER
  235. *> The dimension of the array WORK. LWORK >= max(1,N).
  236. *>
  237. *> If LWORK = -1, then a workspace query is assumed; the routine
  238. *> only calculates the optimal size of the WORK array, returns
  239. *> this value as the first entry of the WORK array, and no error
  240. *> message related to LWORK is issued by XERBLA.
  241. *> \endverbatim
  242. *>
  243. *> \param[out] RWORK
  244. *> \verbatim
  245. *> RWORK is REAL array, dimension (N)
  246. *> \endverbatim
  247. *>
  248. *> \param[out] INFO
  249. *> \verbatim
  250. *> INFO is INTEGER
  251. *> = 0: successful exit
  252. *> < 0: if INFO = -i, the i-th argument had an illegal value
  253. *> = 1,...,N: the QZ iteration did not converge. (H,T) is not
  254. *> in Schur form, but ALPHA(i) and BETA(i),
  255. *> i=INFO+1,...,N should be correct.
  256. *> = N+1,...,2*N: the shift calculation failed. (H,T) is not
  257. *> in Schur form, but ALPHA(i) and BETA(i),
  258. *> i=INFO-N+1,...,N should be correct.
  259. *> \endverbatim
  260. *
  261. * Authors:
  262. * ========
  263. *
  264. *> \author Univ. of Tennessee
  265. *> \author Univ. of California Berkeley
  266. *> \author Univ. of Colorado Denver
  267. *> \author NAG Ltd.
  268. *
  269. *> \ingroup complexGEcomputational
  270. *
  271. *> \par Further Details:
  272. * =====================
  273. *>
  274. *> \verbatim
  275. *>
  276. *> We assume that complex ABS works as long as its value is less than
  277. *> overflow.
  278. *> \endverbatim
  279. *>
  280. * =====================================================================
  281. SUBROUTINE CHGEQZ( JOB, COMPQ, COMPZ, N, ILO, IHI, H, LDH, T, LDT,
  282. $ ALPHA, BETA, Q, LDQ, Z, LDZ, WORK, LWORK,
  283. $ RWORK, INFO )
  284. *
  285. * -- LAPACK computational routine --
  286. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  287. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  288. *
  289. * .. Scalar Arguments ..
  290. CHARACTER COMPQ, COMPZ, JOB
  291. INTEGER IHI, ILO, INFO, LDH, LDQ, LDT, LDZ, LWORK, N
  292. * ..
  293. * .. Array Arguments ..
  294. REAL RWORK( * )
  295. COMPLEX ALPHA( * ), BETA( * ), H( LDH, * ),
  296. $ Q( LDQ, * ), T( LDT, * ), WORK( * ),
  297. $ Z( LDZ, * )
  298. * ..
  299. *
  300. * =====================================================================
  301. *
  302. * .. Parameters ..
  303. COMPLEX CZERO, CONE
  304. PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ),
  305. $ CONE = ( 1.0E+0, 0.0E+0 ) )
  306. REAL ZERO, ONE
  307. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  308. REAL HALF
  309. PARAMETER ( HALF = 0.5E+0 )
  310. * ..
  311. * .. Local Scalars ..
  312. LOGICAL ILAZR2, ILAZRO, ILQ, ILSCHR, ILZ, LQUERY
  313. INTEGER ICOMPQ, ICOMPZ, IFIRST, IFRSTM, IITER, ILAST,
  314. $ ILASTM, IN, ISCHUR, ISTART, J, JC, JCH, JITER,
  315. $ JR, MAXIT
  316. REAL ABSB, ANORM, ASCALE, ATOL, BNORM, BSCALE, BTOL,
  317. $ C, SAFMIN, TEMP, TEMP2, TEMPR, ULP
  318. COMPLEX ABI22, AD11, AD12, AD21, AD22, CTEMP, CTEMP2,
  319. $ CTEMP3, ESHIFT, S, SHIFT, SIGNBC,
  320. $ U12, X, ABI12, Y
  321. * ..
  322. * .. External Functions ..
  323. COMPLEX CLADIV
  324. LOGICAL LSAME
  325. REAL CLANHS, SLAMCH
  326. EXTERNAL CLADIV, LSAME, CLANHS, SLAMCH
  327. * ..
  328. * .. External Subroutines ..
  329. EXTERNAL CLARTG, CLASET, CROT, CSCAL, XERBLA
  330. * ..
  331. * .. Intrinsic Functions ..
  332. INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, MIN, REAL, SQRT
  333. * ..
  334. * .. Statement Functions ..
  335. REAL ABS1
  336. * ..
  337. * .. Statement Function definitions ..
  338. ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
  339. * ..
  340. * .. Executable Statements ..
  341. *
  342. * Decode JOB, COMPQ, COMPZ
  343. *
  344. IF( LSAME( JOB, 'E' ) ) THEN
  345. ILSCHR = .FALSE.
  346. ISCHUR = 1
  347. ELSE IF( LSAME( JOB, 'S' ) ) THEN
  348. ILSCHR = .TRUE.
  349. ISCHUR = 2
  350. ELSE
  351. ILSCHR = .TRUE.
  352. ISCHUR = 0
  353. END IF
  354. *
  355. IF( LSAME( COMPQ, 'N' ) ) THEN
  356. ILQ = .FALSE.
  357. ICOMPQ = 1
  358. ELSE IF( LSAME( COMPQ, 'V' ) ) THEN
  359. ILQ = .TRUE.
  360. ICOMPQ = 2
  361. ELSE IF( LSAME( COMPQ, 'I' ) ) THEN
  362. ILQ = .TRUE.
  363. ICOMPQ = 3
  364. ELSE
  365. ILQ = .TRUE.
  366. ICOMPQ = 0
  367. END IF
  368. *
  369. IF( LSAME( COMPZ, 'N' ) ) THEN
  370. ILZ = .FALSE.
  371. ICOMPZ = 1
  372. ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
  373. ILZ = .TRUE.
  374. ICOMPZ = 2
  375. ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
  376. ILZ = .TRUE.
  377. ICOMPZ = 3
  378. ELSE
  379. ILZ = .TRUE.
  380. ICOMPZ = 0
  381. END IF
  382. *
  383. * Check Argument Values
  384. *
  385. INFO = 0
  386. WORK( 1 ) = MAX( 1, N )
  387. LQUERY = ( LWORK.EQ.-1 )
  388. IF( ISCHUR.EQ.0 ) THEN
  389. INFO = -1
  390. ELSE IF( ICOMPQ.EQ.0 ) THEN
  391. INFO = -2
  392. ELSE IF( ICOMPZ.EQ.0 ) THEN
  393. INFO = -3
  394. ELSE IF( N.LT.0 ) THEN
  395. INFO = -4
  396. ELSE IF( ILO.LT.1 ) THEN
  397. INFO = -5
  398. ELSE IF( IHI.GT.N .OR. IHI.LT.ILO-1 ) THEN
  399. INFO = -6
  400. ELSE IF( LDH.LT.N ) THEN
  401. INFO = -8
  402. ELSE IF( LDT.LT.N ) THEN
  403. INFO = -10
  404. ELSE IF( LDQ.LT.1 .OR. ( ILQ .AND. LDQ.LT.N ) ) THEN
  405. INFO = -14
  406. ELSE IF( LDZ.LT.1 .OR. ( ILZ .AND. LDZ.LT.N ) ) THEN
  407. INFO = -16
  408. ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
  409. INFO = -18
  410. END IF
  411. IF( INFO.NE.0 ) THEN
  412. CALL XERBLA( 'CHGEQZ', -INFO )
  413. RETURN
  414. ELSE IF( LQUERY ) THEN
  415. RETURN
  416. END IF
  417. *
  418. * Quick return if possible
  419. *
  420. * WORK( 1 ) = CMPLX( 1 )
  421. IF( N.LE.0 ) THEN
  422. WORK( 1 ) = CMPLX( 1 )
  423. RETURN
  424. END IF
  425. *
  426. * Initialize Q and Z
  427. *
  428. IF( ICOMPQ.EQ.3 )
  429. $ CALL CLASET( 'Full', N, N, CZERO, CONE, Q, LDQ )
  430. IF( ICOMPZ.EQ.3 )
  431. $ CALL CLASET( 'Full', N, N, CZERO, CONE, Z, LDZ )
  432. *
  433. * Machine Constants
  434. *
  435. IN = IHI + 1 - ILO
  436. SAFMIN = SLAMCH( 'S' )
  437. ULP = SLAMCH( 'E' )*SLAMCH( 'B' )
  438. ANORM = CLANHS( 'F', IN, H( ILO, ILO ), LDH, RWORK )
  439. BNORM = CLANHS( 'F', IN, T( ILO, ILO ), LDT, RWORK )
  440. ATOL = MAX( SAFMIN, ULP*ANORM )
  441. BTOL = MAX( SAFMIN, ULP*BNORM )
  442. ASCALE = ONE / MAX( SAFMIN, ANORM )
  443. BSCALE = ONE / MAX( SAFMIN, BNORM )
  444. *
  445. *
  446. * Set Eigenvalues IHI+1:N
  447. *
  448. DO 10 J = IHI + 1, N
  449. ABSB = ABS( T( J, J ) )
  450. IF( ABSB.GT.SAFMIN ) THEN
  451. SIGNBC = CONJG( T( J, J ) / ABSB )
  452. T( J, J ) = ABSB
  453. IF( ILSCHR ) THEN
  454. CALL CSCAL( J-1, SIGNBC, T( 1, J ), 1 )
  455. CALL CSCAL( J, SIGNBC, H( 1, J ), 1 )
  456. ELSE
  457. CALL CSCAL( 1, SIGNBC, H( J, J ), 1 )
  458. END IF
  459. IF( ILZ )
  460. $ CALL CSCAL( N, SIGNBC, Z( 1, J ), 1 )
  461. ELSE
  462. T( J, J ) = CZERO
  463. END IF
  464. ALPHA( J ) = H( J, J )
  465. BETA( J ) = T( J, J )
  466. 10 CONTINUE
  467. *
  468. * If IHI < ILO, skip QZ steps
  469. *
  470. IF( IHI.LT.ILO )
  471. $ GO TO 190
  472. *
  473. * MAIN QZ ITERATION LOOP
  474. *
  475. * Initialize dynamic indices
  476. *
  477. * Eigenvalues ILAST+1:N have been found.
  478. * Column operations modify rows IFRSTM:whatever
  479. * Row operations modify columns whatever:ILASTM
  480. *
  481. * If only eigenvalues are being computed, then
  482. * IFRSTM is the row of the last splitting row above row ILAST;
  483. * this is always at least ILO.
  484. * IITER counts iterations since the last eigenvalue was found,
  485. * to tell when to use an extraordinary shift.
  486. * MAXIT is the maximum number of QZ sweeps allowed.
  487. *
  488. ILAST = IHI
  489. IF( ILSCHR ) THEN
  490. IFRSTM = 1
  491. ILASTM = N
  492. ELSE
  493. IFRSTM = ILO
  494. ILASTM = IHI
  495. END IF
  496. IITER = 0
  497. ESHIFT = CZERO
  498. MAXIT = 30*( IHI-ILO+1 )
  499. *
  500. DO 170 JITER = 1, MAXIT
  501. *
  502. * Check for too many iterations.
  503. *
  504. IF( JITER.GT.MAXIT )
  505. $ GO TO 180
  506. *
  507. * Split the matrix if possible.
  508. *
  509. * Two tests:
  510. * 1: H(j,j-1)=0 or j=ILO
  511. * 2: T(j,j)=0
  512. *
  513. * Special case: j=ILAST
  514. *
  515. IF( ILAST.EQ.ILO ) THEN
  516. GO TO 60
  517. ELSE
  518. IF( ABS1( H( ILAST, ILAST-1 ) ).LE.MAX( SAFMIN, ULP*(
  519. $ ABS1( H( ILAST, ILAST ) ) + ABS1( H( ILAST-1, ILAST-1 )
  520. $ ) ) ) ) THEN
  521. H( ILAST, ILAST-1 ) = CZERO
  522. GO TO 60
  523. END IF
  524. END IF
  525. *
  526. IF( ABS( T( ILAST, ILAST ) ).LE.BTOL ) THEN
  527. T( ILAST, ILAST ) = CZERO
  528. GO TO 50
  529. END IF
  530. *
  531. * General case: j<ILAST
  532. *
  533. DO 40 J = ILAST - 1, ILO, -1
  534. *
  535. * Test 1: for H(j,j-1)=0 or j=ILO
  536. *
  537. IF( J.EQ.ILO ) THEN
  538. ILAZRO = .TRUE.
  539. ELSE
  540. IF( ABS1( H( J, J-1 ) ).LE.MAX( SAFMIN, ULP*(
  541. $ ABS1( H( J, J ) ) + ABS1( H( J-1, J-1 ) )
  542. $ ) ) ) THEN
  543. H( J, J-1 ) = CZERO
  544. ILAZRO = .TRUE.
  545. ELSE
  546. ILAZRO = .FALSE.
  547. END IF
  548. END IF
  549. *
  550. * Test 2: for T(j,j)=0
  551. *
  552. IF( ABS( T( J, J ) ).LT.BTOL ) THEN
  553. T( J, J ) = CZERO
  554. *
  555. * Test 1a: Check for 2 consecutive small subdiagonals in A
  556. *
  557. ILAZR2 = .FALSE.
  558. IF( .NOT.ILAZRO ) THEN
  559. IF( ABS1( H( J, J-1 ) )*( ASCALE*ABS1( H( J+1,
  560. $ J ) ) ).LE.ABS1( H( J, J ) )*( ASCALE*ATOL ) )
  561. $ ILAZR2 = .TRUE.
  562. END IF
  563. *
  564. * If both tests pass (1 & 2), i.e., the leading diagonal
  565. * element of B in the block is zero, split a 1x1 block off
  566. * at the top. (I.e., at the J-th row/column) The leading
  567. * diagonal element of the remainder can also be zero, so
  568. * this may have to be done repeatedly.
  569. *
  570. IF( ILAZRO .OR. ILAZR2 ) THEN
  571. DO 20 JCH = J, ILAST - 1
  572. CTEMP = H( JCH, JCH )
  573. CALL CLARTG( CTEMP, H( JCH+1, JCH ), C, S,
  574. $ H( JCH, JCH ) )
  575. H( JCH+1, JCH ) = CZERO
  576. CALL CROT( ILASTM-JCH, H( JCH, JCH+1 ), LDH,
  577. $ H( JCH+1, JCH+1 ), LDH, C, S )
  578. CALL CROT( ILASTM-JCH, T( JCH, JCH+1 ), LDT,
  579. $ T( JCH+1, JCH+1 ), LDT, C, S )
  580. IF( ILQ )
  581. $ CALL CROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  582. $ C, CONJG( S ) )
  583. IF( ILAZR2 )
  584. $ H( JCH, JCH-1 ) = H( JCH, JCH-1 )*C
  585. ILAZR2 = .FALSE.
  586. IF( ABS1( T( JCH+1, JCH+1 ) ).GE.BTOL ) THEN
  587. IF( JCH+1.GE.ILAST ) THEN
  588. GO TO 60
  589. ELSE
  590. IFIRST = JCH + 1
  591. GO TO 70
  592. END IF
  593. END IF
  594. T( JCH+1, JCH+1 ) = CZERO
  595. 20 CONTINUE
  596. GO TO 50
  597. ELSE
  598. *
  599. * Only test 2 passed -- chase the zero to T(ILAST,ILAST)
  600. * Then process as in the case T(ILAST,ILAST)=0
  601. *
  602. DO 30 JCH = J, ILAST - 1
  603. CTEMP = T( JCH, JCH+1 )
  604. CALL CLARTG( CTEMP, T( JCH+1, JCH+1 ), C, S,
  605. $ T( JCH, JCH+1 ) )
  606. T( JCH+1, JCH+1 ) = CZERO
  607. IF( JCH.LT.ILASTM-1 )
  608. $ CALL CROT( ILASTM-JCH-1, T( JCH, JCH+2 ), LDT,
  609. $ T( JCH+1, JCH+2 ), LDT, C, S )
  610. CALL CROT( ILASTM-JCH+2, H( JCH, JCH-1 ), LDH,
  611. $ H( JCH+1, JCH-1 ), LDH, C, S )
  612. IF( ILQ )
  613. $ CALL CROT( N, Q( 1, JCH ), 1, Q( 1, JCH+1 ), 1,
  614. $ C, CONJG( S ) )
  615. CTEMP = H( JCH+1, JCH )
  616. CALL CLARTG( CTEMP, H( JCH+1, JCH-1 ), C, S,
  617. $ H( JCH+1, JCH ) )
  618. H( JCH+1, JCH-1 ) = CZERO
  619. CALL CROT( JCH+1-IFRSTM, H( IFRSTM, JCH ), 1,
  620. $ H( IFRSTM, JCH-1 ), 1, C, S )
  621. CALL CROT( JCH-IFRSTM, T( IFRSTM, JCH ), 1,
  622. $ T( IFRSTM, JCH-1 ), 1, C, S )
  623. IF( ILZ )
  624. $ CALL CROT( N, Z( 1, JCH ), 1, Z( 1, JCH-1 ), 1,
  625. $ C, S )
  626. 30 CONTINUE
  627. GO TO 50
  628. END IF
  629. ELSE IF( ILAZRO ) THEN
  630. *
  631. * Only test 1 passed -- work on J:ILAST
  632. *
  633. IFIRST = J
  634. GO TO 70
  635. END IF
  636. *
  637. * Neither test passed -- try next J
  638. *
  639. 40 CONTINUE
  640. *
  641. * (Drop-through is "impossible")
  642. *
  643. INFO = 2*N + 1
  644. GO TO 210
  645. *
  646. * T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a
  647. * 1x1 block.
  648. *
  649. 50 CONTINUE
  650. CTEMP = H( ILAST, ILAST )
  651. CALL CLARTG( CTEMP, H( ILAST, ILAST-1 ), C, S,
  652. $ H( ILAST, ILAST ) )
  653. H( ILAST, ILAST-1 ) = CZERO
  654. CALL CROT( ILAST-IFRSTM, H( IFRSTM, ILAST ), 1,
  655. $ H( IFRSTM, ILAST-1 ), 1, C, S )
  656. CALL CROT( ILAST-IFRSTM, T( IFRSTM, ILAST ), 1,
  657. $ T( IFRSTM, ILAST-1 ), 1, C, S )
  658. IF( ILZ )
  659. $ CALL CROT( N, Z( 1, ILAST ), 1, Z( 1, ILAST-1 ), 1, C, S )
  660. *
  661. * H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHA and BETA
  662. *
  663. 60 CONTINUE
  664. ABSB = ABS( T( ILAST, ILAST ) )
  665. IF( ABSB.GT.SAFMIN ) THEN
  666. SIGNBC = CONJG( T( ILAST, ILAST ) / ABSB )
  667. T( ILAST, ILAST ) = ABSB
  668. IF( ILSCHR ) THEN
  669. CALL CSCAL( ILAST-IFRSTM, SIGNBC, T( IFRSTM, ILAST ), 1 )
  670. CALL CSCAL( ILAST+1-IFRSTM, SIGNBC, H( IFRSTM, ILAST ),
  671. $ 1 )
  672. ELSE
  673. CALL CSCAL( 1, SIGNBC, H( ILAST, ILAST ), 1 )
  674. END IF
  675. IF( ILZ )
  676. $ CALL CSCAL( N, SIGNBC, Z( 1, ILAST ), 1 )
  677. ELSE
  678. T( ILAST, ILAST ) = CZERO
  679. END IF
  680. ALPHA( ILAST ) = H( ILAST, ILAST )
  681. BETA( ILAST ) = T( ILAST, ILAST )
  682. *
  683. * Go to next block -- exit if finished.
  684. *
  685. ILAST = ILAST - 1
  686. IF( ILAST.LT.ILO )
  687. $ GO TO 190
  688. *
  689. * Reset counters
  690. *
  691. IITER = 0
  692. ESHIFT = CZERO
  693. IF( .NOT.ILSCHR ) THEN
  694. ILASTM = ILAST
  695. IF( IFRSTM.GT.ILAST )
  696. $ IFRSTM = ILO
  697. END IF
  698. GO TO 160
  699. *
  700. * QZ step
  701. *
  702. * This iteration only involves rows/columns IFIRST:ILAST. We
  703. * assume IFIRST < ILAST, and that the diagonal of B is non-zero.
  704. *
  705. 70 CONTINUE
  706. IITER = IITER + 1
  707. IF( .NOT.ILSCHR ) THEN
  708. IFRSTM = IFIRST
  709. END IF
  710. *
  711. * Compute the Shift.
  712. *
  713. * At this point, IFIRST < ILAST, and the diagonal elements of
  714. * T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in
  715. * magnitude)
  716. *
  717. IF( ( IITER / 10 )*10.NE.IITER ) THEN
  718. *
  719. * The Wilkinson shift (AEP p.512), i.e., the eigenvalue of
  720. * the bottom-right 2x2 block of A inv(B) which is nearest to
  721. * the bottom-right element.
  722. *
  723. * We factor B as U*D, where U has unit diagonals, and
  724. * compute (A*inv(D))*inv(U).
  725. *
  726. U12 = ( BSCALE*T( ILAST-1, ILAST ) ) /
  727. $ ( BSCALE*T( ILAST, ILAST ) )
  728. AD11 = ( ASCALE*H( ILAST-1, ILAST-1 ) ) /
  729. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  730. AD21 = ( ASCALE*H( ILAST, ILAST-1 ) ) /
  731. $ ( BSCALE*T( ILAST-1, ILAST-1 ) )
  732. AD12 = ( ASCALE*H( ILAST-1, ILAST ) ) /
  733. $ ( BSCALE*T( ILAST, ILAST ) )
  734. AD22 = ( ASCALE*H( ILAST, ILAST ) ) /
  735. $ ( BSCALE*T( ILAST, ILAST ) )
  736. ABI22 = AD22 - U12*AD21
  737. ABI12 = AD12 - U12*AD11
  738. *
  739. SHIFT = ABI22
  740. CTEMP = SQRT( ABI12 )*SQRT( AD21 )
  741. TEMP = ABS1( CTEMP )
  742. IF( CTEMP.NE.ZERO ) THEN
  743. X = HALF*( AD11-SHIFT )
  744. TEMP2 = ABS1( X )
  745. TEMP = MAX( TEMP, ABS1( X ) )
  746. Y = TEMP*SQRT( ( X / TEMP )**2+( CTEMP / TEMP )**2 )
  747. IF( TEMP2.GT.ZERO ) THEN
  748. IF( REAL( X / TEMP2 )*REAL( Y )+
  749. $ AIMAG( X / TEMP2 )*AIMAG( Y ).LT.ZERO )Y = -Y
  750. END IF
  751. SHIFT = SHIFT - CTEMP*CLADIV( CTEMP, ( X+Y ) )
  752. END IF
  753. ELSE
  754. *
  755. * Exceptional shift. Chosen for no particularly good reason.
  756. *
  757. IF( ( IITER / 20 )*20.EQ.IITER .AND.
  758. $ BSCALE*ABS1(T( ILAST, ILAST )).GT.SAFMIN ) THEN
  759. ESHIFT = ESHIFT + ( ASCALE*H( ILAST,
  760. $ ILAST ) )/( BSCALE*T( ILAST, ILAST ) )
  761. ELSE
  762. ESHIFT = ESHIFT + ( ASCALE*H( ILAST,
  763. $ ILAST-1 ) )/( BSCALE*T( ILAST-1, ILAST-1 ) )
  764. END IF
  765. SHIFT = ESHIFT
  766. END IF
  767. *
  768. * Now check for two consecutive small subdiagonals.
  769. *
  770. DO 80 J = ILAST - 1, IFIRST + 1, -1
  771. ISTART = J
  772. CTEMP = ASCALE*H( J, J ) - SHIFT*( BSCALE*T( J, J ) )
  773. TEMP = ABS1( CTEMP )
  774. TEMP2 = ASCALE*ABS1( H( J+1, J ) )
  775. TEMPR = MAX( TEMP, TEMP2 )
  776. IF( TEMPR.LT.ONE .AND. TEMPR.NE.ZERO ) THEN
  777. TEMP = TEMP / TEMPR
  778. TEMP2 = TEMP2 / TEMPR
  779. END IF
  780. IF( ABS1( H( J, J-1 ) )*TEMP2.LE.TEMP*ATOL )
  781. $ GO TO 90
  782. 80 CONTINUE
  783. *
  784. ISTART = IFIRST
  785. CTEMP = ASCALE*H( IFIRST, IFIRST ) -
  786. $ SHIFT*( BSCALE*T( IFIRST, IFIRST ) )
  787. 90 CONTINUE
  788. *
  789. * Do an implicit-shift QZ sweep.
  790. *
  791. * Initial Q
  792. *
  793. CTEMP2 = ASCALE*H( ISTART+1, ISTART )
  794. CALL CLARTG( CTEMP, CTEMP2, C, S, CTEMP3 )
  795. *
  796. * Sweep
  797. *
  798. DO 150 J = ISTART, ILAST - 1
  799. IF( J.GT.ISTART ) THEN
  800. CTEMP = H( J, J-1 )
  801. CALL CLARTG( CTEMP, H( J+1, J-1 ), C, S, H( J, J-1 ) )
  802. H( J+1, J-1 ) = CZERO
  803. END IF
  804. *
  805. DO 100 JC = J, ILASTM
  806. CTEMP = C*H( J, JC ) + S*H( J+1, JC )
  807. H( J+1, JC ) = -CONJG( S )*H( J, JC ) + C*H( J+1, JC )
  808. H( J, JC ) = CTEMP
  809. CTEMP2 = C*T( J, JC ) + S*T( J+1, JC )
  810. T( J+1, JC ) = -CONJG( S )*T( J, JC ) + C*T( J+1, JC )
  811. T( J, JC ) = CTEMP2
  812. 100 CONTINUE
  813. IF( ILQ ) THEN
  814. DO 110 JR = 1, N
  815. CTEMP = C*Q( JR, J ) + CONJG( S )*Q( JR, J+1 )
  816. Q( JR, J+1 ) = -S*Q( JR, J ) + C*Q( JR, J+1 )
  817. Q( JR, J ) = CTEMP
  818. 110 CONTINUE
  819. END IF
  820. *
  821. CTEMP = T( J+1, J+1 )
  822. CALL CLARTG( CTEMP, T( J+1, J ), C, S, T( J+1, J+1 ) )
  823. T( J+1, J ) = CZERO
  824. *
  825. DO 120 JR = IFRSTM, MIN( J+2, ILAST )
  826. CTEMP = C*H( JR, J+1 ) + S*H( JR, J )
  827. H( JR, J ) = -CONJG( S )*H( JR, J+1 ) + C*H( JR, J )
  828. H( JR, J+1 ) = CTEMP
  829. 120 CONTINUE
  830. DO 130 JR = IFRSTM, J
  831. CTEMP = C*T( JR, J+1 ) + S*T( JR, J )
  832. T( JR, J ) = -CONJG( S )*T( JR, J+1 ) + C*T( JR, J )
  833. T( JR, J+1 ) = CTEMP
  834. 130 CONTINUE
  835. IF( ILZ ) THEN
  836. DO 140 JR = 1, N
  837. CTEMP = C*Z( JR, J+1 ) + S*Z( JR, J )
  838. Z( JR, J ) = -CONJG( S )*Z( JR, J+1 ) + C*Z( JR, J )
  839. Z( JR, J+1 ) = CTEMP
  840. 140 CONTINUE
  841. END IF
  842. 150 CONTINUE
  843. *
  844. 160 CONTINUE
  845. *
  846. 170 CONTINUE
  847. *
  848. * Drop-through = non-convergence
  849. *
  850. 180 CONTINUE
  851. INFO = ILAST
  852. GO TO 210
  853. *
  854. * Successful completion of all QZ steps
  855. *
  856. 190 CONTINUE
  857. *
  858. * Set Eigenvalues 1:ILO-1
  859. *
  860. DO 200 J = 1, ILO - 1
  861. ABSB = ABS( T( J, J ) )
  862. IF( ABSB.GT.SAFMIN ) THEN
  863. SIGNBC = CONJG( T( J, J ) / ABSB )
  864. T( J, J ) = ABSB
  865. IF( ILSCHR ) THEN
  866. CALL CSCAL( J-1, SIGNBC, T( 1, J ), 1 )
  867. CALL CSCAL( J, SIGNBC, H( 1, J ), 1 )
  868. ELSE
  869. CALL CSCAL( 1, SIGNBC, H( J, J ), 1 )
  870. END IF
  871. IF( ILZ )
  872. $ CALL CSCAL( N, SIGNBC, Z( 1, J ), 1 )
  873. ELSE
  874. T( J, J ) = CZERO
  875. END IF
  876. ALPHA( J ) = H( J, J )
  877. BETA( J ) = T( J, J )
  878. 200 CONTINUE
  879. *
  880. * Normal Termination
  881. *
  882. INFO = 0
  883. *
  884. * Exit (other than argument error) -- return optimal workspace size
  885. *
  886. 210 CONTINUE
  887. WORK( 1 ) = CMPLX( N )
  888. RETURN
  889. *
  890. * End of CHGEQZ
  891. *
  892. END