1 *> \brief <b> ZGEESX 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 ZGEESX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeesx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeesx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeesx.f">
21 * SUBROUTINE ZGEESX( JOBVS, SORT, SELECT, SENSE, N, A, LDA, SDIM, W,
22 * VS, LDVS, RCONDE, RCONDV, WORK, LWORK, RWORK,
25 * .. Scalar Arguments ..
26 * CHARACTER JOBVS, SENSE, SORT
27 * INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
28 * DOUBLE PRECISION RCONDE, RCONDV
30 * .. Array Arguments ..
32 * DOUBLE PRECISION RWORK( * )
33 * COMPLEX*16 A( LDA, * ), VS( LDVS, * ), W( * ), WORK( * )
35 * .. Function Arguments ..
46 *> ZGEESX computes for an N-by-N complex nonsymmetric matrix A, the
47 *> eigenvalues, the Schur form T, and, optionally, the matrix of Schur
48 *> vectors Z. This gives the Schur factorization A = Z*T*(Z**H).
50 *> Optionally, it also orders the eigenvalues on the diagonal of the
51 *> Schur form so that selected eigenvalues are at the top left;
52 *> computes a reciprocal condition number for the average of the
53 *> selected eigenvalues (RCONDE); and computes a reciprocal condition
54 *> number for the right invariant subspace corresponding to the
55 *> selected eigenvalues (RCONDV). The leading columns of Z form an
56 *> orthonormal basis for this invariant subspace.
58 *> For further explanation of the reciprocal condition numbers RCONDE
59 *> and RCONDV, see Section 4.10 of the LAPACK Users' Guide (where
60 *> these quantities are called s and sep respectively).
62 *> A complex matrix is in Schur form if it is upper triangular.
70 *> JOBVS is CHARACTER*1
71 *> = 'N': Schur vectors are not computed;
72 *> = 'V': Schur vectors are computed.
77 *> SORT is CHARACTER*1
78 *> Specifies whether or not to order the eigenvalues on the
79 *> diagonal of the Schur form.
80 *> = 'N': Eigenvalues are not ordered;
81 *> = 'S': Eigenvalues are ordered (see SELECT).
86 *> SELECT is a LOGICAL FUNCTION of one COMPLEX*16 argument
87 *> SELECT must be declared EXTERNAL in the calling subroutine.
88 *> If SORT = 'S', SELECT is used to select eigenvalues to order
89 *> to the top left of the Schur form.
90 *> If SORT = 'N', SELECT is not referenced.
91 *> An eigenvalue W(j) is selected if SELECT(W(j)) is true.
96 *> SENSE is CHARACTER*1
97 *> Determines which reciprocal condition numbers are computed.
98 *> = 'N': None are computed;
99 *> = 'E': Computed for average of selected eigenvalues only;
100 *> = 'V': Computed for selected right invariant subspace only;
101 *> = 'B': Computed for both.
102 *> If SENSE = 'E', 'V' or 'B', SORT must equal 'S'.
108 *> The order of the matrix A. N >= 0.
113 *> A is COMPLEX*16 array, dimension (LDA, N)
114 *> On entry, the N-by-N matrix A.
115 *> On exit, A is overwritten by its Schur form T.
121 *> The leading dimension of the array A. LDA >= max(1,N).
127 *> If SORT = 'N', SDIM = 0.
128 *> If SORT = 'S', SDIM = number of eigenvalues for which
134 *> W is COMPLEX*16 array, dimension (N)
135 *> W contains the computed eigenvalues, in the same order
136 *> that they appear on the diagonal of the output Schur form T.
141 *> VS is COMPLEX*16 array, dimension (LDVS,N)
142 *> If JOBVS = 'V', VS contains the unitary matrix Z of Schur
144 *> If JOBVS = 'N', VS is not referenced.
150 *> The leading dimension of the array VS. LDVS >= 1, and if
151 *> JOBVS = 'V', LDVS >= N.
154 *> \param[out] RCONDE
156 *> RCONDE is DOUBLE PRECISION
157 *> If SENSE = 'E' or 'B', RCONDE contains the reciprocal
158 *> condition number for the average of the selected eigenvalues.
159 *> Not referenced if SENSE = 'N' or 'V'.
162 *> \param[out] RCONDV
164 *> RCONDV is DOUBLE PRECISION
165 *> If SENSE = 'V' or 'B', RCONDV contains the reciprocal
166 *> condition number for the selected right invariant subspace.
167 *> Not referenced if SENSE = 'N' or 'E'.
172 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
173 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
179 *> The dimension of the array WORK. LWORK >= max(1,2*N).
180 *> Also, if SENSE = 'E' or 'V' or 'B', LWORK >= 2*SDIM*(N-SDIM),
181 *> where SDIM is the number of selected eigenvalues computed by
182 *> this routine. Note that 2*SDIM*(N-SDIM) <= N*N/2. Note also
183 *> that an error is only returned if LWORK < max(1,2*N), but if
184 *> SENSE = 'E' or 'V' or 'B' this may not be large enough.
185 *> For good performance, LWORK must generally be larger.
187 *> If LWORK = -1, then a workspace query is assumed; the routine
188 *> only calculates upper bound on the optimal size of the
189 *> array WORK, returns this value as the first entry of the WORK
190 *> array, and no error message related to LWORK is issued by
196 *> RWORK is DOUBLE PRECISION array, dimension (N)
201 *> BWORK is LOGICAL array, dimension (N)
202 *> Not referenced if SORT = 'N'.
208 *> = 0: successful exit
209 *> < 0: if INFO = -i, the i-th argument had an illegal value.
210 *> > 0: if INFO = i, and i is
211 *> <= N: the QR algorithm failed to compute all the
212 *> eigenvalues; elements 1:ILO-1 and i+1:N of W
213 *> contain those eigenvalues which have converged; if
214 *> JOBVS = 'V', VS contains the transformation which
215 *> reduces A to its partially converged Schur form.
216 *> = N+1: the eigenvalues could not be reordered because some
217 *> eigenvalues were too close to separate (the problem
218 *> is very ill-conditioned);
219 *> = N+2: after reordering, roundoff changed values of some
220 *> complex eigenvalues so that leading eigenvalues in
221 *> the Schur form no longer satisfy SELECT=.TRUE. This
222 *> could also be caused by underflow due to scaling.
228 *> \author Univ. of Tennessee
229 *> \author Univ. of California Berkeley
230 *> \author Univ. of Colorado Denver
235 *> \ingroup complex16GEeigen
237 * =====================================================================
238 SUBROUTINE ZGEESX( JOBVS, SORT, SELECT, SENSE, N, A, LDA, SDIM, W,
239 $ VS, LDVS, RCONDE, RCONDV, WORK, LWORK, RWORK,
242 * -- LAPACK driver routine (version 3.6.1) --
243 * -- LAPACK is a software package provided by Univ. of Tennessee, --
244 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
247 * .. Scalar Arguments ..
248 CHARACTER JOBVS, SENSE, SORT
249 INTEGER INFO, LDA, LDVS, LWORK, N, SDIM
250 DOUBLE PRECISION RCONDE, RCONDV
252 * .. Array Arguments ..
254 DOUBLE PRECISION RWORK( * )
255 COMPLEX*16 A( LDA, * ), VS( LDVS, * ), W( * ), WORK( * )
257 * .. Function Arguments ..
262 * =====================================================================
265 DOUBLE PRECISION ZERO, ONE
266 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
268 * .. Local Scalars ..
269 LOGICAL LQUERY, SCALEA, WANTSB, WANTSE, WANTSN, WANTST,
271 INTEGER HSWORK, I, IBAL, ICOND, IERR, IEVAL, IHI, ILO,
272 $ ITAU, IWRK, LWRK, MAXWRK, MINWRK
273 DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SMLNUM
276 DOUBLE PRECISION DUM( 1 )
278 * .. External Subroutines ..
279 EXTERNAL DLABAD, DLASCL, XERBLA, ZCOPY, ZGEBAK, ZGEBAL,
280 $ ZGEHRD, ZHSEQR, ZLACPY, ZLASCL, ZTRSEN, ZUNGHR
282 * .. External Functions ..
285 DOUBLE PRECISION DLAMCH, ZLANGE
286 EXTERNAL LSAME, ILAENV, DLAMCH, ZLANGE
288 * .. Intrinsic Functions ..
291 * .. Executable Statements ..
293 * Test the input arguments
296 WANTVS = LSAME( JOBVS, 'V' )
297 WANTST = LSAME( SORT, 'S' )
298 WANTSN = LSAME( SENSE, 'N' )
299 WANTSE = LSAME( SENSE, 'E' )
300 WANTSV = LSAME( SENSE, 'V' )
301 WANTSB = LSAME( SENSE, 'B' )
302 LQUERY = ( LWORK.EQ.-1 )
304 IF( ( .NOT.WANTVS ) .AND. ( .NOT.LSAME( JOBVS, 'N' ) ) ) THEN
306 ELSE IF( ( .NOT.WANTST ) .AND. ( .NOT.LSAME( SORT, 'N' ) ) ) THEN
308 ELSE IF( .NOT.( WANTSN .OR. WANTSE .OR. WANTSV .OR. WANTSB ) .OR.
309 $ ( .NOT.WANTST .AND. .NOT.WANTSN ) ) THEN
311 ELSE IF( N.LT.0 ) THEN
313 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
315 ELSE IF( LDVS.LT.1 .OR. ( WANTVS .AND. LDVS.LT.N ) ) THEN
320 * (Note: Comments in the code beginning "Workspace:" describe the
321 * minimal amount of real workspace needed at that point in the
322 * code, as well as the preferred amount for good performance.
323 * CWorkspace refers to complex workspace, and RWorkspace to real
324 * workspace. NB refers to the optimal block size for the
325 * immediately following subroutine, as returned by ILAENV.
326 * HSWORK refers to the workspace preferred by ZHSEQR, as
327 * calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
329 * If SENSE = 'E', 'V' or 'B', then the amount of workspace needed
330 * depends on SDIM, which is computed by the routine ZTRSEN later
338 MAXWRK = N + N*ILAENV( 1, 'ZGEHRD', ' ', N, 1, N, 0 )
341 CALL ZHSEQR( 'S', JOBVS, N, 1, N, A, LDA, W, VS, LDVS,
345 IF( .NOT.WANTVS ) THEN
346 MAXWRK = MAX( MAXWRK, HSWORK )
348 MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'ZUNGHR',
349 $ ' ', N, 1, N, -1 ) )
350 MAXWRK = MAX( MAXWRK, HSWORK )
354 $ LWRK = MAX( LWRK, ( N*N )/2 )
358 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
364 CALL XERBLA( 'ZGEESX', -INFO )
366 ELSE IF( LQUERY ) THEN
370 * Quick return if possible
377 * Get machine constants
380 SMLNUM = DLAMCH( 'S' )
381 BIGNUM = ONE / SMLNUM
382 CALL DLABAD( SMLNUM, BIGNUM )
383 SMLNUM = SQRT( SMLNUM ) / EPS
384 BIGNUM = ONE / SMLNUM
386 * Scale A if max element outside range [SMLNUM,BIGNUM]
388 ANRM = ZLANGE( 'M', N, N, A, LDA, DUM )
390 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
393 ELSE IF( ANRM.GT.BIGNUM ) THEN
398 $ CALL ZLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
401 * Permute the matrix to make it more nearly triangular
403 * (RWorkspace: need N)
406 CALL ZGEBAL( 'P', N, A, LDA, ILO, IHI, RWORK( IBAL ), IERR )
408 * Reduce to upper Hessenberg form
409 * (CWorkspace: need 2*N, prefer N+N*NB)
414 CALL ZGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
415 $ LWORK-IWRK+1, IERR )
419 * Copy Householder vectors to VS
421 CALL ZLACPY( 'L', N, N, A, LDA, VS, LDVS )
423 * Generate unitary matrix in VS
424 * (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
427 CALL ZUNGHR( N, ILO, IHI, VS, LDVS, WORK( ITAU ), WORK( IWRK ),
428 $ LWORK-IWRK+1, IERR )
433 * Perform QR iteration, accumulating Schur vectors in VS if desired
434 * (CWorkspace: need 1, prefer HSWORK (see comments) )
438 CALL ZHSEQR( 'S', JOBVS, N, ILO, IHI, A, LDA, W, VS, LDVS,
439 $ WORK( IWRK ), LWORK-IWRK+1, IEVAL )
443 * Sort eigenvalues if desired
445 IF( WANTST .AND. INFO.EQ.0 ) THEN
447 $ CALL ZLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, W, N, IERR )
449 BWORK( I ) = SELECT( W( I ) )
452 * Reorder eigenvalues, transform Schur vectors, and compute
453 * reciprocal condition numbers
454 * (CWorkspace: if SENSE is not 'N', need 2*SDIM*(N-SDIM)
455 * otherwise, need none )
458 CALL ZTRSEN( SENSE, JOBVS, BWORK, N, A, LDA, VS, LDVS, W, SDIM,
459 $ RCONDE, RCONDV, WORK( IWRK ), LWORK-IWRK+1,
462 $ MAXWRK = MAX( MAXWRK, 2*SDIM*( N-SDIM ) )
463 IF( ICOND.EQ.-14 ) THEN
465 * Not enough complex workspace
475 * (RWorkspace: need N)
477 CALL ZGEBAK( 'P', 'R', N, ILO, IHI, RWORK( IBAL ), N, VS, LDVS,
483 * Undo scaling for the Schur form of A
485 CALL ZLASCL( 'U', 0, 0, CSCALE, ANRM, N, N, A, LDA, IERR )
486 CALL ZCOPY( N, A, LDA+1, W, 1 )
487 IF( ( WANTSV .OR. WANTSB ) .AND. INFO.EQ.0 ) THEN
489 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, 1, 1, DUM, 1, IERR )