1 *> \brief <b> DGGEV3 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 DGGEV3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dggev3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dggev3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dggev3.f">
21 * SUBROUTINE DGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR,
22 * $ ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK,
25 * .. Scalar Arguments ..
26 * CHARACTER JOBVL, JOBVR
27 * INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N
29 * .. Array Arguments ..
30 * DOUBLE PRECISION A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
31 * $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
32 * $ VR( LDVR, * ), WORK( * )
41 *> DGGEV3 computes for a pair of N-by-N real nonsymmetric matrices (A,B)
42 *> the generalized eigenvalues, and optionally, the left and/or right
43 *> 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 eigenvector v(j) corresponding to the eigenvalue lambda(j)
54 *> A * v(j) = lambda(j) * B * v(j).
56 *> The left eigenvector u(j) corresponding to the eigenvalue lambda(j)
59 *> u(j)**H * A = lambda(j) * u(j)**H * B .
61 *> where u(j)**H is the conjugate-transpose of u(j).
70 *> JOBVL is CHARACTER*1
71 *> = 'N': do not compute the left generalized eigenvectors;
72 *> = 'V': compute the left generalized eigenvectors.
77 *> JOBVR is CHARACTER*1
78 *> = 'N': do not compute the right generalized eigenvectors;
79 *> = 'V': compute the right generalized eigenvectors.
85 *> The order of the matrices A, B, VL, and VR. N >= 0.
90 *> A is DOUBLE PRECISION array, dimension (LDA, N)
91 *> On entry, the matrix A in the pair (A,B).
92 *> On exit, A has been overwritten.
98 *> The leading dimension of A. LDA >= max(1,N).
103 *> B is DOUBLE PRECISION array, dimension (LDB, N)
104 *> On entry, the matrix B in the pair (A,B).
105 *> On exit, B has been overwritten.
111 *> The leading dimension of B. LDB >= max(1,N).
114 *> \param[out] ALPHAR
116 *> ALPHAR is DOUBLE PRECISION array, dimension (N)
119 *> \param[out] ALPHAI
121 *> ALPHAI is DOUBLE PRECISION array, dimension (N)
126 *> BETA is DOUBLE PRECISION array, dimension (N)
127 *> On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will
128 *> be the generalized eigenvalues. If ALPHAI(j) is zero, then
129 *> the j-th eigenvalue is real; if positive, then the j-th and
130 *> (j+1)-st eigenvalues are a complex conjugate pair, with
131 *> ALPHAI(j+1) negative.
133 *> Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j)
134 *> may easily over- or underflow, and BETA(j) may even be zero.
135 *> Thus, the user should avoid naively computing the ratio
136 *> alpha/beta. However, ALPHAR and ALPHAI will be always less
137 *> than and usually comparable with norm(A) in magnitude, and
138 *> BETA always less than and usually comparable with norm(B).
143 *> VL is DOUBLE PRECISION array, dimension (LDVL,N)
144 *> If JOBVL = 'V', the left eigenvectors u(j) are stored one
145 *> after another in the columns of VL, in the same order as
146 *> their eigenvalues. If the j-th eigenvalue is real, then
147 *> u(j) = VL(:,j), the j-th column of VL. If the j-th and
148 *> (j+1)-th eigenvalues form a complex conjugate pair, then
149 *> u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1).
150 *> Each eigenvector is scaled so the largest component has
151 *> abs(real part)+abs(imag. part)=1.
152 *> Not referenced if JOBVL = 'N'.
158 *> The leading dimension of the matrix VL. LDVL >= 1, and
159 *> if JOBVL = 'V', LDVL >= N.
164 *> VR is DOUBLE PRECISION array, dimension (LDVR,N)
165 *> If JOBVR = 'V', the right eigenvectors v(j) are stored one
166 *> after another in the columns of VR, in the same order as
167 *> their eigenvalues. If the j-th eigenvalue is real, then
168 *> v(j) = VR(:,j), the j-th column of VR. If the j-th and
169 *> (j+1)-th eigenvalues form a complex conjugate pair, then
170 *> v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1).
171 *> Each eigenvector is scaled so the largest component has
172 *> abs(real part)+abs(imag. part)=1.
173 *> Not referenced if JOBVR = 'N'.
179 *> The leading dimension of the matrix VR. LDVR >= 1, and
180 *> if JOBVR = 'V', LDVR >= N.
185 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
186 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
193 *> If LWORK = -1, then a workspace query is assumed; the routine
194 *> only calculates the optimal size of the WORK array, returns
195 *> this value as the first entry of the WORK array, and no error
196 *> message related to LWORK is issued by XERBLA.
202 *> = 0: successful exit
203 *> < 0: if INFO = -i, the i-th argument had an illegal value.
205 *> The QZ iteration failed. No eigenvectors have been
206 *> calculated, but ALPHAR(j), ALPHAI(j), and BETA(j)
207 *> should be correct for j=INFO+1,...,N.
208 *> > N: =N+1: other than QZ iteration failed in DHGEQZ.
209 *> =N+2: error return from DTGEVC.
215 *> \author Univ. of Tennessee
216 *> \author Univ. of California Berkeley
217 *> \author Univ. of Colorado Denver
220 *> \date January 2015
222 *> \ingroup doubleGEeigen
224 * =====================================================================
225 SUBROUTINE DGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR,
226 $ ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK,
229 * -- LAPACK driver routine (version 3.6.0) --
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, LWKOPT
255 DOUBLE PRECISION ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
261 * .. External Subroutines ..
262 EXTERNAL DGEQRF, DGGBAK, DGGBAL, DGGHD3, DHGEQZ, DLABAD,
263 $ DLACPY, DLASCL, DLASET, DORGQR, DORMQR, DTGEVC,
266 * .. External Functions ..
268 DOUBLE PRECISION DLAMCH, DLANGE
269 EXTERNAL LSAME, DLAMCH, DLANGE
271 * .. Intrinsic Functions ..
272 INTRINSIC ABS, MAX, SQRT
274 * .. Executable Statements ..
276 * Decode the input arguments
278 IF( LSAME( JOBVL, 'N' ) ) THEN
281 ELSE IF( LSAME( JOBVL, 'V' ) ) THEN
289 IF( LSAME( JOBVR, 'N' ) ) THEN
292 ELSE IF( LSAME( JOBVR, 'V' ) ) THEN
301 * Test the input arguments
304 LQUERY = ( LWORK.EQ.-1 )
305 IF( IJOBVL.LE.0 ) THEN
307 ELSE IF( IJOBVR.LE.0 ) THEN
309 ELSE IF( N.LT.0 ) THEN
311 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
313 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
315 ELSE IF( LDVL.LT.1 .OR. ( ILVL .AND. LDVL.LT.N ) ) THEN
317 ELSE IF( LDVR.LT.1 .OR. ( ILVR .AND. LDVR.LT.N ) ) THEN
319 ELSE IF( LWORK.LT.MAX( 1, 8*N ) .AND. .NOT.LQUERY ) THEN
326 CALL DGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR )
327 LWKOPT = MAX(1, 8*N, 3*N+INT( WORK( 1 ) ) )
328 CALL DORMQR( 'L', 'T', N, N, N, B, LDB, WORK, A, LDA, WORK, -1,
330 LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
332 CALL DORGQR( N, N, N, VL, LDVL, WORK, WORK, -1, IERR )
333 LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
336 CALL DGGHD3( JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB, VL,
337 $ LDVL, VR, LDVR, WORK, -1, IERR )
338 LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
339 CALL DHGEQZ( 'S', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
340 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
342 LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) )
344 CALL DGGHD3( 'N', 'N', N, 1, N, A, LDA, B, LDB, VL, LDVL,
345 $ VR, LDVR, WORK, -1, IERR )
346 LWKOPT = MAX( LWKOPT, 3*N+INT( WORK ( 1 ) ) )
347 CALL DHGEQZ( 'E', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
348 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
350 LWKOPT = MAX( LWKOPT, 2*N+INT( WORK ( 1 ) ) )
357 CALL XERBLA( 'DGGEV3 ', -INFO )
359 ELSE IF( LQUERY ) THEN
363 * Quick return if possible
368 * Get machine constants
371 SMLNUM = DLAMCH( 'S' )
372 BIGNUM = ONE / SMLNUM
373 CALL DLABAD( SMLNUM, BIGNUM )
374 SMLNUM = SQRT( SMLNUM ) / EPS
375 BIGNUM = ONE / SMLNUM
377 * Scale A if max element outside range [SMLNUM,BIGNUM]
379 ANRM = DLANGE( 'M', N, N, A, LDA, WORK )
381 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
384 ELSE IF( ANRM.GT.BIGNUM ) THEN
389 $ CALL DLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
391 * Scale B if max element outside range [SMLNUM,BIGNUM]
393 BNRM = DLANGE( 'M', N, N, B, LDB, WORK )
395 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
398 ELSE IF( BNRM.GT.BIGNUM ) THEN
403 $ CALL DLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
405 * Permute the matrices A, B to isolate eigenvalues if possible
410 CALL DGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
411 $ WORK( IRIGHT ), WORK( IWRK ), IERR )
413 * Reduce B to triangular form (QR decomposition of B)
415 IROWS = IHI + 1 - ILO
423 CALL DGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
424 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
426 * Apply the orthogonal transformation to matrix A
428 CALL DORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
429 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
430 $ LWORK+1-IWRK, IERR )
435 CALL DLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
436 IF( IROWS.GT.1 ) THEN
437 CALL DLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
438 $ VL( ILO+1, ILO ), LDVL )
440 CALL DORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
441 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
447 $ CALL DLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
449 * Reduce to generalized Hessenberg form
453 * Eigenvectors requested -- work on whole matrix.
455 CALL DGGHD3( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
456 $ LDVL, VR, LDVR, WORK( IWRK ), LWORK+1-IWRK, IERR )
458 CALL DGGHD3( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
459 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR,
460 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
463 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
464 * Schur forms and Schur vectors)
472 CALL DHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
473 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
474 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
476 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
478 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
486 * Compute Eigenvectors
498 CALL DTGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
499 $ VR, LDVR, N, IN, WORK( IWRK ), IERR )
505 * Undo balancing on VL and VR and normalization
508 CALL DGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
509 $ WORK( IRIGHT ), N, VL, LDVL, IERR )
511 IF( ALPHAI( JC ).LT.ZERO )
514 IF( ALPHAI( JC ).EQ.ZERO ) THEN
516 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
520 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
521 $ ABS( VL( JR, JC+1 ) ) )
527 IF( ALPHAI( JC ).EQ.ZERO ) THEN
529 VL( JR, JC ) = VL( JR, JC )*TEMP
533 VL( JR, JC ) = VL( JR, JC )*TEMP
534 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
540 CALL DGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
541 $ WORK( IRIGHT ), N, VR, LDVR, IERR )
543 IF( ALPHAI( JC ).LT.ZERO )
546 IF( ALPHAI( JC ).EQ.ZERO ) THEN
548 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
552 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
553 $ ABS( VR( JR, JC+1 ) ) )
559 IF( ALPHAI( JC ).EQ.ZERO ) THEN
561 VR( JR, JC ) = VR( JR, JC )*TEMP
565 VR( JR, JC ) = VR( JR, JC )*TEMP
566 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
572 * End of eigenvector calculation
576 * Undo scaling if necessary
581 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
582 CALL DLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
586 CALL DLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )