1 *> \brief <b> ZGGEV3 computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices (blocked algorithm)</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGGEV3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggev3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggev3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggev3.f">
21 * SUBROUTINE ZGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
22 * VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER JOBVL, JOBVR
26 * INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
28 * .. Array Arguments ..
29 * DOUBLE PRECISION RWORK( * )
30 * COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
31 * $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
41 *> ZGGEV3 computes for a pair of N-by-N complex nonsymmetric matrices
42 *> (A,B), the generalized eigenvalues, and optionally, the left and/or
43 *> right generalized eigenvectors.
45 *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar
46 *> lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
47 *> singular. It is usually represented as the pair (alpha,beta), as
48 *> there is a reasonable interpretation for beta=0, and even for both
51 *> The right generalized eigenvector v(j) corresponding to the
52 *> generalized eigenvalue lambda(j) of (A,B) satisfies
54 *> A * v(j) = lambda(j) * B * v(j).
56 *> The left generalized eigenvector u(j) corresponding to the
57 *> generalized eigenvalues lambda(j) of (A,B) satisfies
59 *> u(j)**H * A = lambda(j) * u(j)**H * B
61 *> where u(j)**H is the conjugate-transpose of u(j).
69 *> JOBVL is CHARACTER*1
70 *> = 'N': do not compute the left generalized eigenvectors;
71 *> = 'V': compute the left generalized eigenvectors.
76 *> JOBVR is CHARACTER*1
77 *> = 'N': do not compute the right generalized eigenvectors;
78 *> = 'V': compute the right generalized eigenvectors.
84 *> The order of the matrices A, B, VL, and VR. N >= 0.
89 *> A is COMPLEX*16 array, dimension (LDA, N)
90 *> On entry, the matrix A in the pair (A,B).
91 *> On exit, A has been overwritten.
97 *> The leading dimension of A. LDA >= max(1,N).
102 *> B is COMPLEX*16 array, dimension (LDB, N)
103 *> On entry, the matrix B in the pair (A,B).
104 *> On exit, B has been overwritten.
110 *> The leading dimension of B. LDB >= max(1,N).
115 *> ALPHA is COMPLEX*16 array, dimension (N)
120 *> BETA is COMPLEX*16 array, dimension (N)
121 *> On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the
122 *> generalized eigenvalues.
124 *> Note: the quotients ALPHA(j)/BETA(j) may easily over- or
125 *> underflow, and BETA(j) may even be zero. Thus, the user
126 *> should avoid naively computing the ratio alpha/beta.
127 *> However, ALPHA will be always less than and usually
128 *> comparable with norm(A) in magnitude, and BETA always less
129 *> than and usually comparable with norm(B).
134 *> VL is COMPLEX*16 array, dimension (LDVL,N)
135 *> If JOBVL = 'V', the left generalized eigenvectors u(j) are
136 *> stored one after another in the columns of VL, in the same
137 *> order as their eigenvalues.
138 *> Each eigenvector is scaled so the largest component has
139 *> abs(real part) + abs(imag. part) = 1.
140 *> Not referenced if JOBVL = 'N'.
146 *> The leading dimension of the matrix VL. LDVL >= 1, and
147 *> if JOBVL = 'V', LDVL >= N.
152 *> VR is COMPLEX*16 array, dimension (LDVR,N)
153 *> If JOBVR = 'V', the right generalized eigenvectors v(j) are
154 *> stored one after another in the columns of VR, in the same
155 *> order as their eigenvalues.
156 *> Each eigenvector is scaled so the largest component has
157 *> abs(real part) + abs(imag. part) = 1.
158 *> Not referenced if JOBVR = 'N'.
164 *> The leading dimension of the matrix VR. LDVR >= 1, and
165 *> if JOBVR = 'V', LDVR >= N.
170 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
171 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
177 *> The dimension of the array WORK.
179 *> If LWORK = -1, then a workspace query is assumed; the routine
180 *> only calculates the optimal size of the WORK array, returns
181 *> this value as the first entry of the WORK array, and no error
182 *> message related to LWORK is issued by XERBLA.
187 *> RWORK is DOUBLE PRECISION array, dimension (8*N)
193 *> = 0: successful exit
194 *> < 0: if INFO = -i, the i-th argument had an illegal value.
196 *> The QZ iteration failed. No eigenvectors have been
197 *> calculated, but ALPHA(j) and BETA(j) should be
198 *> correct for j=INFO+1,...,N.
199 *> > N: =N+1: other then QZ iteration failed in DHGEQZ,
200 *> =N+2: error return from DTGEVC.
206 *> \author Univ. of Tennessee
207 *> \author Univ. of California Berkeley
208 *> \author Univ. of Colorado Denver
211 *> \date January 2015
213 *> \ingroup complex16GEeigen
215 * =====================================================================
216 SUBROUTINE ZGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
217 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
219 * -- LAPACK driver routine (version 3.6.1) --
220 * -- LAPACK is a software package provided by Univ. of Tennessee, --
221 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
224 * .. Scalar Arguments ..
225 CHARACTER JOBVL, JOBVR
226 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
228 * .. Array Arguments ..
229 DOUBLE PRECISION RWORK( * )
230 COMPLEX*16 A( LDA, * ), ALPHA( * ), B( LDB, * ),
231 $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
235 * =====================================================================
238 DOUBLE PRECISION ZERO, ONE
239 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
240 COMPLEX*16 CZERO, CONE
241 PARAMETER ( CZERO = ( 0.0D0, 0.0D0 ),
242 $ CONE = ( 1.0D0, 0.0D0 ) )
244 * .. Local Scalars ..
245 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
247 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
248 $ IN, IRIGHT, IROWS, IRWRK, ITAU, IWRK, JC, JR,
250 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
257 * .. External Subroutines ..
258 EXTERNAL DLABAD, XERBLA, ZGEQRF, ZGGBAK, ZGGBAL, ZGGHD3,
259 $ ZHGEQZ, ZLACPY, ZLASCL, ZLASET, ZTGEVC, ZUNGQR,
262 * .. External Functions ..
264 DOUBLE PRECISION DLAMCH, ZLANGE
265 EXTERNAL LSAME, DLAMCH, ZLANGE
267 * .. Intrinsic Functions ..
268 INTRINSIC ABS, DBLE, DIMAG, MAX, SQRT
270 * .. Statement Functions ..
271 DOUBLE PRECISION ABS1
273 * .. Statement Function definitions ..
274 ABS1( X ) = ABS( DBLE( X ) ) + ABS( DIMAG( X ) )
276 * .. Executable Statements ..
278 * Decode the input arguments
280 IF( LSAME( JOBVL, 'N' ) ) THEN
283 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
291 IF( LSAME( JOBVR, 'N' ) ) THEN
294 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
303 * Test the input arguments
306 LQUERY = ( LWORK.EQ.-1 )
307 IF( IJOBVL.LE.0 ) THEN
309 ELSE IF( IJOBVR.LE.0 ) THEN
311 ELSE IF( N.LT.0 ) THEN
313 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
315 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
317 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
319 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
321 ELSE IF( LWORK.LT.MAX( 1, 2*N ) .AND. .NOT.LQUERY ) THEN
328 CALL ZGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR )
329 LWKOPT = MAX( 1, N+INT( WORK( 1 ) ) )
330 CALL ZUNMQR( 'L', 'C', N, N, N, B, LDB, WORK, A, LDA, WORK,
332 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
334 CALL ZUNGQR( N, N, N, VL, LDVL, WORK, WORK, -1, IERR )
335 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
338 CALL ZGGHD3( JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB, VL,
339 $ LDVL, VR, LDVR, WORK, -1, IERR )
340 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
341 CALL ZHGEQZ( 'S', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
342 $ ALPHA, BETA, VL, LDVL, VR, LDVR, WORK, -1,
344 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
346 CALL ZGGHD3( JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB, VL,
347 $ LDVL, VR, LDVR, WORK, -1, IERR )
348 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
349 CALL ZHGEQZ( 'E', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
350 $ ALPHA, BETA, VL, LDVL, VR, LDVR, WORK, -1,
352 LWKOPT = MAX( LWKOPT, N+INT( WORK( 1 ) ) )
354 WORK( 1 ) = DCMPLX( LWKOPT )
358 CALL XERBLA( 'ZGGEV3 ', -INFO )
360 ELSE IF( LQUERY ) THEN
364 * Quick return if possible
369 * Get machine constants
371 EPS = DLAMCH( 'E' )*DLAMCH( 'B' )
372 SMLNUM = DLAMCH( 'S' )
373 BIGNUM = ONE / SMLNUM
374 CALL DLABAD( SMLNUM, BIGNUM )
375 SMLNUM = SQRT( SMLNUM ) / EPS
376 BIGNUM = ONE / SMLNUM
378 * Scale A if max element outside range [SMLNUM,BIGNUM]
380 ANRM = ZLANGE( 'M', N, N, A, LDA, RWORK )
382 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
385 ELSE IF( ANRM.GT.BIGNUM ) THEN
390 $ CALL ZLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
392 * Scale B if max element outside range [SMLNUM,BIGNUM]
394 BNRM = ZLANGE( 'M', N, N, B, LDB, RWORK )
396 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
399 ELSE IF( BNRM.GT.BIGNUM ) THEN
404 $ CALL ZLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
406 * Permute the matrices A, B to isolate eigenvalues if possible
411 CALL ZGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
412 $ RWORK( IRIGHT ), RWORK( IRWRK ), IERR )
414 * Reduce B to triangular form (QR decomposition of B)
416 IROWS = IHI + 1 - ILO
424 CALL ZGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
425 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
427 * Apply the orthogonal transformation to matrix A
429 CALL ZUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
430 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
431 $ LWORK+1-IWRK, IERR )
436 CALL ZLASET( 'Full', N, N, CZERO, CONE, VL, LDVL )
437 IF( IROWS.GT.1 ) THEN
438 CALL ZLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
439 $ VL( ILO+1, ILO ), LDVL )
441 CALL ZUNGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
442 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
448 $ CALL ZLASET( 'Full', N, N, CZERO, CONE, VR, LDVR )
450 * Reduce to generalized Hessenberg form
454 * Eigenvectors requested -- work on whole matrix.
456 CALL ZGGHD3( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
457 $ LDVL, VR, LDVR, WORK( IWRK ), LWORK+1-IWRK, IERR )
459 CALL ZGGHD3( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
460 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR,
461 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
464 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
465 * Schur form and Schur vectors)
473 CALL ZHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
474 $ ALPHA, BETA, VL, LDVL, VR, LDVR, WORK( IWRK ),
475 $ LWORK+1-IWRK, RWORK( IRWRK ), IERR )
477 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
479 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
487 * Compute Eigenvectors
500 CALL ZTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
501 $ VR, LDVR, N, IN, WORK( IWRK ), RWORK( IRWRK ),
508 * Undo balancing on VL and VR and normalization
511 CALL ZGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
512 $ RWORK( IRIGHT ), N, VL, LDVL, IERR )
516 TEMP = MAX( TEMP, ABS1( VL( JR, JC ) ) )
522 VL( JR, JC ) = VL( JR, JC )*TEMP
527 CALL ZGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
528 $ RWORK( IRIGHT ), N, VR, LDVR, IERR )
532 TEMP = MAX( TEMP, ABS1( VR( JR, JC ) ) )
538 VR( JR, JC ) = VR( JR, JC )*TEMP
544 * Undo scaling if necessary
549 $ CALL ZLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHA, N, IERR )
552 $ CALL ZLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
554 WORK( 1 ) = DCMPLX( LWKOPT )