1 *> \brief \b CLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix, using the double-shift/single-shift QR algorithm.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CLAHQR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahqr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahqr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahqr.f">
21 * SUBROUTINE CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
22 * IHIZ, Z, LDZ, INFO )
24 * .. Scalar Arguments ..
25 * INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
26 * LOGICAL WANTT, WANTZ
28 * .. Array Arguments ..
29 * COMPLEX H( LDH, * ), W( * ), Z( LDZ, * )
38 *> CLAHQR is an auxiliary routine called by CHSEQR to update the
39 *> eigenvalues and Schur decomposition already computed by CHSEQR, by
40 *> dealing with the Hessenberg submatrix in rows and columns ILO to
50 *> = .TRUE. : the full Schur form T is required;
51 *> = .FALSE.: only eigenvalues are required.
57 *> = .TRUE. : the matrix of Schur vectors Z is required;
58 *> = .FALSE.: Schur vectors are not required.
64 *> The order of the matrix H. N >= 0.
75 *> It is assumed that H is already upper triangular in rows and
76 *> columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1).
77 *> CLAHQR works primarily with the Hessenberg submatrix in rows
78 *> and columns ILO to IHI, but applies transformations to all of
79 *> H if WANTT is .TRUE..
80 *> 1 <= ILO <= max(1,IHI); IHI <= N.
85 *> H is COMPLEX array, dimension (LDH,N)
86 *> On entry, the upper Hessenberg matrix H.
87 *> On exit, if INFO is zero and if WANTT is .TRUE., then H
88 *> is upper triangular in rows and columns ILO:IHI. If INFO
89 *> is zero and if WANTT is .FALSE., then the contents of H
90 *> are unspecified on exit. The output state of H in case
91 *> INF is positive is below under the description of INFO.
97 *> The leading dimension of the array H. LDH >= max(1,N).
102 *> W is COMPLEX array, dimension (N)
103 *> The computed eigenvalues ILO to IHI are stored in the
104 *> corresponding elements of W. If WANTT is .TRUE., the
105 *> eigenvalues are stored in the same order as on the diagonal
106 *> of the Schur form returned in H, with W(i) = H(i,i).
117 *> Specify the rows of Z to which transformations must be
118 *> applied if WANTZ is .TRUE..
119 *> 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
124 *> Z is COMPLEX array, dimension (LDZ,N)
125 *> If WANTZ is .TRUE., on entry Z must contain the current
126 *> matrix Z of transformations accumulated by CHSEQR, and on
127 *> exit Z has been updated; transformations are applied only to
128 *> the submatrix Z(ILOZ:IHIZ,ILO:IHI).
129 *> If WANTZ is .FALSE., Z is not referenced.
135 *> The leading dimension of the array Z. LDZ >= max(1,N).
141 *> = 0: successful exit
142 *> .GT. 0: if INFO = i, CLAHQR failed to compute all the
143 *> eigenvalues ILO to IHI in a total of 30 iterations
144 *> per eigenvalue; elements i+1:ihi of W contain
145 *> those eigenvalues which have been successfully
148 *> If INFO .GT. 0 and WANTT is .FALSE., then on exit,
149 *> the remaining unconverged eigenvalues are the
150 *> eigenvalues of the upper Hessenberg matrix
151 *> rows and columns ILO thorugh INFO of the final,
152 *> output value of H.
154 *> If INFO .GT. 0 and WANTT is .TRUE., then on exit
155 *> (*) (initial value of H)*U = U*(final value of H)
156 *> where U is an orthognal matrix. The final
157 *> value of H is upper Hessenberg and triangular in
158 *> rows and columns INFO+1 through IHI.
160 *> If INFO .GT. 0 and WANTZ is .TRUE., then on exit
161 *> (final value of Z) = (initial value of Z)*U
162 *> where U is the orthogonal matrix in (*)
163 *> (regardless of the value of WANTT.)
169 *> \author Univ. of Tennessee
170 *> \author Univ. of California Berkeley
171 *> \author Univ. of Colorado Denver
174 *> \date November 2015
176 *> \ingroup complexOTHERauxiliary
178 *> \par Contributors:
183 *> 02-96 Based on modifications by
184 *> David Day, Sandia National Laboratory, USA
186 *> 12-04 Further modifications by
187 *> Ralph Byers, University of Kansas, USA
188 *> This is a modified version of CLAHQR from LAPACK version 3.0.
189 *> It is (1) more robust against overflow and underflow and
190 *> (2) adopts the more conservative Ahues & Tisseur stopping
191 *> criterion (LAWN 122, 1997).
194 * =====================================================================
195 SUBROUTINE CLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
196 $ IHIZ, Z, LDZ, INFO )
198 * -- LAPACK auxiliary routine (version 3.6.0) --
199 * -- LAPACK is a software package provided by Univ. of Tennessee, --
200 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
203 * .. Scalar Arguments ..
204 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
207 * .. Array Arguments ..
208 COMPLEX H( LDH, * ), W( * ), Z( LDZ, * )
211 * =========================================================
215 PARAMETER ( ZERO = ( 0.0e0, 0.0e0 ),
216 $ ONE = ( 1.0e0, 0.0e0 ) )
217 REAL RZERO, RONE, HALF
218 PARAMETER ( RZERO = 0.0e0, RONE = 1.0e0, HALF = 0.5e0 )
220 PARAMETER ( DAT1 = 3.0e0 / 4.0e0 )
222 * .. Local Scalars ..
223 COMPLEX CDUM, H11, H11S, H22, SC, SUM, T, T1, TEMP, U,
225 REAL AA, AB, BA, BB, H10, H21, RTEMP, S, SAFMAX,
226 $ SAFMIN, SMLNUM, SX, T2, TST, ULP
227 INTEGER I, I1, I2, ITS, ITMAX, J, JHI, JLO, K, L, M,
233 * .. External Functions ..
236 EXTERNAL CLADIV, SLAMCH
238 * .. External Subroutines ..
239 EXTERNAL CCOPY, CLARFG, CSCAL, SLABAD
241 * .. Statement Functions ..
244 * .. Intrinsic Functions ..
245 INTRINSIC ABS, AIMAG, CONJG, MAX, MIN, REAL, SQRT
247 * .. Statement Function definitions ..
248 CABS1( CDUM ) = ABS( REAL( CDUM ) ) + ABS( AIMAG( CDUM ) )
250 * .. Executable Statements ..
254 * Quick return if possible
258 IF( ILO.EQ.IHI ) THEN
259 W( ILO ) = H( ILO, ILO )
263 * ==== clear out the trash ====
264 DO 10 J = ILO, IHI - 3
269 $ H( IHI, IHI-2 ) = ZERO
270 * ==== ensure that subdiagonal entries are real ====
278 DO 20 I = ILO + 1, IHI
279 IF( AIMAG( H( I, I-1 ) ).NE.RZERO ) THEN
280 * ==== The following redundant normalization
281 * . avoids problems with both gradual and
282 * . sudden underflow in ABS(H(I,I-1)) ====
283 SC = H( I, I-1 ) / CABS1( H( I, I-1 ) )
284 SC = CONJG( SC ) / ABS( SC )
285 H( I, I-1 ) = ABS( H( I, I-1 ) )
286 CALL CSCAL( JHI-I+1, SC, H( I, I ), LDH )
287 CALL CSCAL( MIN( JHI, I+1 )-JLO+1, CONJG( SC ), H( JLO, I ),
290 $ CALL CSCAL( IHIZ-ILOZ+1, CONJG( SC ), Z( ILOZ, I ), 1 )
297 * Set machine-dependent constants for the stopping criterion.
299 SAFMIN = SLAMCH( 'SAFE MINIMUM' )
300 SAFMAX = RONE / SAFMIN
301 CALL SLABAD( SAFMIN, SAFMAX )
302 ULP = SLAMCH( 'PRECISION' )
303 SMLNUM = SAFMIN*( REAL( NH ) / ULP )
305 * I1 and I2 are the indices of the first row and last column of H
306 * to which transformations must be applied. If eigenvalues only are
307 * being computed, I1 and I2 are set inside the main loop.
314 * ITMAX is the total number of QR iterations allowed.
316 ITMAX = 30 * MAX( 10, NH )
318 * The main loop begins here. I is the loop index and decreases from
319 * IHI to ILO in steps of 1. Each iteration of the loop works
320 * with the active submatrix in rows and columns L to I.
321 * Eigenvalues I+1 to IHI have already converged. Either L = ILO, or
322 * H(L,L-1) is negligible so that the matrix splits.
329 * Perform QR iterations on rows and columns ILO to I until a
330 * submatrix of order 1 splits off at the bottom because a
331 * subdiagonal element has become negligible.
334 DO 130 ITS = 0, ITMAX
336 * Look for a single small subdiagonal element.
338 DO 40 K = I, L + 1, -1
339 IF( CABS1( H( K, K-1 ) ).LE.SMLNUM )
341 TST = CABS1( H( K-1, K-1 ) ) + CABS1( H( K, K ) )
342 IF( TST.EQ.ZERO ) THEN
344 $ TST = TST + ABS( REAL( H( K-1, K-2 ) ) )
346 $ TST = TST + ABS( REAL( H( K+1, K ) ) )
348 * ==== The following is a conservative small subdiagonal
349 * . deflation criterion due to Ahues & Tisseur (LAWN 122,
350 * . 1997). It has better mathematical foundation and
351 * . improves accuracy in some examples. ====
352 IF( ABS( REAL( H( K, K-1 ) ) ).LE.ULP*TST ) THEN
353 AB = MAX( CABS1( H( K, K-1 ) ), CABS1( H( K-1, K ) ) )
354 BA = MIN( CABS1( H( K, K-1 ) ), CABS1( H( K-1, K ) ) )
355 AA = MAX( CABS1( H( K, K ) ),
356 $ CABS1( H( K-1, K-1 )-H( K, K ) ) )
357 BB = MIN( CABS1( H( K, K ) ),
358 $ CABS1( H( K-1, K-1 )-H( K, K ) ) )
360 IF( BA*( AB / S ).LE.MAX( SMLNUM,
361 $ ULP*( BB*( AA / S ) ) ) )GO TO 50
368 * H(L,L-1) is negligible
373 * Exit from loop if a submatrix of order 1 has split off.
378 * Now the active submatrix is in rows and columns L to I. If
379 * eigenvalues only are being computed, only the active submatrix
380 * need be transformed.
382 IF( .NOT.WANTT ) THEN
391 S = DAT1*ABS( REAL( H( L+1, L ) ) )
393 ELSE IF( ITS.EQ.20 ) THEN
397 S = DAT1*ABS( REAL( H( I, I-1 ) ) )
404 U = SQRT( H( I-1, I ) )*SQRT( H( I, I-1 ) )
406 IF( S.NE.RZERO ) THEN
407 X = HALF*( H( I-1, I-1 )-T )
409 S = MAX( S, CABS1( X ) )
410 Y = S*SQRT( ( X / S )**2+( U / S )**2 )
411 IF( SX.GT.RZERO ) THEN
412 IF( REAL( X / SX )*REAL( Y )+AIMAG( X / SX )*
413 $ AIMAG( Y ).LT.RZERO )Y = -Y
415 T = T - U*CLADIV( U, ( X+Y ) )
419 * Look for two consecutive small subdiagonal elements.
421 DO 60 M = I - 1, L + 1, -1
423 * Determine the effect of starting the single-shift QR
424 * iteration at row M, and see if this would make H(M,M-1)
430 H21 = REAL( H( M+1, M ) )
431 S = CABS1( H11S ) + ABS( H21 )
436 H10 = REAL( H( M, M-1 ) )
437 IF( ABS( H10 )*ABS( H21 ).LE.ULP*
438 $ ( CABS1( H11S )*( CABS1( H11 )+CABS1( H22 ) ) ) )
444 H21 = REAL( H( L+1, L ) )
445 S = CABS1( H11S ) + ABS( H21 )
452 * Single-shift QR step
456 * The first iteration of this loop determines a reflection G
457 * from the vector V and applies it from left and right to H,
458 * thus creating a nonzero bulge below the subdiagonal.
460 * Each subsequent iteration determines a reflection G to
461 * restore the Hessenberg form in the (K-1)th column, and thus
462 * chases the bulge one step toward the bottom of the active
465 * V(2) is always real before the call to CLARFG, and hence
466 * after the call T2 ( = T1*V(2) ) is also real.
469 $ CALL CCOPY( 2, H( K, K-1 ), 1, V, 1 )
470 CALL CLARFG( 2, V( 1 ), V( 2 ), 1, T1 )
478 * Apply G from the left to transform the rows of the matrix
479 * in columns K to I2.
482 SUM = CONJG( T1 )*H( K, J ) + T2*H( K+1, J )
483 H( K, J ) = H( K, J ) - SUM
484 H( K+1, J ) = H( K+1, J ) - SUM*V2
487 * Apply G from the right to transform the columns of the
488 * matrix in rows I1 to min(K+2,I).
490 DO 90 J = I1, MIN( K+2, I )
491 SUM = T1*H( J, K ) + T2*H( J, K+1 )
492 H( J, K ) = H( J, K ) - SUM
493 H( J, K+1 ) = H( J, K+1 ) - SUM*CONJG( V2 )
498 * Accumulate transformations in the matrix Z
500 DO 100 J = ILOZ, IHIZ
501 SUM = T1*Z( J, K ) + T2*Z( J, K+1 )
502 Z( J, K ) = Z( J, K ) - SUM
503 Z( J, K+1 ) = Z( J, K+1 ) - SUM*CONJG( V2 )
507 IF( K.EQ.M .AND. M.GT.L ) THEN
509 * If the QR step was started at row M > L because two
510 * consecutive small subdiagonals were found, then extra
511 * scaling must be performed to ensure that H(M,M-1) remains
515 TEMP = TEMP / ABS( TEMP )
516 H( M+1, M ) = H( M+1, M )*CONJG( TEMP )
518 $ H( M+2, M+1 ) = H( M+2, M+1 )*TEMP
522 $ CALL CSCAL( I2-J, TEMP, H( J, J+1 ), LDH )
523 CALL CSCAL( J-I1, CONJG( TEMP ), H( I1, J ), 1 )
525 CALL CSCAL( NZ, CONJG( TEMP ), Z( ILOZ, J ), 1 )
532 * Ensure that H(I,I-1) is real.
535 IF( AIMAG( TEMP ).NE.RZERO ) THEN
540 $ CALL CSCAL( I2-I, CONJG( TEMP ), H( I, I+1 ), LDH )
541 CALL CSCAL( I-I1, TEMP, H( I1, I ), 1 )
543 CALL CSCAL( NZ, TEMP, Z( ILOZ, I ), 1 )
549 * Failure to converge in remaining number of iterations
556 * H(I,I-1) is negligible: one eigenvalue has converged.
560 * return to start of the main loop with new value of I.