1 *> \brief <b> ZGEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGEEVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeevx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeevx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeevx.f">
21 * SUBROUTINE ZGEEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, W, VL,
22 * LDVL, VR, LDVR, ILO, IHI, SCALE, ABNRM, RCONDE,
23 * RCONDV, WORK, LWORK, RWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER BALANC, JOBVL, JOBVR, SENSE
27 * INTEGER IHI, ILO, INFO, LDA, LDVL, LDVR, LWORK, N
28 * DOUBLE PRECISION ABNRM
30 * .. Array Arguments ..
31 * DOUBLE PRECISION RCONDE( * ), RCONDV( * ), RWORK( * ),
33 * COMPLEX*16 A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
43 *> ZGEEVX computes for an N-by-N complex nonsymmetric matrix A, the
44 *> eigenvalues and, optionally, the left and/or right eigenvectors.
46 *> Optionally also, it computes a balancing transformation to improve
47 *> the conditioning of the eigenvalues and eigenvectors (ILO, IHI,
48 *> SCALE, and ABNRM), reciprocal condition numbers for the eigenvalues
49 *> (RCONDE), and reciprocal condition numbers for the right
50 *> eigenvectors (RCONDV).
52 *> The right eigenvector v(j) of A satisfies
53 *> A * v(j) = lambda(j) * v(j)
54 *> where lambda(j) is its eigenvalue.
55 *> The left eigenvector u(j) of A satisfies
56 *> u(j)**H * A = lambda(j) * u(j)**H
57 *> where u(j)**H denotes the conjugate transpose of u(j).
59 *> The computed eigenvectors are normalized to have Euclidean norm
60 *> equal to 1 and largest component real.
62 *> Balancing a matrix means permuting the rows and columns to make it
63 *> more nearly upper triangular, and applying a diagonal similarity
64 *> transformation D * A * D**(-1), where D is a diagonal matrix, to
65 *> make its rows and columns closer in norm and the condition numbers
66 *> of its eigenvalues and eigenvectors smaller. The computed
67 *> reciprocal condition numbers correspond to the balanced matrix.
68 *> Permuting rows and columns will not change the condition numbers
69 *> (in exact arithmetic) but diagonal scaling will. For further
70 *> explanation of balancing, see section 4.10.2 of the LAPACK
79 *> BALANC is CHARACTER*1
80 *> Indicates how the input matrix should be diagonally scaled
81 *> and/or permuted to improve the conditioning of its
83 *> = 'N': Do not diagonally scale or permute;
84 *> = 'P': Perform permutations to make the matrix more nearly
85 *> upper triangular. Do not diagonally scale;
86 *> = 'S': Diagonally scale the matrix, ie. replace A by
87 *> D*A*D**(-1), where D is a diagonal matrix chosen
88 *> to make the rows and columns of A more equal in
89 *> norm. Do not permute;
90 *> = 'B': Both diagonally scale and permute A.
92 *> Computed reciprocal condition numbers will be for the matrix
93 *> after balancing and/or permuting. Permuting does not change
94 *> condition numbers (in exact arithmetic), but balancing does.
99 *> JOBVL is CHARACTER*1
100 *> = 'N': left eigenvectors of A are not computed;
101 *> = 'V': left eigenvectors of A are computed.
102 *> If SENSE = 'E' or 'B', JOBVL must = 'V'.
107 *> JOBVR is CHARACTER*1
108 *> = 'N': right eigenvectors of A are not computed;
109 *> = 'V': right eigenvectors of A are computed.
110 *> If SENSE = 'E' or 'B', JOBVR must = 'V'.
115 *> SENSE is CHARACTER*1
116 *> Determines which reciprocal condition numbers are computed.
117 *> = 'N': None are computed;
118 *> = 'E': Computed for eigenvalues only;
119 *> = 'V': Computed for right eigenvectors only;
120 *> = 'B': Computed for eigenvalues and right eigenvectors.
122 *> If SENSE = 'E' or 'B', both left and right eigenvectors
123 *> must also be computed (JOBVL = 'V' and JOBVR = 'V').
129 *> The order of the matrix A. N >= 0.
134 *> A is COMPLEX*16 array, dimension (LDA,N)
135 *> On entry, the N-by-N matrix A.
136 *> On exit, A has been overwritten. If JOBVL = 'V' or
137 *> JOBVR = 'V', A contains the Schur form of the balanced
138 *> version of the matrix A.
144 *> The leading dimension of the array A. LDA >= max(1,N).
149 *> W is COMPLEX*16 array, dimension (N)
150 *> W contains the computed eigenvalues.
155 *> VL is COMPLEX*16 array, dimension (LDVL,N)
156 *> If JOBVL = 'V', the left eigenvectors u(j) are stored one
157 *> after another in the columns of VL, in the same order
158 *> as their eigenvalues.
159 *> If JOBVL = 'N', VL is not referenced.
160 *> u(j) = VL(:,j), the j-th column of VL.
166 *> The leading dimension of the array VL. LDVL >= 1; if
167 *> JOBVL = 'V', LDVL >= N.
172 *> VR is COMPLEX*16 array, dimension (LDVR,N)
173 *> If JOBVR = 'V', the right eigenvectors v(j) are stored one
174 *> after another in the columns of VR, in the same order
175 *> as their eigenvalues.
176 *> If JOBVR = 'N', VR is not referenced.
177 *> v(j) = VR(:,j), the j-th column of VR.
183 *> The leading dimension of the array VR. LDVR >= 1; if
184 *> JOBVR = 'V', LDVR >= N.
195 *> ILO and IHI are integer values determined when A was
196 *> balanced. The balanced A(i,j) = 0 if I > J and
197 *> J = 1,...,ILO-1 or I = IHI+1,...,N.
202 *> SCALE is DOUBLE PRECISION array, dimension (N)
203 *> Details of the permutations and scaling factors applied
204 *> when balancing A. If P(j) is the index of the row and column
205 *> interchanged with row and column j, and D(j) is the scaling
206 *> factor applied to row and column j, then
207 *> SCALE(J) = P(J), for J = 1,...,ILO-1
208 *> = D(J), for J = ILO,...,IHI
209 *> = P(J) for J = IHI+1,...,N.
210 *> The order in which the interchanges are made is N to IHI+1,
216 *> ABNRM is DOUBLE PRECISION
217 *> The one-norm of the balanced matrix (the maximum
218 *> of the sum of absolute values of elements of any column).
221 *> \param[out] RCONDE
223 *> RCONDE is DOUBLE PRECISION array, dimension (N)
224 *> RCONDE(j) is the reciprocal condition number of the j-th
228 *> \param[out] RCONDV
230 *> RCONDV is DOUBLE PRECISION array, dimension (N)
231 *> RCONDV(j) is the reciprocal condition number of the j-th
232 *> right eigenvector.
237 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
238 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
244 *> The dimension of the array WORK. If SENSE = 'N' or 'E',
245 *> LWORK >= max(1,2*N), and if SENSE = 'V' or 'B',
247 *> For good performance, LWORK must generally be larger.
249 *> If LWORK = -1, then a workspace query is assumed; the routine
250 *> only calculates the optimal size of the WORK array, returns
251 *> this value as the first entry of the WORK array, and no error
252 *> message related to LWORK is issued by XERBLA.
257 *> RWORK is DOUBLE PRECISION array, dimension (2*N)
263 *> = 0: successful exit
264 *> < 0: if INFO = -i, the i-th argument had an illegal value.
265 *> > 0: if INFO = i, the QR algorithm failed to compute all the
266 *> eigenvalues, and no eigenvectors or condition numbers
267 *> have been computed; elements 1:ILO-1 and i+1:N of W
268 *> contain eigenvalues which have converged.
274 *> \author Univ. of Tennessee
275 *> \author Univ. of California Berkeley
276 *> \author Univ. of Colorado Denver
281 * @precisions fortran z -> c
283 *> \ingroup complex16GEeigen
285 * =====================================================================
286 SUBROUTINE ZGEEVX( BALANC, JOBVL, JOBVR, SENSE, N, A, LDA, W, VL,
287 $ LDVL, VR, LDVR, ILO, IHI, SCALE, ABNRM, RCONDE,
288 $ RCONDV, WORK, LWORK, RWORK, INFO )
291 * -- LAPACK driver routine (version 3.6.1) --
292 * -- LAPACK is a software package provided by Univ. of Tennessee, --
293 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
296 * .. Scalar Arguments ..
297 CHARACTER BALANC, JOBVL, JOBVR, SENSE
298 INTEGER IHI, ILO, INFO, LDA, LDVL, LDVR, LWORK, N
299 DOUBLE PRECISION ABNRM
301 * .. Array Arguments ..
302 DOUBLE PRECISION RCONDE( * ), RCONDV( * ), RWORK( * ),
304 COMPLEX*16 A( LDA, * ), VL( LDVL, * ), VR( LDVR, * ),
308 * =====================================================================
311 DOUBLE PRECISION ZERO, ONE
312 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
314 * .. Local Scalars ..
315 LOGICAL LQUERY, SCALEA, WANTVL, WANTVR, WNTSNB, WNTSNE,
318 INTEGER HSWORK, I, ICOND, IERR, ITAU, IWRK, K,
319 $ LWORK_TREVC, MAXWRK, MINWRK, NOUT
320 DOUBLE PRECISION ANRM, BIGNUM, CSCALE, EPS, SCL, SMLNUM
325 DOUBLE PRECISION DUM( 1 )
327 * .. External Subroutines ..
328 EXTERNAL DLABAD, DLASCL, XERBLA, ZDSCAL, ZGEBAK, ZGEBAL,
329 $ ZGEHRD, ZHSEQR, ZLACPY, ZLASCL, ZSCAL, ZTREVC3,
332 * .. External Functions ..
334 INTEGER IDAMAX, ILAENV
335 DOUBLE PRECISION DLAMCH, DZNRM2, ZLANGE
336 EXTERNAL LSAME, IDAMAX, ILAENV, DLAMCH, DZNRM2, ZLANGE
338 * .. Intrinsic Functions ..
339 INTRINSIC DBLE, DCMPLX, CONJG, AIMAG, MAX, SQRT
341 * .. Executable Statements ..
343 * Test the input arguments
346 LQUERY = ( LWORK.EQ.-1 )
347 WANTVL = LSAME( JOBVL, 'V' )
348 WANTVR = LSAME( JOBVR, 'V' )
349 WNTSNN = LSAME( SENSE, 'N' )
350 WNTSNE = LSAME( SENSE, 'E' )
351 WNTSNV = LSAME( SENSE, 'V' )
352 WNTSNB = LSAME( SENSE, 'B' )
353 IF( .NOT.( LSAME( BALANC, 'N' ) .OR. LSAME( BALANC, 'S' ) .OR.
354 $ LSAME( BALANC, 'P' ) .OR. LSAME( BALANC, 'B' ) ) ) THEN
356 ELSE IF( ( .NOT.WANTVL ) .AND. ( .NOT.LSAME( JOBVL, 'N' ) ) ) THEN
358 ELSE IF( ( .NOT.WANTVR ) .AND. ( .NOT.LSAME( JOBVR, 'N' ) ) ) THEN
360 ELSE IF( .NOT.( WNTSNN .OR. WNTSNE .OR. WNTSNB .OR. WNTSNV ) .OR.
361 $ ( ( WNTSNE .OR. WNTSNB ) .AND. .NOT.( WANTVL .AND.
364 ELSE IF( N.LT.0 ) THEN
366 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
368 ELSE IF( LDVL.LT.1 .OR. ( WANTVL .AND. LDVL.LT.N ) ) THEN
370 ELSE IF( LDVR.LT.1 .OR. ( WANTVR .AND. LDVR.LT.N ) ) THEN
375 * (Note: Comments in the code beginning "Workspace:" describe the
376 * minimal amount of workspace needed at that point in the code,
377 * as well as the preferred amount for good performance.
378 * CWorkspace refers to complex workspace, and RWorkspace to real
379 * workspace. NB refers to the optimal block size for the
380 * immediately following subroutine, as returned by ILAENV.
381 * HSWORK refers to the workspace preferred by ZHSEQR, as
382 * calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
390 MAXWRK = N + N*ILAENV( 1, 'ZGEHRD', ' ', N, 1, N, 0 )
393 CALL ZTREVC3( 'L', 'B', SELECT, N, A, LDA,
394 $ VL, LDVL, VR, LDVR,
395 $ N, NOUT, WORK, -1, RWORK, -1, IERR )
396 LWORK_TREVC = INT( WORK(1) )
397 MAXWRK = MAX( MAXWRK, LWORK_TREVC )
398 CALL ZHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VL, LDVL,
400 ELSE IF( WANTVR ) THEN
401 CALL ZTREVC3( 'R', 'B', SELECT, N, A, LDA,
402 $ VL, LDVL, VR, LDVR,
403 $ N, NOUT, WORK, -1, RWORK, -1, IERR )
404 LWORK_TREVC = INT( WORK(1) )
405 MAXWRK = MAX( MAXWRK, LWORK_TREVC )
406 CALL ZHSEQR( 'S', 'V', N, 1, N, A, LDA, W, VR, LDVR,
410 CALL ZHSEQR( 'E', 'N', N, 1, N, A, LDA, W, VR, LDVR,
413 CALL ZHSEQR( 'S', 'N', N, 1, N, A, LDA, W, VR, LDVR,
417 HSWORK = INT( WORK(1) )
419 IF( ( .NOT.WANTVL ) .AND. ( .NOT.WANTVR ) ) THEN
421 IF( .NOT.( WNTSNN .OR. WNTSNE ) )
422 $ MINWRK = MAX( MINWRK, N*N + 2*N )
423 MAXWRK = MAX( MAXWRK, HSWORK )
424 IF( .NOT.( WNTSNN .OR. WNTSNE ) )
425 $ MAXWRK = MAX( MAXWRK, N*N + 2*N )
428 IF( .NOT.( WNTSNN .OR. WNTSNE ) )
429 $ MINWRK = MAX( MINWRK, N*N + 2*N )
430 MAXWRK = MAX( MAXWRK, HSWORK )
431 MAXWRK = MAX( MAXWRK, N + ( N - 1 )*ILAENV( 1, 'ZUNGHR',
432 $ ' ', N, 1, N, -1 ) )
433 IF( .NOT.( WNTSNN .OR. WNTSNE ) )
434 $ MAXWRK = MAX( MAXWRK, N*N + 2*N )
435 MAXWRK = MAX( MAXWRK, 2*N )
437 MAXWRK = MAX( MAXWRK, MINWRK )
441 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
447 CALL XERBLA( 'ZGEEVX', -INFO )
449 ELSE IF( LQUERY ) THEN
453 * Quick return if possible
458 * Get machine constants
461 SMLNUM = DLAMCH( 'S' )
462 BIGNUM = ONE / SMLNUM
463 CALL DLABAD( SMLNUM, BIGNUM )
464 SMLNUM = SQRT( SMLNUM ) / EPS
465 BIGNUM = ONE / SMLNUM
467 * Scale A if max element outside range [SMLNUM,BIGNUM]
470 ANRM = ZLANGE( 'M', N, N, A, LDA, DUM )
472 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
475 ELSE IF( ANRM.GT.BIGNUM ) THEN
480 $ CALL ZLASCL( 'G', 0, 0, ANRM, CSCALE, N, N, A, LDA, IERR )
482 * Balance the matrix and compute ABNRM
484 CALL ZGEBAL( BALANC, N, A, LDA, ILO, IHI, SCALE, IERR )
485 ABNRM = ZLANGE( '1', N, N, A, LDA, DUM )
488 CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, 1, 1, DUM, 1, IERR )
492 * Reduce to upper Hessenberg form
493 * (CWorkspace: need 2*N, prefer N+N*NB)
498 CALL ZGEHRD( N, ILO, IHI, A, LDA, WORK( ITAU ), WORK( IWRK ),
499 $ LWORK-IWRK+1, IERR )
503 * Want left eigenvectors
504 * Copy Householder vectors to VL
507 CALL ZLACPY( 'L', N, N, A, LDA, VL, LDVL )
509 * Generate unitary matrix in VL
510 * (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
513 CALL ZUNGHR( N, ILO, IHI, VL, LDVL, WORK( ITAU ), WORK( IWRK ),
514 $ LWORK-IWRK+1, IERR )
516 * Perform QR iteration, accumulating Schur vectors in VL
517 * (CWorkspace: need 1, prefer HSWORK (see comments) )
521 CALL ZHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VL, LDVL,
522 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
526 * Want left and right eigenvectors
527 * Copy Schur vectors to VR
530 CALL ZLACPY( 'F', N, N, VL, LDVL, VR, LDVR )
533 ELSE IF( WANTVR ) THEN
535 * Want right eigenvectors
536 * Copy Householder vectors to VR
539 CALL ZLACPY( 'L', N, N, A, LDA, VR, LDVR )
541 * Generate unitary matrix in VR
542 * (CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
545 CALL ZUNGHR( N, ILO, IHI, VR, LDVR, WORK( ITAU ), WORK( IWRK ),
546 $ LWORK-IWRK+1, IERR )
548 * Perform QR iteration, accumulating Schur vectors in VR
549 * (CWorkspace: need 1, prefer HSWORK (see comments) )
553 CALL ZHSEQR( 'S', 'V', N, ILO, IHI, A, LDA, W, VR, LDVR,
554 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
558 * Compute eigenvalues only
559 * If condition numbers desired, compute Schur form
567 * (CWorkspace: need 1, prefer HSWORK (see comments) )
571 CALL ZHSEQR( JOB, 'N', N, ILO, IHI, A, LDA, W, VR, LDVR,
572 $ WORK( IWRK ), LWORK-IWRK+1, INFO )
575 * If INFO .NE. 0 from ZHSEQR, then quit
580 IF( WANTVL .OR. WANTVR ) THEN
582 * Compute left and/or right eigenvectors
583 * (CWorkspace: need 2*N, prefer N + 2*N*NB)
584 * (RWorkspace: need N)
586 CALL ZTREVC3( SIDE, 'B', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
587 $ N, NOUT, WORK( IWRK ), LWORK-IWRK+1,
591 * Compute condition numbers if desired
592 * (CWorkspace: need N*N+2*N unless SENSE = 'E')
593 * (RWorkspace: need 2*N unless SENSE = 'E')
595 IF( .NOT.WNTSNN ) THEN
596 CALL ZTRSNA( SENSE, 'A', SELECT, N, A, LDA, VL, LDVL, VR, LDVR,
597 $ RCONDE, RCONDV, N, NOUT, WORK( IWRK ), N, RWORK,
603 * Undo balancing of left eigenvectors
605 CALL ZGEBAK( BALANC, 'L', N, ILO, IHI, SCALE, N, VL, LDVL,
608 * Normalize left eigenvectors and make largest component real
611 SCL = ONE / DZNRM2( N, VL( 1, I ), 1 )
612 CALL ZDSCAL( N, SCL, VL( 1, I ), 1 )
614 RWORK( K ) = DBLE( VL( K, I ) )**2 +
615 $ AIMAG( VL( K, I ) )**2
617 K = IDAMAX( N, RWORK, 1 )
618 TMP = CONJG( VL( K, I ) ) / SQRT( RWORK( K ) )
619 CALL ZSCAL( N, TMP, VL( 1, I ), 1 )
620 VL( K, I ) = DCMPLX( DBLE( VL( K, I ) ), ZERO )
626 * Undo balancing of right eigenvectors
628 CALL ZGEBAK( BALANC, 'R', N, ILO, IHI, SCALE, N, VR, LDVR,
631 * Normalize right eigenvectors and make largest component real
634 SCL = ONE / DZNRM2( N, VR( 1, I ), 1 )
635 CALL ZDSCAL( N, SCL, VR( 1, I ), 1 )
637 RWORK( K ) = DBLE( VR( K, I ) )**2 +
638 $ AIMAG( VR( K, I ) )**2
640 K = IDAMAX( N, RWORK, 1 )
641 TMP = CONJG( VR( K, I ) ) / SQRT( RWORK( K ) )
642 CALL ZSCAL( N, TMP, VR( 1, I ), 1 )
643 VR( K, I ) = DCMPLX( DBLE( VR( K, I ) ), ZERO )
647 * Undo scaling if necessary
651 CALL ZLASCL( 'G', 0, 0, CSCALE, ANRM, N-INFO, 1, W( INFO+1 ),
652 $ MAX( N-INFO, 1 ), IERR )
654 IF( ( WNTSNV .OR. WNTSNB ) .AND. ICOND.EQ.0 )
655 $ CALL DLASCL( 'G', 0, 0, CSCALE, ANRM, N, 1, RCONDV, N,
658 CALL ZLASCL( 'G', 0, 0, CSCALE, ANRM, ILO-1, 1, W, N, IERR )