1 *> \brief <b> CGGEV computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGGEV + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggev.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggev.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggev.f">
21 * SUBROUTINE CGGEV( 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 ..
30 * COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
31 * $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
41 *> CGGEV 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 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 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 array, dimension (N)
120 *> BETA is COMPLEX 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 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 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 array, dimension (MAX(1,LWORK))
171 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
177 *> The dimension of the array WORK. LWORK >= max(1,2*N).
178 *> For good performance, LWORK must generally be larger.
180 *> If LWORK = -1, then a workspace query is assumed; the routine
181 *> only calculates the optimal size of the WORK array, returns
182 *> this value as the first entry of the WORK array, and no error
183 *> message related to LWORK is issued by XERBLA.
188 *> RWORK is REAL array, dimension (8*N)
194 *> = 0: successful exit
195 *> < 0: if INFO = -i, the i-th argument had an illegal value.
197 *> The QZ iteration failed. No eigenvectors have been
198 *> calculated, but ALPHA(j) and BETA(j) should be
199 *> correct for j=INFO+1,...,N.
200 *> > N: =N+1: other then QZ iteration failed in SHGEQZ,
201 *> =N+2: error return from STGEVC.
207 *> \author Univ. of Tennessee
208 *> \author Univ. of California Berkeley
209 *> \author Univ. of Colorado Denver
214 *> \ingroup complexGEeigen
216 * =====================================================================
217 SUBROUTINE CGGEV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHA, BETA,
218 $ VL, LDVL, VR, LDVR, WORK, LWORK, RWORK, INFO )
220 * -- LAPACK driver routine (version 3.4.1) --
221 * -- LAPACK is a software package provided by Univ. of Tennessee, --
222 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
225 * .. Scalar Arguments ..
226 CHARACTER JOBVL, JOBVR
227 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
229 * .. Array Arguments ..
231 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
232 $ BETA( * ), VL( LDVL, * ), VR( LDVR, * ),
236 * =====================================================================
240 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
242 PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
243 $ CONE = ( 1.0E0, 0.0E0 ) )
245 * .. Local Scalars ..
246 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
248 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
249 $ IN, IRIGHT, IROWS, IRWRK, ITAU, IWRK, JC, JR,
251 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
258 * .. External Subroutines ..
259 EXTERNAL CGEQRF, CGGBAK, CGGBAL, CGGHRD, CHGEQZ, CLACPY,
260 $ CLASCL, CLASET, CTGEVC, CUNGQR, CUNMQR, SLABAD,
263 * .. External Functions ..
267 EXTERNAL LSAME, ILAENV, CLANGE, SLAMCH
269 * .. Intrinsic Functions ..
270 INTRINSIC ABS, AIMAG, MAX, REAL, SQRT
272 * .. Statement Functions ..
275 * .. Statement Function definitions ..
276 ABS1( X ) = ABS( REAL( X ) ) + ABS( AIMAG( X ) )
278 * .. Executable Statements ..
280 * Decode the input arguments
282 IF( LSAME( JOBVL, 'N' ) ) THEN
285 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
293 IF( LSAME( JOBVR, 'N' ) ) THEN
296 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
305 * Test the input arguments
308 LQUERY = ( LWORK.EQ.-1 )
309 IF( IJOBVL.LE.0 ) THEN
311 ELSE IF( IJOBVR.LE.0 ) THEN
313 ELSE IF( N.LT.0 ) THEN
315 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
317 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
319 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
321 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
326 * (Note: Comments in the code beginning "Workspace:" describe the
327 * minimal amount of workspace needed at that point in the code,
328 * as well as the preferred amount for good performance.
329 * NB refers to the optimal block size for the immediately
330 * following subroutine, as returned by ILAENV. The workspace is
331 * computed assuming ILO = 1 and IHI = N, the worst case.)
334 LWKMIN = MAX( 1, 2*N )
335 LWKOPT = MAX( 1, N + N*ILAENV( 1, 'CGEQRF', ' ', N, 1, N, 0 ) )
336 LWKOPT = MAX( LWKOPT, N +
337 $ N*ILAENV( 1, 'CUNMQR', ' ', N, 1, N, 0 ) )
339 LWKOPT = MAX( LWKOPT, N +
340 $ N*ILAENV( 1, 'CUNGQR', ' ', N, 1, N, -1 ) )
344 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY )
349 CALL XERBLA( 'CGGEV ', -INFO )
351 ELSE IF( LQUERY ) THEN
355 * Quick return if possible
360 * Get machine constants
362 EPS = SLAMCH( 'E' )*SLAMCH( 'B' )
363 SMLNUM = SLAMCH( 'S' )
364 BIGNUM = ONE / SMLNUM
365 CALL SLABAD( SMLNUM, BIGNUM )
366 SMLNUM = SQRT( SMLNUM ) / EPS
367 BIGNUM = ONE / SMLNUM
369 * Scale A if max element outside range [SMLNUM,BIGNUM]
371 ANRM = CLANGE( 'M', N, N, A, LDA, RWORK )
373 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
376 ELSE IF( ANRM.GT.BIGNUM ) THEN
381 $ CALL CLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
383 * Scale B if max element outside range [SMLNUM,BIGNUM]
385 BNRM = CLANGE( 'M', N, N, B, LDB, RWORK )
387 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
390 ELSE IF( BNRM.GT.BIGNUM ) THEN
395 $ CALL CLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
397 * Permute the matrices A, B to isolate eigenvalues if possible
398 * (Real Workspace: need 6*N)
403 CALL CGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
404 $ RWORK( IRIGHT ), RWORK( IRWRK ), IERR )
406 * Reduce B to triangular form (QR decomposition of B)
407 * (Complex Workspace: need N, prefer N*NB)
409 IROWS = IHI + 1 - ILO
417 CALL CGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
418 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
420 * Apply the orthogonal transformation to matrix A
421 * (Complex Workspace: need N, prefer N*NB)
423 CALL CUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
424 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
425 $ LWORK+1-IWRK, IERR )
428 * (Complex Workspace: need N, prefer N*NB)
431 CALL CLASET( 'Full', N, N, CZERO, CONE, VL, LDVL )
432 IF( IROWS.GT.1 ) THEN
433 CALL CLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
434 $ VL( ILO+1, ILO ), LDVL )
436 CALL CUNGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
437 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
443 $ CALL CLASET( 'Full', N, N, CZERO, CONE, VR, LDVR )
445 * Reduce to generalized Hessenberg form
449 * Eigenvectors requested -- work on whole matrix.
451 CALL CGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
452 $ LDVL, VR, LDVR, IERR )
454 CALL CGGHRD( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
455 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR, IERR )
458 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
459 * Schur form and Schur vectors)
460 * (Complex Workspace: need N)
461 * (Real Workspace: need N)
469 CALL CHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
470 $ ALPHA, BETA, VL, LDVL, VR, LDVR, WORK( IWRK ),
471 $ LWORK+1-IWRK, RWORK( IRWRK ), IERR )
473 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
475 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
483 * Compute Eigenvectors
484 * (Real Workspace: need 2*N)
485 * (Complex Workspace: need 2*N)
498 CALL CTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
499 $ VR, LDVR, N, IN, WORK( IWRK ), RWORK( IRWRK ),
506 * Undo balancing on VL and VR and normalization
507 * (Workspace: none needed)
510 CALL CGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
511 $ RWORK( IRIGHT ), N, VL, LDVL, IERR )
515 TEMP = MAX( TEMP, ABS1( VL( JR, JC ) ) )
521 VL( JR, JC ) = VL( JR, JC )*TEMP
526 CALL CGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
527 $ RWORK( IRIGHT ), N, VR, LDVR, IERR )
531 TEMP = MAX( TEMP, ABS1( VR( JR, JC ) ) )
537 VR( JR, JC ) = VR( JR, JC )*TEMP
543 * Undo scaling if necessary
548 $ CALL CLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHA, N, IERR )
551 $ CALL CLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )