1 *> \brief <b> CGGES3 computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE matrices (blocked algorithm)</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGGES3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgges3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgges3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgges3.f">
21 * SUBROUTINE CGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B,
22 * $ LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR,
23 * $ WORK, LWORK, RWORK, BWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBVSL, JOBVSR, SORT
27 * INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
29 * .. Array Arguments ..
32 * COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
33 * $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ),
36 * .. Function Arguments ..
47 *> CGGES3 computes for a pair of N-by-N complex nonsymmetric matrices
48 *> (A,B), the generalized eigenvalues, the generalized complex Schur
49 *> form (S, T), and optionally left and/or right Schur vectors (VSL
50 *> and VSR). This gives the generalized Schur factorization
52 *> (A,B) = ( (VSL)*S*(VSR)**H, (VSL)*T*(VSR)**H )
54 *> where (VSR)**H is the conjugate-transpose of VSR.
56 *> Optionally, it also orders the eigenvalues so that a selected cluster
57 *> of eigenvalues appears in the leading diagonal blocks of the upper
58 *> triangular matrix S and the upper triangular matrix T. The leading
59 *> columns of VSL and VSR then form an unitary basis for the
60 *> corresponding left and right eigenspaces (deflating subspaces).
62 *> (If only the generalized eigenvalues are needed, use the driver
63 *> CGGEV instead, which is faster.)
65 *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar w
66 *> or a ratio alpha/beta = w, such that A - w*B is singular. It is
67 *> usually represented as the pair (alpha,beta), as there is a
68 *> reasonable interpretation for beta=0, and even for both being zero.
70 *> A pair of matrices (S,T) is in generalized complex Schur form if S
71 *> and T are upper triangular and, in addition, the diagonal elements
72 *> of T are non-negative real numbers.
80 *> JOBVSL is CHARACTER*1
81 *> = 'N': do not compute the left Schur vectors;
82 *> = 'V': compute the left Schur vectors.
87 *> JOBVSR is CHARACTER*1
88 *> = 'N': do not compute the right Schur vectors;
89 *> = 'V': compute the right Schur vectors.
94 *> SORT is CHARACTER*1
95 *> Specifies whether or not to order the eigenvalues on the
96 *> diagonal of the generalized Schur form.
97 *> = 'N': Eigenvalues are not ordered;
98 *> = 'S': Eigenvalues are ordered (see SELCTG).
103 *> SELCTG is a LOGICAL FUNCTION of two COMPLEX arguments
104 *> SELCTG must be declared EXTERNAL in the calling subroutine.
105 *> If SORT = 'N', SELCTG is not referenced.
106 *> If SORT = 'S', SELCTG is used to select eigenvalues to sort
107 *> to the top left of the Schur form.
108 *> An eigenvalue ALPHA(j)/BETA(j) is selected if
109 *> SELCTG(ALPHA(j),BETA(j)) is true.
111 *> Note that a selected complex eigenvalue may no longer satisfy
112 *> SELCTG(ALPHA(j),BETA(j)) = .TRUE. after ordering, since
113 *> ordering may change the value of complex eigenvalues
114 *> (especially if the eigenvalue is ill-conditioned), in this
115 *> case INFO is set to N+2 (See INFO below).
121 *> The order of the matrices A, B, VSL, and VSR. N >= 0.
126 *> A is COMPLEX array, dimension (LDA, N)
127 *> On entry, the first of the pair of matrices.
128 *> On exit, A has been overwritten by its generalized Schur
135 *> The leading dimension of A. LDA >= max(1,N).
140 *> B is COMPLEX array, dimension (LDB, N)
141 *> On entry, the second of the pair of matrices.
142 *> On exit, B has been overwritten by its generalized Schur
149 *> The leading dimension of B. LDB >= max(1,N).
155 *> If SORT = 'N', SDIM = 0.
156 *> If SORT = 'S', SDIM = number of eigenvalues (after sorting)
157 *> for which SELCTG is true.
162 *> ALPHA is COMPLEX array, dimension (N)
167 *> BETA is COMPLEX array, dimension (N)
168 *> On exit, ALPHA(j)/BETA(j), j=1,...,N, will be the
169 *> generalized eigenvalues. ALPHA(j), j=1,...,N and BETA(j),
170 *> j=1,...,N are the diagonals of the complex Schur form (A,B)
171 *> output by CGGES3. The BETA(j) will be non-negative real.
173 *> Note: the quotients ALPHA(j)/BETA(j) may easily over- or
174 *> underflow, and BETA(j) may even be zero. Thus, the user
175 *> should avoid naively computing the ratio alpha/beta.
176 *> However, ALPHA will be always less than and usually
177 *> comparable with norm(A) in magnitude, and BETA always less
178 *> than and usually comparable with norm(B).
183 *> VSL is COMPLEX array, dimension (LDVSL,N)
184 *> If JOBVSL = 'V', VSL will contain the left Schur vectors.
185 *> Not referenced if JOBVSL = 'N'.
191 *> The leading dimension of the matrix VSL. LDVSL >= 1, and
192 *> if JOBVSL = 'V', LDVSL >= N.
197 *> VSR is COMPLEX array, dimension (LDVSR,N)
198 *> If JOBVSR = 'V', VSR will contain the right Schur vectors.
199 *> Not referenced if JOBVSR = 'N'.
205 *> The leading dimension of the matrix VSR. LDVSR >= 1, and
206 *> if JOBVSR = 'V', LDVSR >= N.
211 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
212 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
218 *> The dimension of the array WORK.
220 *> If LWORK = -1, then a workspace query is assumed; the routine
221 *> only calculates the optimal size of the WORK array, returns
222 *> this value as the first entry of the WORK array, and no error
223 *> message related to LWORK is issued by XERBLA.
228 *> RWORK is REAL array, dimension (8*N)
233 *> BWORK is LOGICAL array, dimension (N)
234 *> Not referenced if SORT = 'N'.
240 *> = 0: successful exit
241 *> < 0: if INFO = -i, the i-th argument had an illegal value.
243 *> The QZ iteration failed. (A,B) are not in Schur
244 *> form, but ALPHA(j) and BETA(j) should be correct for
246 *> > N: =N+1: other than QZ iteration failed in CHGEQZ
247 *> =N+2: after reordering, roundoff changed values of
248 *> some complex eigenvalues so that leading
249 *> eigenvalues in the Generalized Schur form no
250 *> longer satisfy SELCTG=.TRUE. This could also
251 *> be caused due to scaling.
252 *> =N+3: reordering failed in CTGSEN.
258 *> \author Univ. of Tennessee
259 *> \author Univ. of California Berkeley
260 *> \author Univ. of Colorado Denver
263 *> \date January 2015
265 *> \ingroup complexGEeigen
267 * =====================================================================
268 SUBROUTINE CGGES3( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B,
269 $ LDB, SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR,
270 $ WORK, LWORK, RWORK, BWORK, INFO )
272 * -- LAPACK driver routine (version 3.6.1) --
273 * -- LAPACK is a software package provided by Univ. of Tennessee, --
274 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
277 * .. Scalar Arguments ..
278 CHARACTER JOBVSL, JOBVSR, SORT
279 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
281 * .. Array Arguments ..
284 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
285 $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ),
288 * .. Function Arguments ..
293 * =====================================================================
297 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
299 PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
300 $ CONE = ( 1.0E0, 0.0E0 ) )
302 * .. Local Scalars ..
303 LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL,
305 INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT,
306 $ ILO, IRIGHT, IROWS, IRWRK, ITAU, IWRK, LWKOPT
307 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL,
314 * .. External Subroutines ..
315 EXTERNAL CGEQRF, CGGBAK, CGGBAL, CGGHD3, CHGEQZ, CLACPY,
316 $ CLASCL, CLASET, CTGSEN, CUNGQR, CUNMQR, SLABAD,
319 * .. External Functions ..
322 EXTERNAL LSAME, CLANGE, SLAMCH
324 * .. Intrinsic Functions ..
327 * .. Executable Statements ..
329 * Decode the input arguments
331 IF( LSAME( JOBVSL, 'N' ) ) THEN
334 ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN
342 IF( LSAME( JOBVSR, 'N' ) ) THEN
345 ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN
353 WANTST = LSAME( SORT, 'S' )
355 * Test the input arguments
358 LQUERY = ( LWORK.EQ.-1 )
359 IF( IJOBVL.LE.0 ) THEN
361 ELSE IF( IJOBVR.LE.0 ) THEN
363 ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
365 ELSE IF( N.LT.0 ) THEN
367 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
369 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
371 ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN
373 ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN
375 ELSE IF( LWORK.LT.MAX( 1, 2*N ) .AND. .NOT.LQUERY ) THEN
382 CALL CGEQRF( N, N, B, LDB, WORK, WORK, -1, IERR )
383 LWKOPT = MAX( 1, N + INT ( WORK( 1 ) ) )
384 CALL CUNMQR( 'L', 'C', N, N, N, B, LDB, WORK, A, LDA, WORK,
386 LWKOPT = MAX( LWKOPT, N + INT ( WORK( 1 ) ) )
388 CALL CUNGQR( N, N, N, VSL, LDVSL, WORK, WORK, -1,
390 LWKOPT = MAX( LWKOPT, N + INT ( WORK( 1 ) ) )
392 CALL CGGHD3( JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB, VSL,
393 $ LDVSL, VSR, LDVSR, WORK, -1, IERR )
394 LWKOPT = MAX( LWKOPT, N + INT ( WORK( 1 ) ) )
395 CALL CHGEQZ( 'S', JOBVSL, JOBVSR, N, 1, N, A, LDA, B, LDB,
396 $ ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, WORK, -1,
398 LWKOPT = MAX( LWKOPT, INT ( WORK( 1 ) ) )
400 CALL CTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB,
401 $ ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, SDIM,
402 $ PVSL, PVSR, DIF, WORK, -1, IDUM, 1, IERR )
403 LWKOPT = MAX( LWKOPT, INT ( WORK( 1 ) ) )
405 WORK( 1 ) = CMPLX( LWKOPT )
410 CALL XERBLA( 'CGGES3 ', -INFO )
412 ELSE IF( LQUERY ) THEN
416 * Quick return if possible
423 * Get machine constants
426 SMLNUM = SLAMCH( 'S' )
427 BIGNUM = ONE / SMLNUM
428 CALL SLABAD( SMLNUM, BIGNUM )
429 SMLNUM = SQRT( SMLNUM ) / EPS
430 BIGNUM = ONE / SMLNUM
432 * Scale A if max element outside range [SMLNUM,BIGNUM]
434 ANRM = CLANGE( 'M', N, N, A, LDA, RWORK )
436 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
439 ELSE IF( ANRM.GT.BIGNUM ) THEN
445 $ CALL CLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
447 * Scale B if max element outside range [SMLNUM,BIGNUM]
449 BNRM = CLANGE( 'M', N, N, B, LDB, RWORK )
451 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
454 ELSE IF( BNRM.GT.BIGNUM ) THEN
460 $ CALL CLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
462 * Permute the matrix to make it more nearly triangular
467 CALL CGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
468 $ RWORK( IRIGHT ), RWORK( IRWRK ), IERR )
470 * Reduce B to triangular form (QR decomposition of B)
472 IROWS = IHI + 1 - ILO
476 CALL CGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
477 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
479 * Apply the orthogonal transformation to matrix A
481 CALL CUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
482 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
483 $ LWORK+1-IWRK, IERR )
488 CALL CLASET( 'Full', N, N, CZERO, CONE, VSL, LDVSL )
489 IF( IROWS.GT.1 ) THEN
490 CALL CLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
491 $ VSL( ILO+1, ILO ), LDVSL )
493 CALL CUNGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL,
494 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
500 $ CALL CLASET( 'Full', N, N, CZERO, CONE, VSR, LDVSR )
502 * Reduce to generalized Hessenberg form
504 CALL CGGHD3( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL,
505 $ LDVSL, VSR, LDVSR, WORK( IWRK ), LWORK+1-IWRK, IERR )
509 * Perform QZ algorithm, computing Schur vectors if desired
512 CALL CHGEQZ( 'S', JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB,
513 $ ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, WORK( IWRK ),
514 $ LWORK+1-IWRK, RWORK( IRWRK ), IERR )
516 IF( IERR.GT.0 .AND. IERR.LE.N ) THEN
518 ELSE IF( IERR.GT.N .AND. IERR.LE.2*N ) THEN
526 * Sort eigenvalues ALPHA/BETA if desired
530 * Undo scaling on eigenvalues before selecting
533 $ CALL CLASCL( 'G', 0, 0, ANRM, ANRMTO, N, 1, ALPHA, N, IERR )
535 $ CALL CLASCL( 'G', 0, 0, BNRM, BNRMTO, N, 1, BETA, N, IERR )
540 BWORK( I ) = SELCTG( ALPHA( I ), BETA( I ) )
543 CALL CTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, ALPHA,
544 $ BETA, VSL, LDVSL, VSR, LDVSR, SDIM, PVSL, PVSR,
545 $ DIF, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1, IERR )
551 * Apply back-permutation to VSL and VSR
554 $ CALL CGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
555 $ RWORK( IRIGHT ), N, VSL, LDVSL, IERR )
557 $ CALL CGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
558 $ RWORK( IRIGHT ), N, VSR, LDVSR, IERR )
563 CALL CLASCL( 'U', 0, 0, ANRMTO, ANRM, N, N, A, LDA, IERR )
564 CALL CLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHA, N, IERR )
568 CALL CLASCL( 'U', 0, 0, BNRMTO, BNRM, N, N, B, LDB, IERR )
569 CALL CLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
574 * Check if reordering is correct
579 CURSL = SELCTG( ALPHA( I ), BETA( I ) )
582 IF( CURSL .AND. .NOT.LASTSL )
591 WORK( 1 ) = CMPLX( LWKOPT )