1 *> \brief <b> CGGES computes the eigenvalues, the Schur form, and, optionally, the matrix of Schur vectors for GE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGGES + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgges.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgges.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgges.f">
21 * SUBROUTINE CGGES( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, LDB,
22 * SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, WORK,
23 * 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 *> CGGES 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 CGGES. 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. LWORK >= max(1,2*N).
219 *> For good performance, LWORK must generally be larger.
221 *> If LWORK = -1, then a workspace query is assumed; the routine
222 *> only calculates the optimal size of the WORK array, returns
223 *> this value as the first entry of the WORK array, and no error
224 *> message related to LWORK is issued by XERBLA.
229 *> RWORK is REAL array, dimension (8*N)
234 *> BWORK is LOGICAL array, dimension (N)
235 *> Not referenced if SORT = 'N'.
241 *> = 0: successful exit
242 *> < 0: if INFO = -i, the i-th argument had an illegal value.
244 *> The QZ iteration failed. (A,B) are not in Schur
245 *> form, but ALPHA(j) and BETA(j) should be correct for
247 *> > N: =N+1: other than QZ iteration failed in CHGEQZ
248 *> =N+2: after reordering, roundoff changed values of
249 *> some complex eigenvalues so that leading
250 *> eigenvalues in the Generalized Schur form no
251 *> longer satisfy SELCTG=.TRUE. This could also
252 *> be caused due to scaling.
253 *> =N+3: reordering failed in CTGSEN.
259 *> \author Univ. of Tennessee
260 *> \author Univ. of California Berkeley
261 *> \author Univ. of Colorado Denver
264 *> \date November 2015
266 *> \ingroup complexGEeigen
268 * =====================================================================
269 SUBROUTINE CGGES( JOBVSL, JOBVSR, SORT, SELCTG, N, A, LDA, B, LDB,
270 $ SDIM, ALPHA, BETA, VSL, LDVSL, VSR, LDVSR, WORK,
271 $ LWORK, RWORK, BWORK, INFO )
273 * -- LAPACK driver routine (version 3.6.0) --
274 * -- LAPACK is a software package provided by Univ. of Tennessee, --
275 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
278 * .. Scalar Arguments ..
279 CHARACTER JOBVSL, JOBVSR, SORT
280 INTEGER INFO, LDA, LDB, LDVSL, LDVSR, LWORK, N, SDIM
282 * .. Array Arguments ..
285 COMPLEX A( LDA, * ), ALPHA( * ), B( LDB, * ),
286 $ BETA( * ), VSL( LDVSL, * ), VSR( LDVSR, * ),
289 * .. Function Arguments ..
294 * =====================================================================
298 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
300 PARAMETER ( CZERO = ( 0.0E0, 0.0E0 ),
301 $ CONE = ( 1.0E0, 0.0E0 ) )
303 * .. Local Scalars ..
304 LOGICAL CURSL, ILASCL, ILBSCL, ILVSL, ILVSR, LASTSL,
306 INTEGER I, ICOLS, IERR, IHI, IJOBVL, IJOBVR, ILEFT,
307 $ ILO, IRIGHT, IROWS, IRWRK, ITAU, IWRK, LWKMIN,
309 REAL ANRM, ANRMTO, BIGNUM, BNRM, BNRMTO, EPS, PVSL,
316 * .. External Subroutines ..
317 EXTERNAL CGEQRF, CGGBAK, CGGBAL, CGGHRD, CHGEQZ, CLACPY,
318 $ CLASCL, CLASET, CTGSEN, CUNGQR, CUNMQR, SLABAD,
321 * .. External Functions ..
325 EXTERNAL LSAME, ILAENV, CLANGE, SLAMCH
327 * .. Intrinsic Functions ..
330 * .. Executable Statements ..
332 * Decode the input arguments
334 IF( LSAME( JOBVSL, 'N' ) ) THEN
337 ELSE IF( LSAME( JOBVSL, 'V' ) ) THEN
345 IF( LSAME( JOBVSR, 'N' ) ) THEN
348 ELSE IF( LSAME( JOBVSR, 'V' ) ) THEN
356 WANTST = LSAME( SORT, 'S' )
358 * Test the input arguments
361 LQUERY = ( LWORK.EQ.-1 )
362 IF( IJOBVL.LE.0 ) THEN
364 ELSE IF( IJOBVR.LE.0 ) THEN
366 ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
368 ELSE IF( N.LT.0 ) THEN
370 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
372 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
374 ELSE IF( LDVSL.LT.1 .OR. ( ILVSL .AND. LDVSL.LT.N ) ) THEN
376 ELSE IF( LDVSR.LT.1 .OR. ( ILVSR .AND. LDVSR.LT.N ) ) THEN
381 * (Note: Comments in the code beginning "Workspace:" describe the
382 * minimal amount of workspace needed at that point in the code,
383 * as well as the preferred amount for good performance.
384 * NB refers to the optimal block size for the immediately
385 * following subroutine, as returned by ILAENV.)
388 LWKMIN = MAX( 1, 2*N )
389 LWKOPT = MAX( 1, N + N*ILAENV( 1, 'CGEQRF', ' ', N, 1, N, 0 ) )
390 LWKOPT = MAX( LWKOPT, N +
391 $ N*ILAENV( 1, 'CUNMQR', ' ', N, 1, N, -1 ) )
393 LWKOPT = MAX( LWKOPT, N +
394 $ N*ILAENV( 1, 'CUNGQR', ' ', N, 1, N, -1 ) )
398 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY )
403 CALL XERBLA( 'CGGES ', -INFO )
405 ELSE IF( LQUERY ) THEN
409 * Quick return if possible
416 * Get machine constants
419 SMLNUM = SLAMCH( 'S' )
420 BIGNUM = ONE / SMLNUM
421 CALL SLABAD( SMLNUM, BIGNUM )
422 SMLNUM = SQRT( SMLNUM ) / EPS
423 BIGNUM = ONE / SMLNUM
425 * Scale A if max element outside range [SMLNUM,BIGNUM]
427 ANRM = CLANGE( 'M', N, N, A, LDA, RWORK )
429 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
432 ELSE IF( ANRM.GT.BIGNUM ) THEN
438 $ CALL CLASCL( 'G', 0, 0, ANRM, ANRMTO, N, N, A, LDA, IERR )
440 * Scale B if max element outside range [SMLNUM,BIGNUM]
442 BNRM = CLANGE( 'M', N, N, B, LDB, RWORK )
444 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
447 ELSE IF( BNRM.GT.BIGNUM ) THEN
453 $ CALL CLASCL( 'G', 0, 0, BNRM, BNRMTO, N, N, B, LDB, IERR )
455 * Permute the matrix to make it more nearly triangular
456 * (Real Workspace: need 6*N)
461 CALL CGGBAL( 'P', N, A, LDA, B, LDB, ILO, IHI, RWORK( ILEFT ),
462 $ RWORK( IRIGHT ), RWORK( IRWRK ), IERR )
464 * Reduce B to triangular form (QR decomposition of B)
465 * (Complex Workspace: need N, prefer N*NB)
467 IROWS = IHI + 1 - ILO
471 CALL CGEQRF( IROWS, ICOLS, B( ILO, ILO ), LDB, WORK( ITAU ),
472 $ WORK( IWRK ), LWORK+1-IWRK, IERR )
474 * Apply the orthogonal transformation to matrix A
475 * (Complex Workspace: need N, prefer N*NB)
477 CALL CUNMQR( 'L', 'C', IROWS, ICOLS, IROWS, B( ILO, ILO ), LDB,
478 $ WORK( ITAU ), A( ILO, ILO ), LDA, WORK( IWRK ),
479 $ LWORK+1-IWRK, IERR )
482 * (Complex Workspace: need N, prefer N*NB)
485 CALL CLASET( 'Full', N, N, CZERO, CONE, VSL, LDVSL )
486 IF( IROWS.GT.1 ) THEN
487 CALL CLACPY( 'L', IROWS-1, IROWS-1, B( ILO+1, ILO ), LDB,
488 $ VSL( ILO+1, ILO ), LDVSL )
490 CALL CUNGQR( IROWS, IROWS, IROWS, VSL( ILO, ILO ), LDVSL,
491 $ WORK( ITAU ), WORK( IWRK ), LWORK+1-IWRK, IERR )
497 $ CALL CLASET( 'Full', N, N, CZERO, CONE, VSR, LDVSR )
499 * Reduce to generalized Hessenberg form
500 * (Workspace: none needed)
502 CALL CGGHRD( JOBVSL, JOBVSR, N, ILO, IHI, A, LDA, B, LDB, VSL,
503 $ LDVSL, VSR, LDVSR, IERR )
507 * Perform QZ algorithm, computing Schur vectors if desired
508 * (Complex Workspace: need N)
509 * (Real Workspace: need N)
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
527 * (Workspace: none needed)
531 * Undo scaling on eigenvalues before selecting
534 $ CALL CLASCL( 'G', 0, 0, ANRM, ANRMTO, N, 1, ALPHA, N, IERR )
536 $ CALL CLASCL( 'G', 0, 0, BNRM, BNRMTO, N, 1, BETA, N, IERR )
541 BWORK( I ) = SELCTG( ALPHA( I ), BETA( I ) )
544 CALL CTGSEN( 0, ILVSL, ILVSR, BWORK, N, A, LDA, B, LDB, ALPHA,
545 $ BETA, VSL, LDVSL, VSR, LDVSR, SDIM, PVSL, PVSR,
546 $ DIF, WORK( IWRK ), LWORK-IWRK+1, IDUM, 1, IERR )
552 * Apply back-permutation to VSL and VSR
553 * (Workspace: none needed)
556 $ CALL CGGBAK( 'P', 'L', N, ILO, IHI, RWORK( ILEFT ),
557 $ RWORK( IRIGHT ), N, VSL, LDVSL, IERR )
559 $ CALL CGGBAK( 'P', 'R', N, ILO, IHI, RWORK( ILEFT ),
560 $ RWORK( IRIGHT ), N, VSR, LDVSR, IERR )
565 CALL CLASCL( 'U', 0, 0, ANRMTO, ANRM, N, N, A, LDA, IERR )
566 CALL CLASCL( 'G', 0, 0, ANRMTO, ANRM, N, 1, ALPHA, N, IERR )
570 CALL CLASCL( 'U', 0, 0, BNRMTO, BNRM, N, N, B, LDB, IERR )
571 CALL CLASCL( 'G', 0, 0, BNRMTO, BNRM, N, 1, BETA, N, IERR )
576 * Check if reordering is correct
581 CURSL = SELCTG( ALPHA( I ), BETA( I ) )
584 IF( CURSL .AND. .NOT.LASTSL )