1 *> \brief <b> SGGEV3 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 SGGEV3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggev3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggev3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggev3.f">
21 * SUBROUTINE SGGEV3( 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 * REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
31 * $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
32 * $ VR( LDVR, * ), WORK( * )
41 *> SGGEV3 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 REAL 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 REAL 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 REAL array, dimension (N)
119 *> \param[out] ALPHAI
121 *> ALPHAI is REAL array, dimension (N)
126 *> BETA is REAL 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 REAL 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 REAL 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 REAL 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 SHGEQZ.
209 *> =N+2: error return from STGEVC.
215 *> \author Univ. of Tennessee
216 *> \author Univ. of California Berkeley
217 *> \author Univ. of Colorado Denver
220 *> \date January 2015
222 *> \ingroup realGEeigen
224 * =====================================================================
225 SUBROUTINE SGGEV3( 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 REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ),
240 $ B( LDB, * ), BETA( * ), VL( LDVL, * ),
241 $ VR( LDVR, * ), WORK( * )
244 * =====================================================================
248 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+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 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS,
261 * .. External Subroutines ..
262 EXTERNAL SGEQRF, SGGBAK, SGGBAL, SGGHD3, SHGEQZ, SLABAD,
263 $ SLACPY, SLASCL, SLASET, SORGQR, SORMQR, STGEVC,
266 * .. External Functions ..
269 EXTERNAL LSAME, SLAMCH, SLANGE
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 SGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR )
327 LWKOPT = MAX( 1, 8*N, 3*N+INT ( WORK( 1 ) ) )
328 CALL SORMQR( 'L', 'T', N, N, N, B, LDB, WORK, A, LDA, WORK,
330 LWKOPT = MAX( LWKOPT, 3*N+INT ( WORK( 1 ) ) )
331 CALL SGGHD3( JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB, VL, LDVL,
332 $ VR, LDVR, WORK, -1, IERR )
333 LWKOPT = MAX( LWKOPT, 3*N+INT ( WORK( 1 ) ) )
335 CALL SORGQR( N, N, N, VL, LDVL, WORK, WORK, -1, IERR )
336 LWKOPT = MAX( LWKOPT, 3*N+INT ( WORK( 1 ) ) )
337 CALL SHGEQZ( 'S', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
338 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
340 LWKOPT = MAX( LWKOPT, 2*N+INT ( WORK( 1 ) ) )
342 CALL SHGEQZ( 'E', JOBVL, JOBVR, N, 1, N, A, LDA, B, LDB,
343 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
345 LWKOPT = MAX( LWKOPT, 2*N+INT ( WORK( 1 ) ) )
347 WORK( 1 ) = REAL( LWKOPT )
352 CALL XERBLA( 'SGGEV3 ', -INFO )
354 ELSE IF( LQUERY ) THEN
358 * Quick return if possible
363 * Get machine constants
366 SMLNUM = SLAMCH( 'S' )
367 BIGNUM = ONE / SMLNUM
368 CALL SLABAD( SMLNUM, BIGNUM )
369 SMLNUM = SQRT( SMLNUM ) / EPS
370 BIGNUM = ONE / SMLNUM
372 * Scale A if max element outside range [SMLNUM,BIGNUM]
374 ANRM = SLANGE( 'M', N, N, A, LDA, WORK )
376 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
379 ELSE IF( ANRM.GT.BIGNUM ) THEN
384 $ CALL SLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
386 * Scale B if max element outside range [SMLNUM,BIGNUM]
388 BNRM = SLANGE( 'M', N, N, B, LDB, WORK )
390 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
393 ELSE IF( BNRM.GT.BIGNUM ) THEN
398 $ CALL SLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
400 * Permute the matrices A, B to isolate eigenvalues if possible
405 CALL SGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, WORK( ILEFT ),
406 $ WORK( IRIGHT ), WORK( IWRK ), IERR )
408 * Reduce B to triangular form (QR decomposition of B)
410 IROWS = IHI + 1 - ILO
418 CALL SGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
419 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
421 * Apply the orthogonal transformation to matrix A
423 CALL SORMQR( 'L', 'T', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
424 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
425 $ LWORK+1-IWRK, IERR )
430 CALL SLASET( 'Full', N, N, ZERO, ONE, VL, LDVL )
431 IF( IROWS.GT.1 ) THEN
432 CALL SLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
433 $ VL( ILO+1, ILO ), LDVL )
435 CALL SORGQR( IROWS, IROWS, IROWS, VL( ILO, ILO ), LDVL,
436 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
442 $ CALL SLASET( 'Full', N, N, ZERO, ONE, VR, LDVR )
444 * Reduce to generalized Hessenberg form
448 * Eigenvectors requested -- work on whole matrix.
450 CALL SGGHD3( JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB, VL,
451 $ LDVL, VR, LDVR, WORK( IWRK ), LWORK+1-IWRK, IERR )
453 CALL SGGHD3( 'N', 'N', IROWS, 1, IROWS, A( ILO, ILO ), LDA,
454 $ B( ILO, ILO ), LDB, VL, LDVL, VR, LDVR,
455 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
458 * Perform QZ algorithm (Compute eigenvalues, and optionally, the
459 * Schur forms and Schur vectors)
467 CALL SHGEQZ( CHTEMP, JOBVL, JOBVR, N, ILO, IHI, A, LDA, B, LDB,
468 $ ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR,
469 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
471 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
473 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
481 * Compute Eigenvectors
493 CALL STGEVC( CHTEMP, 'B', LDUMMA, N, A, LDA, B, LDB, VL, LDVL,
494 $ VR, LDVR, N, IN, WORK( IWRK ), IERR )
500 * Undo balancing on VL and VR and normalization
503 CALL SGGBAK( 'P', 'L', N, ILO, IHI, WORK( ILEFT ),
504 $ WORK( IRIGHT ), N, VL, LDVL, IERR )
506 IF( ALPHAI( JC ).LT.ZERO )
509 IF( ALPHAI( JC ).EQ.ZERO ) THEN
511 TEMP = MAX( TEMP, ABS( VL( JR, JC ) ) )
515 TEMP = MAX( TEMP, ABS( VL( JR, JC ) )+
516 $ ABS( VL( JR, JC+1 ) ) )
522 IF( ALPHAI( JC ).EQ.ZERO ) THEN
524 VL( JR, JC ) = VL( JR, JC )*TEMP
528 VL( JR, JC ) = VL( JR, JC )*TEMP
529 VL( JR, JC+1 ) = VL( JR, JC+1 )*TEMP
535 CALL SGGBAK( 'P', 'R', N, ILO, IHI, WORK( ILEFT ),
536 $ WORK( IRIGHT ), N, VR, LDVR, IERR )
538 IF( ALPHAI( JC ).LT.ZERO )
541 IF( ALPHAI( JC ).EQ.ZERO ) THEN
543 TEMP = MAX( TEMP, ABS( VR( JR, JC ) ) )
547 TEMP = MAX( TEMP, ABS( VR( JR, JC ) )+
548 $ ABS( VR( JR, JC+1 ) ) )
554 IF( ALPHAI( JC ).EQ.ZERO ) THEN
556 VR( JR, JC ) = VR( JR, JC )*TEMP
560 VR( JR, JC ) = VR( JR, JC )*TEMP
561 VR( JR, JC+1 ) = VR( JR, JC+1 )*TEMP
567 * End of eigenvector calculation
571 * Undo scaling if necessary
576 CALL SLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAR, N, IERR )
577 CALL SLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHAI, N, IERR )
581 CALL SLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
584 WORK( 1 ) = REAL( LWKOPT )