LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zlahqr.f
Go to the documentation of this file.
1*> \brief \b ZLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix, using the double-shift/single-shift QR algorithm.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZLAHQR + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahqr.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahqr.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahqr.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZLAHQR( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
20* IHIZ, Z, LDZ, INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
24* LOGICAL WANTT, WANTZ
25* ..
26* .. Array Arguments ..
27* COMPLEX*16 H( LDH, * ), W( * ), Z( LDZ, * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> ZLAHQR is an auxiliary routine called by CHSEQR to update the
37*> eigenvalues and Schur decomposition already computed by CHSEQR, by
38*> dealing with the Hessenberg submatrix in rows and columns ILO to
39*> IHI.
40*> \endverbatim
41*
42* Arguments:
43* ==========
44*
45*> \param[in] WANTT
46*> \verbatim
47*> WANTT is LOGICAL
48*> = .TRUE. : the full Schur form T is required;
49*> = .FALSE.: only eigenvalues are required.
50*> \endverbatim
51*>
52*> \param[in] WANTZ
53*> \verbatim
54*> WANTZ is LOGICAL
55*> = .TRUE. : the matrix of Schur vectors Z is required;
56*> = .FALSE.: Schur vectors are not required.
57*> \endverbatim
58*>
59*> \param[in] N
60*> \verbatim
61*> N is INTEGER
62*> The order of the matrix H. N >= 0.
63*> \endverbatim
64*>
65*> \param[in] ILO
66*> \verbatim
67*> ILO is INTEGER
68*> \endverbatim
69*>
70*> \param[in] IHI
71*> \verbatim
72*> IHI is INTEGER
73*> It is assumed that H is already upper triangular in rows and
74*> columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1).
75*> ZLAHQR works primarily with the Hessenberg submatrix in rows
76*> and columns ILO to IHI, but applies transformations to all of
77*> H if WANTT is .TRUE..
78*> 1 <= ILO <= max(1,IHI); IHI <= N.
79*> \endverbatim
80*>
81*> \param[in,out] H
82*> \verbatim
83*> H is COMPLEX*16 array, dimension (LDH,N)
84*> On entry, the upper Hessenberg matrix H.
85*> On exit, if INFO is zero and if WANTT is .TRUE., then H
86*> is upper triangular in rows and columns ILO:IHI. If INFO
87*> is zero and if WANTT is .FALSE., then the contents of H
88*> are unspecified on exit. The output state of H in case
89*> INF is positive is below under the description of INFO.
90*> \endverbatim
91*>
92*> \param[in] LDH
93*> \verbatim
94*> LDH is INTEGER
95*> The leading dimension of the array H. LDH >= max(1,N).
96*> \endverbatim
97*>
98*> \param[out] W
99*> \verbatim
100*> W is COMPLEX*16 array, dimension (N)
101*> The computed eigenvalues ILO to IHI are stored in the
102*> corresponding elements of W. If WANTT is .TRUE., the
103*> eigenvalues are stored in the same order as on the diagonal
104*> of the Schur form returned in H, with W(i) = H(i,i).
105*> \endverbatim
106*>
107*> \param[in] ILOZ
108*> \verbatim
109*> ILOZ is INTEGER
110*> \endverbatim
111*>
112*> \param[in] IHIZ
113*> \verbatim
114*> IHIZ is INTEGER
115*> Specify the rows of Z to which transformations must be
116*> applied if WANTZ is .TRUE..
117*> 1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
118*> \endverbatim
119*>
120*> \param[in,out] Z
121*> \verbatim
122*> Z is COMPLEX*16 array, dimension (LDZ,N)
123*> If WANTZ is .TRUE., on entry Z must contain the current
124*> matrix Z of transformations accumulated by CHSEQR, and on
125*> exit Z has been updated; transformations are applied only to
126*> the submatrix Z(ILOZ:IHIZ,ILO:IHI).
127*> If WANTZ is .FALSE., Z is not referenced.
128*> \endverbatim
129*>
130*> \param[in] LDZ
131*> \verbatim
132*> LDZ is INTEGER
133*> The leading dimension of the array Z. LDZ >= max(1,N).
134*> \endverbatim
135*>
136*> \param[out] INFO
137*> \verbatim
138*> INFO is INTEGER
139*> = 0: successful exit
140*> > 0: if INFO = i, ZLAHQR failed to compute all the
141*> eigenvalues ILO to IHI in a total of 30 iterations
142*> per eigenvalue; elements i+1:ihi of W contain
143*> those eigenvalues which have been successfully
144*> computed.
145*>
146*> If INFO > 0 and WANTT is .FALSE., then on exit,
147*> the remaining unconverged eigenvalues are the
148*> eigenvalues of the upper Hessenberg matrix
149*> rows and columns ILO through INFO of the final,
150*> output value of H.
151*>
152*> If INFO > 0 and WANTT is .TRUE., then on exit
153*> (*) (initial value of H)*U = U*(final value of H)
154*> where U is an orthogonal matrix. The final
155*> value of H is upper Hessenberg and triangular in
156*> rows and columns INFO+1 through IHI.
157*>
158*> If INFO > 0 and WANTZ is .TRUE., then on exit
159*> (final value of Z) = (initial value of Z)*U
160*> where U is the orthogonal matrix in (*)
161*> (regardless of the value of WANTT.)
162*> \endverbatim
163*
164* Authors:
165* ========
166*
167*> \author Univ. of Tennessee
168*> \author Univ. of California Berkeley
169*> \author Univ. of Colorado Denver
170*> \author NAG Ltd.
171*
172*> \ingroup lahqr
173*
174*> \par Contributors:
175* ==================
176*>
177*> \verbatim
178*>
179*> 02-96 Based on modifications by
180*> David Day, Sandia National Laboratory, USA
181*>
182*> 12-04 Further modifications by
183*> Ralph Byers, University of Kansas, USA
184*> This is a modified version of ZLAHQR from LAPACK version 3.0.
185*> It is (1) more robust against overflow and underflow and
186*> (2) adopts the more conservative Ahues & Tisseur stopping
187*> criterion (LAWN 122, 1997).
188*> \endverbatim
189*>
190* =====================================================================
191 SUBROUTINE zlahqr( WANTT, WANTZ, N, ILO, IHI, H, LDH, W, ILOZ,
192 $ IHIZ, Z, LDZ, INFO )
193 IMPLICIT NONE
194*
195* -- LAPACK auxiliary routine --
196* -- LAPACK is a software package provided by Univ. of Tennessee, --
197* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
198*
199* .. Scalar Arguments ..
200 INTEGER IHI, IHIZ, ILO, ILOZ, INFO, LDH, LDZ, N
201 LOGICAL WANTT, WANTZ
202* ..
203* .. Array Arguments ..
204 COMPLEX*16 H( LDH, * ), W( * ), Z( LDZ, * )
205* ..
206*
207* =========================================================
208*
209* .. Parameters ..
210 COMPLEX*16 ZERO, ONE
211 parameter( zero = ( 0.0d0, 0.0d0 ),
212 $ one = ( 1.0d0, 0.0d0 ) )
213 DOUBLE PRECISION RZERO, RONE, HALF
214 parameter( rzero = 0.0d0, rone = 1.0d0, half = 0.5d0 )
215 DOUBLE PRECISION DAT1
216 parameter( dat1 = 3.0d0 / 4.0d0 )
217 INTEGER KEXSH
218 parameter( kexsh = 10 )
219* ..
220* .. Local Scalars ..
221 COMPLEX*16 CDUM, H11, H11S, H22, SC, SUM, T, T1, TEMP, U,
222 $ v2, x, y
223 DOUBLE PRECISION AA, AB, BA, BB, H10, H21, RTEMP, S, SAFMAX,
224 $ safmin, smlnum, sx, t2, tst, ulp
225 INTEGER I, I1, I2, ITS, ITMAX, J, JHI, JLO, K, L, M,
226 $ nh, nz, kdefl
227* ..
228* .. Local Arrays ..
229 COMPLEX*16 V( 2 )
230* ..
231* .. External Functions ..
232 COMPLEX*16 ZLADIV
233 DOUBLE PRECISION DLAMCH
234 EXTERNAL zladiv, dlamch
235* ..
236* .. External Subroutines ..
237 EXTERNAL zcopy, zlarfg, zscal
238* ..
239* .. Statement Functions ..
240 DOUBLE PRECISION CABS1
241* ..
242* .. Intrinsic Functions ..
243 INTRINSIC abs, dble, dconjg, dimag, max, min, sqrt
244* ..
245* .. Statement Function definitions ..
246 cabs1( cdum ) = abs( dble( cdum ) ) + abs( dimag( cdum ) )
247* ..
248* .. Executable Statements ..
249*
250 info = 0
251*
252* Quick return if possible
253*
254 IF( n.EQ.0 )
255 $ RETURN
256 IF( ilo.EQ.ihi ) THEN
257 w( ilo ) = h( ilo, ilo )
258 RETURN
259 END IF
260*
261* ==== clear out the trash ====
262 DO 10 j = ilo, ihi - 3
263 h( j+2, j ) = zero
264 h( j+3, j ) = zero
265 10 CONTINUE
266 IF( ilo.LE.ihi-2 )
267 $ h( ihi, ihi-2 ) = zero
268* ==== ensure that subdiagonal entries are real ====
269 IF( wantt ) THEN
270 jlo = 1
271 jhi = n
272 ELSE
273 jlo = ilo
274 jhi = ihi
275 END IF
276 DO 20 i = ilo + 1, ihi
277 IF( dimag( h( i, i-1 ) ).NE.rzero ) THEN
278* ==== The following redundant normalization
279* . avoids problems with both gradual and
280* . sudden underflow in ABS(H(I,I-1)) ====
281 sc = h( i, i-1 ) / cabs1( h( i, i-1 ) )
282 sc = dconjg( sc ) / abs( sc )
283 h( i, i-1 ) = abs( h( i, i-1 ) )
284 CALL zscal( jhi-i+1, sc, h( i, i ), ldh )
285 CALL zscal( min( jhi, i+1 )-jlo+1, dconjg( sc ),
286 $ h( jlo, i ), 1 )
287 IF( wantz )
288 $ CALL zscal( ihiz-iloz+1, dconjg( sc ), z( iloz, i ),
289 $ 1 )
290 END IF
291 20 CONTINUE
292*
293 nh = ihi - ilo + 1
294 nz = ihiz - iloz + 1
295*
296* Set machine-dependent constants for the stopping criterion.
297*
298 safmin = dlamch( 'SAFE MINIMUM' )
299 safmax = rone / safmin
300 ulp = dlamch( 'PRECISION' )
301 smlnum = safmin*( dble( nh ) / ulp )
302*
303* I1 and I2 are the indices of the first row and last column of H
304* to which transformations must be applied. If eigenvalues only are
305* being computed, I1 and I2 are set inside the main loop.
306*
307 IF( wantt ) THEN
308 i1 = 1
309 i2 = n
310 END IF
311*
312* ITMAX is the total number of QR iterations allowed.
313*
314 itmax = 30 * max( 10, nh )
315*
316* KDEFL counts the number of iterations since a deflation
317*
318 kdefl = 0
319*
320* The main loop begins here. I is the loop index and decreases from
321* IHI to ILO in steps of 1. Each iteration of the loop works
322* with the active submatrix in rows and columns L to I.
323* Eigenvalues I+1 to IHI have already converged. Either L = ILO, or
324* H(L,L-1) is negligible so that the matrix splits.
325*
326 i = ihi
327 30 CONTINUE
328 IF( i.LT.ilo )
329 $ GO TO 150
330*
331* Perform QR iterations on rows and columns ILO to I until a
332* submatrix of order 1 splits off at the bottom because a
333* subdiagonal element has become negligible.
334*
335 l = ilo
336 DO 130 its = 0, itmax
337*
338* Look for a single small subdiagonal element.
339*
340 DO 40 k = i, l + 1, -1
341 IF( cabs1( h( k, k-1 ) ).LE.smlnum )
342 $ GO TO 50
343 tst = cabs1( h( k-1, k-1 ) ) + cabs1( h( k, k ) )
344 IF( tst.EQ.zero ) THEN
345 IF( k-2.GE.ilo )
346 $ tst = tst + abs( dble( h( k-1, k-2 ) ) )
347 IF( k+1.LE.ihi )
348 $ tst = tst + abs( dble( h( k+1, k ) ) )
349 END IF
350* ==== The following is a conservative small subdiagonal
351* . deflation criterion due to Ahues & Tisseur (LAWN 122,
352* . 1997). It has better mathematical foundation and
353* . improves accuracy in some examples. ====
354 IF( abs( dble( h( k, k-1 ) ) ).LE.ulp*tst ) THEN
355 ab = max( cabs1( h( k, k-1 ) ), cabs1( h( k-1, k ) ) )
356 ba = min( cabs1( h( k, k-1 ) ), cabs1( h( k-1, k ) ) )
357 aa = max( cabs1( h( k, k ) ),
358 $ cabs1( h( k-1, k-1 )-h( k, k ) ) )
359 bb = min( cabs1( h( k, k ) ),
360 $ cabs1( h( k-1, k-1 )-h( k, k ) ) )
361 s = aa + ab
362 IF( ba*( ab / s ).LE.max( smlnum,
363 $ ulp*( bb*( aa / s ) ) ) )GO TO 50
364 END IF
365 40 CONTINUE
366 50 CONTINUE
367 l = k
368 IF( l.GT.ilo ) THEN
369*
370* H(L,L-1) is negligible
371*
372 h( l, l-1 ) = zero
373 END IF
374*
375* Exit from loop if a submatrix of order 1 has split off.
376*
377 IF( l.GE.i )
378 $ GO TO 140
379 kdefl = kdefl + 1
380*
381* Now the active submatrix is in rows and columns L to I. If
382* eigenvalues only are being computed, only the active submatrix
383* need be transformed.
384*
385 IF( .NOT.wantt ) THEN
386 i1 = l
387 i2 = i
388 END IF
389*
390 IF( mod(kdefl,2*kexsh).EQ.0 ) THEN
391*
392* Exceptional shift.
393*
394 s = dat1*abs( dble( h( i, i-1 ) ) )
395 t = s + h( i, i )
396 ELSE IF( mod(kdefl,kexsh).EQ.0 ) THEN
397*
398* Exceptional shift.
399*
400 s = dat1*abs( dble( h( l+1, l ) ) )
401 t = s + h( l, l )
402 ELSE
403*
404* Wilkinson's shift.
405*
406 t = h( i, i )
407 u = sqrt( h( i-1, i ) )*sqrt( h( i, i-1 ) )
408 s = cabs1( u )
409 IF( s.NE.rzero ) THEN
410 x = half*( h( i-1, i-1 )-t )
411 sx = cabs1( x )
412 s = max( s, cabs1( x ) )
413 y = s*sqrt( ( x / s )**2+( u / s )**2 )
414 IF( sx.GT.rzero ) THEN
415 IF( dble( x / sx )*dble( y )+dimag( x / sx )*
416 $ dimag( y ).LT.rzero )y = -y
417 END IF
418 t = t - u*zladiv( u, ( x+y ) )
419 END IF
420 END IF
421*
422* Look for two consecutive small subdiagonal elements.
423*
424 DO 60 m = i - 1, l + 1, -1
425*
426* Determine the effect of starting the single-shift QR
427* iteration at row M, and see if this would make H(M,M-1)
428* negligible.
429*
430 h11 = h( m, m )
431 h22 = h( m+1, m+1 )
432 h11s = h11 - t
433 h21 = dble( h( m+1, m ) )
434 s = cabs1( h11s ) + abs( h21 )
435 h11s = h11s / s
436 h21 = h21 / s
437 v( 1 ) = h11s
438 v( 2 ) = h21
439 h10 = dble( h( m, m-1 ) )
440 IF( abs( h10 )*abs( h21 ).LE.ulp*
441 $ ( cabs1( h11s )*( cabs1( h11 )+cabs1( h22 ) ) ) )
442 $ GO TO 70
443 60 CONTINUE
444 h11 = h( l, l )
445 h22 = h( l+1, l+1 )
446 h11s = h11 - t
447 h21 = dble( h( l+1, l ) )
448 s = cabs1( h11s ) + abs( h21 )
449 h11s = h11s / s
450 h21 = h21 / s
451 v( 1 ) = h11s
452 v( 2 ) = h21
453 70 CONTINUE
454*
455* Single-shift QR step
456*
457 DO 120 k = m, i - 1
458*
459* The first iteration of this loop determines a reflection G
460* from the vector V and applies it from left and right to H,
461* thus creating a nonzero bulge below the subdiagonal.
462*
463* Each subsequent iteration determines a reflection G to
464* restore the Hessenberg form in the (K-1)th column, and thus
465* chases the bulge one step toward the bottom of the active
466* submatrix.
467*
468* V(2) is always real before the call to ZLARFG, and hence
469* after the call T2 ( = T1*V(2) ) is also real.
470*
471 IF( k.GT.m )
472 $ CALL zcopy( 2, h( k, k-1 ), 1, v, 1 )
473 CALL zlarfg( 2, v( 1 ), v( 2 ), 1, t1 )
474 IF( k.GT.m ) THEN
475 h( k, k-1 ) = v( 1 )
476 h( k+1, k-1 ) = zero
477 END IF
478 v2 = v( 2 )
479 t2 = dble( t1*v2 )
480*
481* Apply G from the left to transform the rows of the matrix
482* in columns K to I2.
483*
484 DO 80 j = k, i2
485 sum = dconjg( t1 )*h( k, j ) + t2*h( k+1, j )
486 h( k, j ) = h( k, j ) - sum
487 h( k+1, j ) = h( k+1, j ) - sum*v2
488 80 CONTINUE
489*
490* Apply G from the right to transform the columns of the
491* matrix in rows I1 to min(K+2,I).
492*
493 DO 90 j = i1, min( k+2, i )
494 sum = t1*h( j, k ) + t2*h( j, k+1 )
495 h( j, k ) = h( j, k ) - sum
496 h( j, k+1 ) = h( j, k+1 ) - sum*dconjg( v2 )
497 90 CONTINUE
498*
499 IF( wantz ) THEN
500*
501* Accumulate transformations in the matrix Z
502*
503 DO 100 j = iloz, ihiz
504 sum = t1*z( j, k ) + t2*z( j, k+1 )
505 z( j, k ) = z( j, k ) - sum
506 z( j, k+1 ) = z( j, k+1 ) - sum*dconjg( v2 )
507 100 CONTINUE
508 END IF
509*
510 IF( k.EQ.m .AND. m.GT.l ) THEN
511*
512* If the QR step was started at row M > L because two
513* consecutive small subdiagonals were found, then extra
514* scaling must be performed to ensure that H(M,M-1) remains
515* real.
516*
517 temp = one - t1
518 temp = temp / abs( temp )
519 h( m+1, m ) = h( m+1, m )*dconjg( temp )
520 IF( m+2.LE.i )
521 $ h( m+2, m+1 ) = h( m+2, m+1 )*temp
522 DO 110 j = m, i
523 IF( j.NE.m+1 ) THEN
524 IF( i2.GT.j )
525 $ CALL zscal( i2-j, temp, h( j, j+1 ), ldh )
526 CALL zscal( j-i1, dconjg( temp ), h( i1, j ),
527 $ 1 )
528 IF( wantz ) THEN
529 CALL zscal( nz, dconjg( temp ), z( iloz, j ),
530 $ 1 )
531 END IF
532 END IF
533 110 CONTINUE
534 END IF
535 120 CONTINUE
536*
537* Ensure that H(I,I-1) is real.
538*
539 temp = h( i, i-1 )
540 IF( dimag( temp ).NE.rzero ) THEN
541 rtemp = abs( temp )
542 h( i, i-1 ) = rtemp
543 temp = temp / rtemp
544 IF( i2.GT.i )
545 $ CALL zscal( i2-i, dconjg( temp ), h( i, i+1 ), ldh )
546 CALL zscal( i-i1, temp, h( i1, i ), 1 )
547 IF( wantz ) THEN
548 CALL zscal( nz, temp, z( iloz, i ), 1 )
549 END IF
550 END IF
551*
552 130 CONTINUE
553*
554* Failure to converge in remaining number of iterations
555*
556 info = i
557 RETURN
558*
559 140 CONTINUE
560*
561* H(I,I-1) is negligible: one eigenvalue has converged.
562*
563 w( i ) = h( i, i )
564* reset deflation counter
565 kdefl = 0
566*
567* return to start of the main loop with new value of I.
568*
569 i = l - 1
570 GO TO 30
571*
572 150 CONTINUE
573 RETURN
574*
575* End of ZLAHQR
576*
577 END
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
Definition zcopy.f:81
subroutine zlahqr(wantt, wantz, n, ilo, ihi, h, ldh, w, iloz, ihiz, z, ldz, info)
ZLAHQR computes the eigenvalues and Schur factorization of an upper Hessenberg matrix,...
Definition zlahqr.f:193
subroutine zlarfg(n, alpha, x, incx, tau)
ZLARFG generates an elementary reflector (Householder matrix).
Definition zlarfg.f:104
subroutine zscal(n, za, zx, incx)
ZSCAL
Definition zscal.f:78