1 *> \brief \b DLAHQR 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 DLAHQR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlahqr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlahqr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlahqr.f">
21 * SUBROUTINE DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
22 * ILOZ, 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 * DOUBLE PRECISION H( LDH, * ), WI( * ), WR( * ), Z( LDZ, * )
38 *> DLAHQR is an auxiliary routine called by DHSEQR to update the
39 *> eigenvalues and Schur decomposition already computed by DHSEQR, 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 quasi-triangular in
76 *> rows and columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless
77 *> ILO = 1). DLAHQR works primarily with the Hessenberg
78 *> submatrix in rows and columns ILO to IHI, but applies
79 *> transformations to all of H if WANTT is .TRUE..
80 *> 1 <= ILO <= max(1,IHI); IHI <= N.
85 *> H is DOUBLE PRECISION array, dimension (LDH,N)
86 *> On entry, the upper Hessenberg matrix H.
87 *> On exit, if INFO is zero and if WANTT is .TRUE., H is upper
88 *> quasi-triangular in rows and columns ILO:IHI, with any
89 *> 2-by-2 diagonal blocks in standard form. If INFO is zero
90 *> and WANTT is .FALSE., the contents of H are unspecified on
91 *> exit. The output state of H if INFO is nonzero is given
92 *> below under the description of INFO.
98 *> The leading dimension of the array H. LDH >= max(1,N).
103 *> WR is DOUBLE PRECISION array, dimension (N)
108 *> WI is DOUBLE PRECISION array, dimension (N)
109 *> The real and imaginary parts, respectively, of the computed
110 *> eigenvalues ILO to IHI are stored in the corresponding
111 *> elements of WR and WI. If two eigenvalues are computed as a
112 *> complex conjugate pair, they are stored in consecutive
113 *> elements of WR and WI, say the i-th and (i+1)th, with
114 *> WI(i) > 0 and WI(i+1) < 0. If WANTT is .TRUE., the
115 *> eigenvalues are stored in the same order as on the diagonal
116 *> of the Schur form returned in H, with WR(i) = H(i,i), and, if
117 *> H(i:i+1,i:i+1) is a 2-by-2 diagonal block,
118 *> WI(i) = sqrt(H(i+1,i)*H(i,i+1)) and WI(i+1) = -WI(i).
129 *> Specify the rows of Z to which transformations must be
130 *> applied if WANTZ is .TRUE..
131 *> 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
136 *> Z is DOUBLE PRECISION array, dimension (LDZ,N)
137 *> If WANTZ is .TRUE., on entry Z must contain the current
138 *> matrix Z of transformations accumulated by DHSEQR, and on
139 *> exit Z has been updated; transformations are applied only to
140 *> the submatrix Z(ILOZ:IHIZ,ILO:IHI).
141 *> If WANTZ is .FALSE., Z is not referenced.
147 *> The leading dimension of the array Z. LDZ >= max(1,N).
153 *> = 0: successful exit
154 *> .GT. 0: If INFO = i, DLAHQR failed to compute all the
155 *> eigenvalues ILO to IHI in a total of 30 iterations
156 *> per eigenvalue; elements i+1:ihi of WR and WI
157 *> contain those eigenvalues which have been
158 *> successfully computed.
160 *> If INFO .GT. 0 and WANTT is .FALSE., then on exit,
161 *> the remaining unconverged eigenvalues are the
162 *> eigenvalues of the upper Hessenberg matrix rows
163 *> and columns ILO thorugh INFO of the final, output
166 *> If INFO .GT. 0 and WANTT is .TRUE., then on exit
167 *> (*) (initial value of H)*U = U*(final value of H)
168 *> where U is an orthognal matrix. The final
169 *> value of H is upper Hessenberg and triangular in
170 *> rows and columns INFO+1 through IHI.
172 *> If INFO .GT. 0 and WANTZ is .TRUE., then on exit
173 *> (final value of Z) = (initial value of Z)*U
174 *> where U is the orthogonal matrix in (*)
175 *> (regardless of the value of WANTT.)
181 *> \author Univ. of Tennessee
182 *> \author Univ. of California Berkeley
183 *> \author Univ. of Colorado Denver
186 *> \date November 2015
188 *> \ingroup doubleOTHERauxiliary
190 *> \par Further Details:
191 * =====================
195 *> 02-96 Based on modifications by
196 *> David Day, Sandia National Laboratory, USA
198 *> 12-04 Further modifications by
199 *> Ralph Byers, University of Kansas, USA
200 *> This is a modified version of DLAHQR from LAPACK version 3.0.
201 *> It is (1) more robust against overflow and underflow and
202 *> (2) adopts the more conservative Ahues & Tisseur stopping
203 *> criterion (LAWN 122, 1997).
206 * =====================================================================
207 SUBROUTINE DLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, WR, WI,
208 $ ILOZ, IHIZ, Z, LDZ, INFO )
210 * -- LAPACK auxiliary routine (version 3.6.0) --
211 * -- LAPACK is a software package provided by Univ. of Tennessee, --
212 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
215 * .. Scalar Arguments ..
216 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
219 * .. Array Arguments ..
220 DOUBLE PRECISION H( LDH, * ), WI( * ), WR( * ), Z( LDZ, * )
223 * =========================================================
226 DOUBLE PRECISION ZERO, ONE, TWO
227 PARAMETER ( ZERO = 0.0d0, ONE = 1.0d0, TWO = 2.0d0 )
228 DOUBLE PRECISION DAT1, DAT2
229 PARAMETER ( DAT1 = 3.0d0 / 4.0d0, DAT2 = -0.4375d0 )
231 * .. Local Scalars ..
232 DOUBLE PRECISION AA, AB, BA, BB, CS, DET, H11, H12, H21, H21S,
233 $ H22, RT1I, RT1R, RT2I, RT2R, RTDISC, S, SAFMAX,
234 $ SAFMIN, SMLNUM, SN, SUM, T1, T2, T3, TR, TST,
236 INTEGER I, I1, I2, ITS, ITMAX, J, K, L, M, NH, NR, NZ
239 DOUBLE PRECISION V( 3 )
241 * .. External Functions ..
242 DOUBLE PRECISION DLAMCH
245 * .. External Subroutines ..
246 EXTERNAL DCOPY, DLABAD, DLANV2, DLARFG, DROT
248 * .. Intrinsic Functions ..
249 INTRINSIC ABS, DBLE, MAX, MIN, SQRT
251 * .. Executable Statements ..
255 * Quick return if possible
259 IF( ILO.EQ.IHI ) THEN
260 WR( ILO ) = H( ILO, ILO )
265 * ==== clear out the trash ====
266 DO 10 J = ILO, IHI - 3
271 $ H( IHI, IHI-2 ) = ZERO
276 * Set machine-dependent constants for the stopping criterion.
278 SAFMIN = DLAMCH( 'SAFE MINIMUM' )
279 SAFMAX = ONE / SAFMIN
280 CALL DLABAD( SAFMIN, SAFMAX )
281 ULP = DLAMCH( 'PRECISION' )
282 SMLNUM = SAFMIN*( DBLE( NH ) / ULP )
284 * I1 and I2 are the indices of the first row and last column of H
285 * to which transformations must be applied. If eigenvalues only are
286 * being computed, I1 and I2 are set inside the main loop.
293 * ITMAX is the total number of QR iterations allowed.
295 ITMAX = 30 * MAX( 10, NH )
297 * The main loop begins here. I is the loop index and decreases from
298 * IHI to ILO in steps of 1 or 2. Each iteration of the loop works
299 * with the active submatrix in rows and columns L to I.
300 * Eigenvalues I+1 to IHI have already converged. Either L = ILO or
301 * H(L,L-1) is negligible so that the matrix splits.
309 * Perform QR iterations on rows and columns ILO to I until a
310 * submatrix of order 1 or 2 splits off at the bottom because a
311 * subdiagonal element has become negligible.
313 DO 140 ITS = 0, ITMAX
315 * Look for a single small subdiagonal element.
317 DO 30 K = I, L + 1, -1
318 IF( ABS( H( K, K-1 ) ).LE.SMLNUM )
320 TST = ABS( H( K-1, K-1 ) ) + ABS( H( K, K ) )
321 IF( TST.EQ.ZERO ) THEN
323 $ TST = TST + ABS( H( K-1, K-2 ) )
325 $ TST = TST + ABS( H( K+1, K ) )
327 * ==== The following is a conservative small subdiagonal
328 * . deflation criterion due to Ahues & Tisseur (LAWN 122,
329 * . 1997). It has better mathematical foundation and
330 * . improves accuracy in some cases. ====
331 IF( ABS( H( K, K-1 ) ).LE.ULP*TST ) THEN
332 AB = MAX( ABS( H( K, K-1 ) ), ABS( H( K-1, K ) ) )
333 BA = MIN( ABS( H( K, K-1 ) ), ABS( H( K-1, K ) ) )
334 AA = MAX( ABS( H( K, K ) ),
335 $ ABS( H( K-1, K-1 )-H( K, K ) ) )
336 BB = MIN( ABS( H( K, K ) ),
337 $ ABS( H( K-1, K-1 )-H( K, K ) ) )
339 IF( BA*( AB / S ).LE.MAX( SMLNUM,
340 $ ULP*( BB*( AA / S ) ) ) )GO TO 40
347 * H(L,L-1) is negligible
352 * Exit from loop if a submatrix of order 1 or 2 has split off.
357 * Now the active submatrix is in rows and columns L to I. If
358 * eigenvalues only are being computed, only the active submatrix
359 * need be transformed.
361 IF( .NOT.WANTT ) THEN
370 S = ABS( H( L+1, L ) ) + ABS( H( L+2, L+1 ) )
371 H11 = DAT1*S + H( L, L )
375 ELSE IF( ITS.EQ.20 ) THEN
379 S = ABS( H( I, I-1 ) ) + ABS( H( I-1, I-2 ) )
380 H11 = DAT1*S + H( I, I )
386 * Prepare to use Francis' double shift
387 * (i.e. 2nd degree generalized Rayleigh quotient)
394 S = ABS( H11 ) + ABS( H12 ) + ABS( H21 ) + ABS( H22 )
405 TR = ( H11+H22 ) / TWO
406 DET = ( H11-TR )*( H22-TR ) - H12*H21
407 RTDISC = SQRT( ABS( DET ) )
408 IF( DET.GE.ZERO ) THEN
410 * ==== complex conjugate shifts ====
418 * ==== real shifts (use only one of them) ====
422 IF( ABS( RT1R-H22 ).LE.ABS( RT2R-H22 ) ) THEN
434 * Look for two consecutive small subdiagonal elements.
436 DO 50 M = I - 2, L, -1
437 * Determine the effect of starting the double-shift QR
438 * iteration at row M, and see if this would make H(M,M-1)
439 * negligible. (The following uses scaling to avoid
440 * overflows and most underflows.)
443 S = ABS( H( M, M )-RT2R ) + ABS( RT2I ) + ABS( H21S )
444 H21S = H( M+1, M ) / S
445 V( 1 ) = H21S*H( M, M+1 ) + ( H( M, M )-RT1R )*
446 $ ( ( H( M, M )-RT2R ) / S ) - RT1I*( RT2I / S )
447 V( 2 ) = H21S*( H( M, M )+H( M+1, M+1 )-RT1R-RT2R )
448 V( 3 ) = H21S*H( M+2, M+1 )
449 S = ABS( V( 1 ) ) + ABS( V( 2 ) ) + ABS( V( 3 ) )
455 IF( ABS( H( M, M-1 ) )*( ABS( V( 2 ) )+ABS( V( 3 ) ) ).LE.
456 $ ULP*ABS( V( 1 ) )*( ABS( H( M-1, M-1 ) )+ABS( H( M,
457 $ M ) )+ABS( H( M+1, M+1 ) ) ) )GO TO 60
461 * Double-shift QR step
465 * The first iteration of this loop determines a reflection G
466 * from the vector V and applies it from left and right to H,
467 * thus creating a nonzero bulge below the subdiagonal.
469 * Each subsequent iteration determines a reflection G to
470 * restore the Hessenberg form in the (K-1)th column, and thus
471 * chases the bulge one step toward the bottom of the active
472 * submatrix. NR is the order of G.
476 $ CALL DCOPY( NR, H( K, K-1 ), 1, V, 1 )
477 CALL DLARFG( NR, V( 1 ), V( 2 ), 1, T1 )
482 $ H( K+2, K-1 ) = ZERO
483 ELSE IF( M.GT.L ) THEN
484 * ==== Use the following instead of
485 * . H( K, K-1 ) = -H( K, K-1 ) to
486 * . avoid a bug when v(2) and v(3)
488 H( K, K-1 ) = H( K, K-1 )*( ONE-T1 )
496 * Apply G from the left to transform the rows of the matrix
497 * in columns K to I2.
500 SUM = H( K, J ) + V2*H( K+1, J ) + V3*H( K+2, J )
501 H( K, J ) = H( K, J ) - SUM*T1
502 H( K+1, J ) = H( K+1, J ) - SUM*T2
503 H( K+2, J ) = H( K+2, J ) - SUM*T3
506 * Apply G from the right to transform the columns of the
507 * matrix in rows I1 to min(K+3,I).
509 DO 80 J = I1, MIN( K+3, I )
510 SUM = H( J, K ) + V2*H( J, K+1 ) + V3*H( J, K+2 )
511 H( J, K ) = H( J, K ) - SUM*T1
512 H( J, K+1 ) = H( J, K+1 ) - SUM*T2
513 H( J, K+2 ) = H( J, K+2 ) - SUM*T3
518 * Accumulate transformations in the matrix Z
521 SUM = Z( J, K ) + V2*Z( J, K+1 ) + V3*Z( J, K+2 )
522 Z( J, K ) = Z( J, K ) - SUM*T1
523 Z( J, K+1 ) = Z( J, K+1 ) - SUM*T2
524 Z( J, K+2 ) = Z( J, K+2 ) - SUM*T3
527 ELSE IF( NR.EQ.2 ) THEN
529 * Apply G from the left to transform the rows of the matrix
530 * in columns K to I2.
533 SUM = H( K, J ) + V2*H( K+1, J )
534 H( K, J ) = H( K, J ) - SUM*T1
535 H( K+1, J ) = H( K+1, J ) - SUM*T2
538 * Apply G from the right to transform the columns of the
539 * matrix in rows I1 to min(K+3,I).
542 SUM = H( J, K ) + V2*H( J, K+1 )
543 H( J, K ) = H( J, K ) - SUM*T1
544 H( J, K+1 ) = H( J, K+1 ) - SUM*T2
549 * Accumulate transformations in the matrix Z
551 DO 120 J = ILOZ, IHIZ
552 SUM = Z( J, K ) + V2*Z( J, K+1 )
553 Z( J, K ) = Z( J, K ) - SUM*T1
554 Z( J, K+1 ) = Z( J, K+1 ) - SUM*T2
562 * Failure to converge in remaining number of iterations
571 * H(I,I-1) is negligible: one eigenvalue has converged.
575 ELSE IF( L.EQ.I-1 ) THEN
577 * H(I-1,I-2) is negligible: a pair of eigenvalues have converged.
579 * Transform the 2-by-2 submatrix to standard Schur form,
580 * and compute and store the eigenvalues.
582 CALL DLANV2( H( I-1, I-1 ), H( I-1, I ), H( I, I-1 ),
583 $ H( I, I ), WR( I-1 ), WI( I-1 ), WR( I ), WI( I ),
588 * Apply the transformation to the rest of H.
591 $ CALL DROT( I2-I, H( I-1, I+1 ), LDH, H( I, I+1 ), LDH,
593 CALL DROT( I-I1-1, H( I1, I-1 ), 1, H( I1, I ), 1, CS, SN )
597 * Apply the transformation to Z.
599 CALL DROT( NZ, Z( ILOZ, I-1 ), 1, Z( ILOZ, I ), 1, CS, SN )
603 * return to start of the main loop with new value of I.