1 *> \brief <b> DGGEV 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 DGGEV + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dggev.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dggev.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dggev.f">
21 * SUBROUTINE DGGEV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI,
22 * BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO )
24 * .. Scalar Arguments ..
25 * CHARACTER JOBVL, JOBVR
26 * INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
28 * .. Array Arguments ..
29 * DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
30 * $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
31 * $ VR( LDVR, * ), WORK( * )
40 *> DGGEV computes for a pair of N-by-N real nonsymmetric matrices (A,B)
41 *> the generalized eigenvalues, and optionally, the left and/or right
42 *> generalized eigenvectors.
44 *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar
45 *> lambda or a ratio alpha/beta = lambda, such that A - lambda*B is
46 *> singular. It is usually represented as the pair (alpha,beta), as
47 *> there is a reasonable interpretation for beta=0, and even for both
50 *> The right eigenvector v(j) corresponding to the eigenvalue lambda(j)
53 *> A * v(j) = lambda(j) * B * v(j).
55 *> The left eigenvector u(j) corresponding to the eigenvalue lambda(j)
58 *> u(j)**H * A = lambda(j) * u(j)**H * B .
60 *> 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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).
113 *> \param[out] ALPHAR
115 *> ALPHAR is DOUBLE PRECISION array, dimension (N)
118 *> \param[out] ALPHAI
120 *> ALPHAI is DOUBLE PRECISION array, dimension (N)
125 *> BETA is DOUBLE PRECISION array, dimension (N)
126 *> On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
127 *> be the generalized eigenvalues. If ALPHAI(j) is zero, then
128 *> the j-th eigenvalue is real; if positive, then the j-th and
129 *> (j+1)-st eigenvalues are a complex conjugate pair, with
130 *> ALPHAI(j+1) negative.
132 *> Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
133 *> may easily over- or underflow, and BETA(j) may even be zero.
134 *> Thus, the user should avoid naively computing the ratio
135 *> alpha/beta. However, ALPHAR and ALPHAI will be always less
136 *> than and usually comparable with norm(A) in magnitude, and
137 *> BETA always less than and usually comparable with norm(B).
142 *> VL is DOUBLE PRECISION array, dimension (LDVL,N)
143 *> If JOBVL = 'V', the left eigenvectors u(j) are stored one
144 *> after another in the columns of VL, in the same order as
145 *> their eigenvalues. If the j-th eigenvalue is real, then
146 *> u(j) = VL(:,j), the j-th column of VL. If the j-th and
147 *> (j+1)-th eigenvalues form a complex conjugate pair, then
148 *> u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1).
149 *> Each eigenvector is scaled so the largest component has
150 *> abs(real part)+abs(imag. part)=1.
151 *> Not referenced if JOBVL = 'N'.
157 *> The leading dimension of the matrix VL. LDVL >= 1, and
158 *> if JOBVL = 'V', LDVL >= N.
163 *> VR is DOUBLE PRECISION array, dimension (LDVR,N)
164 *> If JOBVR = 'V', the right eigenvectors v(j) are stored one
165 *> after another in the columns of VR, in the same order as
166 *> their eigenvalues. If the j-th eigenvalue is real, then
167 *> v(j) = VR(:,j), the j-th column of VR. If the j-th and
168 *> (j+1)-th eigenvalues form a complex conjugate pair, then
169 *> v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1).
170 *> Each eigenvector is scaled so the largest component has
171 *> abs(real part)+abs(imag. part)=1.
172 *> Not referenced if JOBVR = 'N'.
178 *> The leading dimension of the matrix VR. LDVR >= 1, and
179 *> if JOBVR = 'V', LDVR >= N.
184 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
185 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
191 *> The dimension of the array WORK. LWORK >= max(1,8*N).
192 *> For good performance, LWORK must generally be larger.
194 *> If LWORK = -1, then a workspace query is assumed; the routine
195 *> only calculates the optimal size of the WORK array, returns
196 *> this value as the first entry of the WORK array, and no error
197 *> message related to LWORK is issued by XERBLA.
203 *> = 0: successful exit
204 *> < 0: if INFO = -i, the i-th argument had an illegal value.
206 *> The QZ iteration failed. No eigenvectors have been
207 *> calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
208 *> should be correct for j=INFO+1,...,N.
209 *> > N: =N+1: other than QZ iteration failed in DHGEQZ.
210 *> =N+2: error return from DTGEVC.
216 *> \author Univ. of Tennessee
217 *> \author Univ. of California Berkeley
218 *> \author Univ. of Colorado Denver
223 *> \ingroup doubleGEeigen
225 * =====================================================================
226 SUBROUTINE DGGEV( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, ALPHAI,
227 $ BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO )
229 * -- LAPACK driver routine (version 3.4.1) --
230 * -- LAPACK is a software package provided by Univ. of Tennessee, --
231 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
234 * .. Scalar Arguments ..
235 CHARACTER JOBVL, JOBVR
236 INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
238 * .. Array Arguments ..
239 DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
240 $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
241 $ VR( LDVR, * ), WORK( * )
244 * =====================================================================
247 DOUBLE PRECISION ZERO, ONE
248 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
250 * .. Local Scalars ..
251 LOGICAL ILASCL, ILBSCL, ILV, ILVL, ILVR, LQUERY
253 INTEGER ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT, ILO,
254 $ IN, IRIGHT, IROWS, ITAU, IWRK, JC, JR, MAXWRK,
256 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
262 * .. External Subroutines ..
263 EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHRD, DHGEQZ, DLABAD,
264 $ DLACPY,DLASCL, DLASET, DORGQR, DORMQR, DTGEVC,
267 * .. External Functions ..
270 DOUBLE PRECISION DLAMCH, DLANGE
271 EXTERNAL LSAME, ILAENV, DLAMCH, DLANGE
273 * .. Intrinsic Functions ..
274 INTRINSIC ABS, MAX, SQRT
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
324 * (Note: Comments in the code beginning "Workspace:" describe the
325 * minimal amount of workspace needed at that point in the code,
326 * as well as the preferred amount for good performance.
327 * NB refers to the optimal block size for the immediately
328 * following subroutine, as returned by ILAENV. The workspace is
329 * computed assuming ILO = 1 and IHI = N, the worst case.)
332 MINWRK = MAX( 1, 8*N )
333 MAXWRK = MAX( 1, N*( 7 +
334 $ ILAENV( 1, 'DGEQRF', ' ', N, 1, N, 0 ) ) )
335 MAXWRK = MAX( MAXWRK, N*( 7 +
336 $ ILAENV( 1, 'DORMQR', ' ', N, 1, N, 0 ) ) )
338 MAXWRK = MAX( MAXWRK, N*( 7 +
339 $ ILAENV( 1, 'DORGQR', ' ', N, 1, N, -1 ) ) )
343 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY )
348 CALL XERBLA( 'DGGEV ', -INFO )
350 ELSE IF( LQUERY ) THEN
354 * Quick return if possible
359 * Get machine constants
362 SMLNUM = DLAMCH( 'S' )
363 BIGNUM = ONE / SMLNUM
364 CALL DLABAD( SMLNUM, BIGNUM )
365 SMLNUM = SQRT( SMLNUM ) / EPS
366 BIGNUM = ONE / SMLNUM
368 * Scale A if max element outside range [SMLNUM,BIGNUM]
370 ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
372 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
375 ELSE IF( ANRM.GT.BIGNUM ) THEN
380 $ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
382 * Scale B if max element outside range [SMLNUM,BIGNUM]
384 BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
386 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
389 ELSE IF( BNRM.GT.BIGNUM ) THEN
394 $ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
396 * Permute the matrices A, B to isolate eigenvalues if possible
397 * (Workspace: need 6*N)
402 CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
403 $ WORK( IRIGHT ), WORK( IWRK ), IERR )
405 * Reduce B to triangular form (QR decomposition of B)
406 * (Workspace: need N, prefer N*NB)
408 IROWS = IHI + 1 - ILO
416 CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
417 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
419 * Apply the orthogonal transformation to matrix A
420 * (Workspace: need N, prefer N*NB)
422 CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
423 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
424 $ LWORK+1-IWRK, IERR )
427 * (Workspace: need N, prefer N*NB)
430 CALL DLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
431 IF( IROWS.GT.1 ) THEN
432 CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
433 $ VL( ILO+1, ILO ), LDVL )
435 CALL DORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
436 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
442 $ CALL DLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
444 * Reduce to generalized Hessenberg form
445 * (Workspace: none needed)
449 * Eigenvectors requested -- work on whole matrix.
451 CALL DGGHRD( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
452 $ LDVL, VR, LDVR, IERR )
454 CALL DGGHRD( '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 forms and Schur vectors)
460 * (Workspace: need N)
468 CALL DHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
469 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
470 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
472 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
474 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
482 * Compute Eigenvectors
483 * (Workspace: need 6*N)
495 CALL DTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
496 $ VR, LDVR, N, IN, WORK( IWRK ), IERR )
502 * Undo balancing on VL and VR and normalization
503 * (Workspace: none needed)
506 CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
507 $ WORK( IRIGHT ), N, VL, LDVL, IERR )
509 IF( ALPHAI( JC ).LT.ZERO )
512 IF( ALPHAI( JC ).EQ.ZERO ) THEN
514 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
518 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
519 $ ABS( VL( JR, JC+1 ) ) )
525 IF( ALPHAI( JC ).EQ.ZERO ) THEN
527 VL( JR, JC ) = VL( JR, JC )*TEMP
531 VL( JR, JC ) = VL( JR, JC )*TEMP
532 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
538 CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
539 $ WORK( IRIGHT ), N, VR, LDVR, IERR )
541 IF( ALPHAI( JC ).LT.ZERO )
544 IF( ALPHAI( JC ).EQ.ZERO ) THEN
546 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
550 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
551 $ ABS( VR( JR, JC+1 ) ) )
557 IF( ALPHAI( JC ).EQ.ZERO ) THEN
559 VR( JR, JC ) = VR( JR, JC )*TEMP
563 VR( JR, JC ) = VR( JR, JC )*TEMP
564 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
570 * End of eigenvector calculation
574 * Undo scaling if necessary
579 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
580 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
584 CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )