1 *> \brief <b> ZHEEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZHEEVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zheevx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zheevx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zheevx.f">
21 * SUBROUTINE ZHEEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
22 * ABSTOL, M, W, Z, LDZ, WORK, LWORK, RWORK,
23 * IWORK, IFAIL, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE, UPLO
27 * INTEGER IL, INFO, IU, LDA, LDZ, LWORK, M, N
28 * DOUBLE PRECISION ABSTOL, VL, VU
30 * .. Array Arguments ..
31 * INTEGER IFAIL( * ), IWORK( * )
32 * DOUBLE PRECISION RWORK( * ), W( * )
33 * COMPLEX*16 A( LDA, * ), WORK( * ), Z( LDZ, * )
42 *> ZHEEVX computes selected eigenvalues and, optionally, eigenvectors
43 *> of a complex Hermitian matrix A. Eigenvalues and eigenvectors can
44 *> be selected by specifying either a range of values or a range of
45 *> indices for the desired eigenvalues.
53 *> JOBZ is CHARACTER*1
54 *> = 'N': Compute eigenvalues only;
55 *> = 'V': Compute eigenvalues and eigenvectors.
60 *> RANGE is CHARACTER*1
61 *> = 'A': all eigenvalues will be found.
62 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
64 *> = 'I': the IL-th through IU-th eigenvalues will be found.
69 *> UPLO is CHARACTER*1
70 *> = 'U': Upper triangle of A is stored;
71 *> = 'L': Lower triangle of A is stored.
77 *> The order of the matrix A. N >= 0.
82 *> A is COMPLEX*16 array, dimension (LDA, N)
83 *> On entry, the Hermitian matrix A. If UPLO = 'U', the
84 *> leading N-by-N upper triangular part of A contains the
85 *> upper triangular part of the matrix A. If UPLO = 'L',
86 *> the leading N-by-N lower triangular part of A contains
87 *> the lower triangular part of the matrix A.
88 *> On exit, the lower triangle (if UPLO='L') or the upper
89 *> triangle (if UPLO='U') of A, including the diagonal, is
96 *> The leading dimension of the array A. LDA >= max(1,N).
101 *> VL is DOUBLE PRECISION
102 *> If RANGE='V', the lower bound of the interval to
103 *> be searched for eigenvalues. VL < VU.
104 *> Not referenced if RANGE = 'A' or 'I'.
109 *> VU is DOUBLE PRECISION
110 *> If RANGE='V', the upper bound of the interval to
111 *> be searched for eigenvalues. VL < VU.
112 *> Not referenced if RANGE = 'A' or 'I'.
118 *> If RANGE='I', the index of the
119 *> smallest eigenvalue to be returned.
120 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
121 *> Not referenced if RANGE = 'A' or 'V'.
127 *> If RANGE='I', the index of the
128 *> largest eigenvalue to be returned.
129 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
130 *> Not referenced if RANGE = 'A' or 'V'.
135 *> ABSTOL is DOUBLE PRECISION
136 *> The absolute error tolerance for the eigenvalues.
137 *> An approximate eigenvalue is accepted as converged
138 *> when it is determined to lie in an interval [a,b]
139 *> of width less than or equal to
141 *> ABSTOL + EPS * max( |a|,|b| ) ,
143 *> where EPS is the machine precision. If ABSTOL is less than
144 *> or equal to zero, then EPS*|T| will be used in its place,
145 *> where |T| is the 1-norm of the tridiagonal matrix obtained
146 *> by reducing A to tridiagonal form.
148 *> Eigenvalues will be computed most accurately when ABSTOL is
149 *> set to twice the underflow threshold 2*DLAMCH('S'), not zero.
150 *> If this routine returns with INFO>0, indicating that some
151 *> eigenvectors did not converge, try setting ABSTOL to
154 *> See "Computing Small Singular Values of Bidiagonal Matrices
155 *> with Guaranteed High Relative Accuracy," by Demmel and
156 *> Kahan, LAPACK Working Note #3.
162 *> The total number of eigenvalues found. 0 <= M <= N.
163 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
168 *> W is DOUBLE PRECISION array, dimension (N)
169 *> On normal exit, the first M elements contain the selected
170 *> eigenvalues in ascending order.
175 *> Z is COMPLEX*16 array, dimension (LDZ, max(1,M))
176 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
177 *> contain the orthonormal eigenvectors of the matrix A
178 *> corresponding to the selected eigenvalues, with the i-th
179 *> column of Z holding the eigenvector associated with W(i).
180 *> If an eigenvector fails to converge, then that column of Z
181 *> contains the latest approximation to the eigenvector, and the
182 *> index of the eigenvector is returned in IFAIL.
183 *> If JOBZ = 'N', then Z is not referenced.
184 *> Note: the user must ensure that at least max(1,M) columns are
185 *> supplied in the array Z; if RANGE = 'V', the exact value of M
186 *> is not known in advance and an upper bound must be used.
192 *> The leading dimension of the array Z. LDZ >= 1, and if
193 *> JOBZ = 'V', LDZ >= max(1,N).
198 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
199 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
205 *> The length of the array WORK. LWORK >= 1, when N <= 1;
207 *> For optimal efficiency, LWORK >= (NB+1)*N,
208 *> where NB is the max of the blocksize for ZHETRD and for
209 *> ZUNMTR as returned by ILAENV.
211 *> If LWORK = -1, then a workspace query is assumed; the routine
212 *> only calculates the optimal size of the WORK array, returns
213 *> this value as the first entry of the WORK array, and no error
214 *> message related to LWORK is issued by XERBLA.
219 *> RWORK is DOUBLE PRECISION array, dimension (7*N)
224 *> IWORK is INTEGER array, dimension (5*N)
229 *> IFAIL is INTEGER array, dimension (N)
230 *> If JOBZ = 'V', then if INFO = 0, the first M elements of
231 *> IFAIL are zero. If INFO > 0, then IFAIL contains the
232 *> indices of the eigenvectors that failed to converge.
233 *> If JOBZ = 'N', then IFAIL is not referenced.
239 *> = 0: successful exit
240 *> < 0: if INFO = -i, the i-th argument had an illegal value
241 *> > 0: if INFO = i, then i eigenvectors failed to converge.
242 *> Their indices are stored in array IFAIL.
248 *> \author Univ. of Tennessee
249 *> \author Univ. of California Berkeley
250 *> \author Univ. of Colorado Denver
255 *> \ingroup complex16HEeigen
257 * =====================================================================
258 SUBROUTINE ZHEEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
259 $ ABSTOL, M, W, Z, LDZ, WORK, LWORK, RWORK,
260 $ IWORK, IFAIL, INFO )
262 * -- LAPACK driver routine (version 3.6.1) --
263 * -- LAPACK is a software package provided by Univ. of Tennessee, --
264 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
267 * .. Scalar Arguments ..
268 CHARACTER JOBZ, RANGE, UPLO
269 INTEGER IL, INFO, IU, LDA, LDZ, LWORK, M, N
270 DOUBLE PRECISION ABSTOL, VL, VU
272 * .. Array Arguments ..
273 INTEGER IFAIL( * ), IWORK( * )
274 DOUBLE PRECISION RWORK( * ), W( * )
275 COMPLEX*16 A( LDA, * ), WORK( * ), Z( LDZ, * )
278 * =====================================================================
281 DOUBLE PRECISION ZERO, ONE
282 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
284 PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
286 * .. Local Scalars ..
287 LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG,
290 INTEGER I, IINFO, IMAX, INDD, INDE, INDEE, INDIBL,
291 $ INDISP, INDIWK, INDRWK, INDTAU, INDWRK, ISCALE,
292 $ ITMP1, J, JJ, LLWORK, LWKMIN, LWKOPT, NB,
294 DOUBLE PRECISION ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
295 $ SIGMA, SMLNUM, TMP1, VLL, VUU
297 * .. External Functions ..
300 DOUBLE PRECISION DLAMCH, ZLANHE
301 EXTERNAL LSAME, ILAENV, DLAMCH, ZLANHE
303 * .. External Subroutines ..
304 EXTERNAL DCOPY, DSCAL, DSTEBZ, DSTERF, XERBLA, ZDSCAL,
305 $ ZHETRD, ZLACPY, ZSTEIN, ZSTEQR, ZSWAP, ZUNGTR,
308 * .. Intrinsic Functions ..
309 INTRINSIC DBLE, MAX, MIN, SQRT
311 * .. Executable Statements ..
313 * Test the input parameters.
315 LOWER = LSAME( UPLO, 'L' )
316 WANTZ = LSAME( JOBZ, 'V' )
317 ALLEIG = LSAME( RANGE, 'A' )
318 VALEIG = LSAME( RANGE, 'V' )
319 INDEIG = LSAME( RANGE, 'I' )
320 LQUERY = ( LWORK.EQ.-1 )
323 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
325 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
327 ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
329 ELSE IF( N.LT.0 ) THEN
331 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
335 IF( N.GT.0 .AND. VU.LE.VL )
337 ELSE IF( INDEIG ) THEN
338 IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
340 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
346 IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
357 NB = ILAENV( 1, 'ZHETRD', UPLO, N, -1, -1, -1 )
358 NB = MAX( NB, ILAENV( 1, 'ZUNMTR', UPLO, N, -1, -1, -1 ) )
359 LWKOPT = MAX( 1, ( NB + 1 )*N )
363 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY )
368 CALL XERBLA( 'ZHEEVX', -INFO )
370 ELSE IF( LQUERY ) THEN
374 * Quick return if possible
382 IF( ALLEIG .OR. INDEIG ) THEN
385 ELSE IF( VALEIG ) THEN
386 IF( VL.LT.DBLE( A( 1, 1 ) ) .AND. VU.GE.DBLE( A( 1, 1 ) ) )
397 * Get machine constants.
399 SAFMIN = DLAMCH( 'Safe minimum' )
400 EPS = DLAMCH( 'Precision' )
401 SMLNUM = SAFMIN / EPS
402 BIGNUM = ONE / SMLNUM
403 RMIN = SQRT( SMLNUM )
404 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
406 * Scale matrix to allowable range, if necessary.
414 ANRM = ZLANHE( 'M', UPLO, N, A, LDA, RWORK )
415 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
418 ELSE IF( ANRM.GT.RMAX ) THEN
422 IF( ISCALE.EQ.1 ) THEN
425 CALL ZDSCAL( N-J+1, SIGMA, A( J, J ), 1 )
429 CALL ZDSCAL( J, SIGMA, A( 1, J ), 1 )
433 $ ABSTLL = ABSTOL*SIGMA
440 * Call ZHETRD to reduce Hermitian matrix to tridiagonal form.
447 LLWORK = LWORK - INDWRK + 1
448 CALL ZHETRD( UPLO, N, A, LDA, RWORK( INDD ), RWORK( INDE ),
449 $ WORK( INDTAU ), WORK( INDWRK ), LLWORK, IINFO )
451 * If all eigenvalues are desired and ABSTOL is less than or equal to
452 * zero, then call DSTERF or ZUNGTR and ZSTEQR. If this fails for
453 * some eigenvalue, then try DSTEBZ.
457 IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
461 IF( ( ALLEIG .OR. TEST ) .AND. ( ABSTOL.LE.ZERO ) ) THEN
462 CALL DCOPY( N, RWORK( INDD ), 1, W, 1 )
464 IF( .NOT.WANTZ ) THEN
465 CALL DCOPY( N-1, RWORK( INDE ), 1, RWORK( INDEE ), 1 )
466 CALL DSTERF( N, W, RWORK( INDEE ), INFO )
468 CALL ZLACPY( 'A', N, N, A, LDA, Z, LDZ )
469 CALL ZUNGTR( UPLO, N, Z, LDZ, WORK( INDTAU ),
470 $ WORK( INDWRK ), LLWORK, IINFO )
471 CALL DCOPY( N-1, RWORK( INDE ), 1, RWORK( INDEE ), 1 )
472 CALL ZSTEQR( JOBZ, N, W, RWORK( INDEE ), Z, LDZ,
473 $ RWORK( INDRWK ), INFO )
487 * Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN.
497 CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
498 $ RWORK( INDD ), RWORK( INDE ), M, NSPLIT, W,
499 $ IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
500 $ IWORK( INDIWK ), INFO )
503 CALL ZSTEIN( N, RWORK( INDD ), RWORK( INDE ), M, W,
504 $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
505 $ RWORK( INDRWK ), IWORK( INDIWK ), IFAIL, INFO )
507 * Apply unitary matrix used in reduction to tridiagonal
508 * form to eigenvectors returned by ZSTEIN.
510 CALL ZUNMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
511 $ LDZ, WORK( INDWRK ), LLWORK, IINFO )
514 * If matrix was scaled, then rescale eigenvalues appropriately.
517 IF( ISCALE.EQ.1 ) THEN
523 CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
526 * If eigenvalues are not in order, then sort them, along with
534 IF( W( JJ ).LT.TMP1 ) THEN
541 ITMP1 = IWORK( INDIBL+I-1 )
543 IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
545 IWORK( INDIBL+J-1 ) = ITMP1
546 CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
549 IFAIL( I ) = IFAIL( J )
556 * Set WORK(1) to optimal complex workspace size.