![]() |
LAPACK
3.4.1
LAPACK: Linear Algebra PACKage
|
00001 *> \brief <b> SSYEVX computes the eigenvalues and, optionally, the left and/or right eigenvectors for SY matrices</b> 00002 * 00003 * =========== DOCUMENTATION =========== 00004 * 00005 * Online html documentation available at 00006 * http://www.netlib.org/lapack/explore-html/ 00007 * 00008 *> \htmlonly 00009 *> Download SSYEVX + dependencies 00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyevx.f"> 00011 *> [TGZ]</a> 00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyevx.f"> 00013 *> [ZIP]</a> 00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyevx.f"> 00015 *> [TXT]</a> 00016 *> \endhtmlonly 00017 * 00018 * Definition: 00019 * =========== 00020 * 00021 * SUBROUTINE SSYEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, 00022 * ABSTOL, M, W, Z, LDZ, WORK, LWORK, IWORK, 00023 * IFAIL, INFO ) 00024 * 00025 * .. Scalar Arguments .. 00026 * CHARACTER JOBZ, RANGE, UPLO 00027 * INTEGER IL, INFO, IU, LDA, LDZ, LWORK, M, N 00028 * REAL ABSTOL, VL, VU 00029 * .. 00030 * .. Array Arguments .. 00031 * INTEGER IFAIL( * ), IWORK( * ) 00032 * REAL A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * ) 00033 * .. 00034 * 00035 * 00036 *> \par Purpose: 00037 * ============= 00038 *> 00039 *> \verbatim 00040 *> 00041 *> SSYEVX computes selected eigenvalues and, optionally, eigenvectors 00042 *> of a real symmetric matrix A. Eigenvalues and eigenvectors can be 00043 *> selected by specifying either a range of values or a range of indices 00044 *> for the desired eigenvalues. 00045 *> \endverbatim 00046 * 00047 * Arguments: 00048 * ========== 00049 * 00050 *> \param[in] JOBZ 00051 *> \verbatim 00052 *> JOBZ is CHARACTER*1 00053 *> = 'N': Compute eigenvalues only; 00054 *> = 'V': Compute eigenvalues and eigenvectors. 00055 *> \endverbatim 00056 *> 00057 *> \param[in] RANGE 00058 *> \verbatim 00059 *> RANGE is CHARACTER*1 00060 *> = 'A': all eigenvalues will be found. 00061 *> = 'V': all eigenvalues in the half-open interval (VL,VU] 00062 *> will be found. 00063 *> = 'I': the IL-th through IU-th eigenvalues will be found. 00064 *> \endverbatim 00065 *> 00066 *> \param[in] UPLO 00067 *> \verbatim 00068 *> UPLO is CHARACTER*1 00069 *> = 'U': Upper triangle of A is stored; 00070 *> = 'L': Lower triangle of A is stored. 00071 *> \endverbatim 00072 *> 00073 *> \param[in] N 00074 *> \verbatim 00075 *> N is INTEGER 00076 *> The order of the matrix A. N >= 0. 00077 *> \endverbatim 00078 *> 00079 *> \param[in,out] A 00080 *> \verbatim 00081 *> A is REAL array, dimension (LDA, N) 00082 *> On entry, the symmetric matrix A. If UPLO = 'U', the 00083 *> leading N-by-N upper triangular part of A contains the 00084 *> upper triangular part of the matrix A. If UPLO = 'L', 00085 *> the leading N-by-N lower triangular part of A contains 00086 *> the lower triangular part of the matrix A. 00087 *> On exit, the lower triangle (if UPLO='L') or the upper 00088 *> triangle (if UPLO='U') of A, including the diagonal, is 00089 *> destroyed. 00090 *> \endverbatim 00091 *> 00092 *> \param[in] LDA 00093 *> \verbatim 00094 *> LDA is INTEGER 00095 *> The leading dimension of the array A. LDA >= max(1,N). 00096 *> \endverbatim 00097 *> 00098 *> \param[in] VL 00099 *> \verbatim 00100 *> VL is REAL 00101 *> \endverbatim 00102 *> 00103 *> \param[in] VU 00104 *> \verbatim 00105 *> VU is REAL 00106 *> If RANGE='V', the lower and upper bounds of the interval to 00107 *> be searched for eigenvalues. VL < VU. 00108 *> Not referenced if RANGE = 'A' or 'I'. 00109 *> \endverbatim 00110 *> 00111 *> \param[in] IL 00112 *> \verbatim 00113 *> IL is INTEGER 00114 *> \endverbatim 00115 *> 00116 *> \param[in] IU 00117 *> \verbatim 00118 *> IU is INTEGER 00119 *> If RANGE='I', the indices (in ascending order) of the 00120 *> smallest and largest eigenvalues to be returned. 00121 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. 00122 *> Not referenced if RANGE = 'A' or 'V'. 00123 *> \endverbatim 00124 *> 00125 *> \param[in] ABSTOL 00126 *> \verbatim 00127 *> ABSTOL is REAL 00128 *> The absolute error tolerance for the eigenvalues. 00129 *> An approximate eigenvalue is accepted as converged 00130 *> when it is determined to lie in an interval [a,b] 00131 *> of width less than or equal to 00132 *> 00133 *> ABSTOL + EPS * max( |a|,|b| ) , 00134 *> 00135 *> where EPS is the machine precision. If ABSTOL is less than 00136 *> or equal to zero, then EPS*|T| will be used in its place, 00137 *> where |T| is the 1-norm of the tridiagonal matrix obtained 00138 *> by reducing A to tridiagonal form. 00139 *> 00140 *> Eigenvalues will be computed most accurately when ABSTOL is 00141 *> set to twice the underflow threshold 2*SLAMCH('S'), not zero. 00142 *> If this routine returns with INFO>0, indicating that some 00143 *> eigenvectors did not converge, try setting ABSTOL to 00144 *> 2*SLAMCH('S'). 00145 *> 00146 *> See "Computing Small Singular Values of Bidiagonal Matrices 00147 *> with Guaranteed High Relative Accuracy," by Demmel and 00148 *> Kahan, LAPACK Working Note #3. 00149 *> \endverbatim 00150 *> 00151 *> \param[out] M 00152 *> \verbatim 00153 *> M is INTEGER 00154 *> The total number of eigenvalues found. 0 <= M <= N. 00155 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. 00156 *> \endverbatim 00157 *> 00158 *> \param[out] W 00159 *> \verbatim 00160 *> W is REAL array, dimension (N) 00161 *> On normal exit, the first M elements contain the selected 00162 *> eigenvalues in ascending order. 00163 *> \endverbatim 00164 *> 00165 *> \param[out] Z 00166 *> \verbatim 00167 *> Z is REAL array, dimension (LDZ, max(1,M)) 00168 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z 00169 *> contain the orthonormal eigenvectors of the matrix A 00170 *> corresponding to the selected eigenvalues, with the i-th 00171 *> column of Z holding the eigenvector associated with W(i). 00172 *> If an eigenvector fails to converge, then that column of Z 00173 *> contains the latest approximation to the eigenvector, and the 00174 *> index of the eigenvector is returned in IFAIL. 00175 *> If JOBZ = 'N', then Z is not referenced. 00176 *> Note: the user must ensure that at least max(1,M) columns are 00177 *> supplied in the array Z; if RANGE = 'V', the exact value of M 00178 *> is not known in advance and an upper bound must be used. 00179 *> \endverbatim 00180 *> 00181 *> \param[in] LDZ 00182 *> \verbatim 00183 *> LDZ is INTEGER 00184 *> The leading dimension of the array Z. LDZ >= 1, and if 00185 *> JOBZ = 'V', LDZ >= max(1,N). 00186 *> \endverbatim 00187 *> 00188 *> \param[out] WORK 00189 *> \verbatim 00190 *> WORK is REAL array, dimension (MAX(1,LWORK)) 00191 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00192 *> \endverbatim 00193 *> 00194 *> \param[in] LWORK 00195 *> \verbatim 00196 *> LWORK is INTEGER 00197 *> The length of the array WORK. LWORK >= 1, when N <= 1; 00198 *> otherwise 8*N. 00199 *> For optimal efficiency, LWORK >= (NB+3)*N, 00200 *> where NB is the max of the blocksize for SSYTRD and SORMTR 00201 *> returned by ILAENV. 00202 *> 00203 *> If LWORK = -1, then a workspace query is assumed; the routine 00204 *> only calculates the optimal size of the WORK array, returns 00205 *> this value as the first entry of the WORK array, and no error 00206 *> message related to LWORK is issued by XERBLA. 00207 *> \endverbatim 00208 *> 00209 *> \param[out] IWORK 00210 *> \verbatim 00211 *> IWORK is INTEGER array, dimension (5*N) 00212 *> \endverbatim 00213 *> 00214 *> \param[out] IFAIL 00215 *> \verbatim 00216 *> IFAIL is INTEGER array, dimension (N) 00217 *> If JOBZ = 'V', then if INFO = 0, the first M elements of 00218 *> IFAIL are zero. If INFO > 0, then IFAIL contains the 00219 *> indices of the eigenvectors that failed to converge. 00220 *> If JOBZ = 'N', then IFAIL is not referenced. 00221 *> \endverbatim 00222 *> 00223 *> \param[out] INFO 00224 *> \verbatim 00225 *> INFO is INTEGER 00226 *> = 0: successful exit 00227 *> < 0: if INFO = -i, the i-th argument had an illegal value 00228 *> > 0: if INFO = i, then i eigenvectors failed to converge. 00229 *> Their indices are stored in array IFAIL. 00230 *> \endverbatim 00231 * 00232 * Authors: 00233 * ======== 00234 * 00235 *> \author Univ. of Tennessee 00236 *> \author Univ. of California Berkeley 00237 *> \author Univ. of Colorado Denver 00238 *> \author NAG Ltd. 00239 * 00240 *> \date November 2011 00241 * 00242 *> \ingroup realSYeigen 00243 * 00244 * ===================================================================== 00245 SUBROUTINE SSYEVX( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, 00246 $ ABSTOL, M, W, Z, LDZ, WORK, LWORK, IWORK, 00247 $ IFAIL, INFO ) 00248 * 00249 * -- LAPACK driver routine (version 3.4.0) -- 00250 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00251 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00252 * November 2011 00253 * 00254 * .. Scalar Arguments .. 00255 CHARACTER JOBZ, RANGE, UPLO 00256 INTEGER IL, INFO, IU, LDA, LDZ, LWORK, M, N 00257 REAL ABSTOL, VL, VU 00258 * .. 00259 * .. Array Arguments .. 00260 INTEGER IFAIL( * ), IWORK( * ) 00261 REAL A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * ) 00262 * .. 00263 * 00264 * ===================================================================== 00265 * 00266 * .. Parameters .. 00267 REAL ZERO, ONE 00268 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) 00269 * .. 00270 * .. Local Scalars .. 00271 LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG, 00272 $ WANTZ 00273 CHARACTER ORDER 00274 INTEGER I, IINFO, IMAX, INDD, INDE, INDEE, INDIBL, 00275 $ INDISP, INDIWO, INDTAU, INDWKN, INDWRK, ISCALE, 00276 $ ITMP1, J, JJ, LLWORK, LLWRKN, LWKMIN, 00277 $ LWKOPT, NB, NSPLIT 00278 REAL ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, 00279 $ SIGMA, SMLNUM, TMP1, VLL, VUU 00280 * .. 00281 * .. External Functions .. 00282 LOGICAL LSAME 00283 INTEGER ILAENV 00284 REAL SLAMCH, SLANSY 00285 EXTERNAL LSAME, ILAENV, SLAMCH, SLANSY 00286 * .. 00287 * .. External Subroutines .. 00288 EXTERNAL SCOPY, SLACPY, SORGTR, SORMTR, SSCAL, SSTEBZ, 00289 $ SSTEIN, SSTEQR, SSTERF, SSWAP, SSYTRD, XERBLA 00290 * .. 00291 * .. Intrinsic Functions .. 00292 INTRINSIC MAX, MIN, SQRT 00293 * .. 00294 * .. Executable Statements .. 00295 * 00296 * Test the input parameters. 00297 * 00298 LOWER = LSAME( UPLO, 'L' ) 00299 WANTZ = LSAME( JOBZ, 'V' ) 00300 ALLEIG = LSAME( RANGE, 'A' ) 00301 VALEIG = LSAME( RANGE, 'V' ) 00302 INDEIG = LSAME( RANGE, 'I' ) 00303 LQUERY = ( LWORK.EQ.-1 ) 00304 * 00305 INFO = 0 00306 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN 00307 INFO = -1 00308 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN 00309 INFO = -2 00310 ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN 00311 INFO = -3 00312 ELSE IF( N.LT.0 ) THEN 00313 INFO = -4 00314 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 00315 INFO = -6 00316 ELSE 00317 IF( VALEIG ) THEN 00318 IF( N.GT.0 .AND. VU.LE.VL ) 00319 $ INFO = -8 00320 ELSE IF( INDEIG ) THEN 00321 IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN 00322 INFO = -9 00323 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN 00324 INFO = -10 00325 END IF 00326 END IF 00327 END IF 00328 IF( INFO.EQ.0 ) THEN 00329 IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN 00330 INFO = -15 00331 END IF 00332 END IF 00333 * 00334 IF( INFO.EQ.0 ) THEN 00335 IF( N.LE.1 ) THEN 00336 LWKMIN = 1 00337 WORK( 1 ) = LWKMIN 00338 ELSE 00339 LWKMIN = 8*N 00340 NB = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 ) 00341 NB = MAX( NB, ILAENV( 1, 'SORMTR', UPLO, N, -1, -1, -1 ) ) 00342 LWKOPT = MAX( LWKMIN, ( NB + 3 )*N ) 00343 WORK( 1 ) = LWKOPT 00344 END IF 00345 * 00346 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) 00347 $ INFO = -17 00348 END IF 00349 * 00350 IF( INFO.NE.0 ) THEN 00351 CALL XERBLA( 'SSYEVX', -INFO ) 00352 RETURN 00353 ELSE IF( LQUERY ) THEN 00354 RETURN 00355 END IF 00356 * 00357 * Quick return if possible 00358 * 00359 M = 0 00360 IF( N.EQ.0 ) THEN 00361 RETURN 00362 END IF 00363 * 00364 IF( N.EQ.1 ) THEN 00365 IF( ALLEIG .OR. INDEIG ) THEN 00366 M = 1 00367 W( 1 ) = A( 1, 1 ) 00368 ELSE 00369 IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN 00370 M = 1 00371 W( 1 ) = A( 1, 1 ) 00372 END IF 00373 END IF 00374 IF( WANTZ ) 00375 $ Z( 1, 1 ) = ONE 00376 RETURN 00377 END IF 00378 * 00379 * Get machine constants. 00380 * 00381 SAFMIN = SLAMCH( 'Safe minimum' ) 00382 EPS = SLAMCH( 'Precision' ) 00383 SMLNUM = SAFMIN / EPS 00384 BIGNUM = ONE / SMLNUM 00385 RMIN = SQRT( SMLNUM ) 00386 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) ) 00387 * 00388 * Scale matrix to allowable range, if necessary. 00389 * 00390 ISCALE = 0 00391 ABSTLL = ABSTOL 00392 IF( VALEIG ) THEN 00393 VLL = VL 00394 VUU = VU 00395 END IF 00396 ANRM = SLANSY( 'M', UPLO, N, A, LDA, WORK ) 00397 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN 00398 ISCALE = 1 00399 SIGMA = RMIN / ANRM 00400 ELSE IF( ANRM.GT.RMAX ) THEN 00401 ISCALE = 1 00402 SIGMA = RMAX / ANRM 00403 END IF 00404 IF( ISCALE.EQ.1 ) THEN 00405 IF( LOWER ) THEN 00406 DO 10 J = 1, N 00407 CALL SSCAL( N-J+1, SIGMA, A( J, J ), 1 ) 00408 10 CONTINUE 00409 ELSE 00410 DO 20 J = 1, N 00411 CALL SSCAL( J, SIGMA, A( 1, J ), 1 ) 00412 20 CONTINUE 00413 END IF 00414 IF( ABSTOL.GT.0 ) 00415 $ ABSTLL = ABSTOL*SIGMA 00416 IF( VALEIG ) THEN 00417 VLL = VL*SIGMA 00418 VUU = VU*SIGMA 00419 END IF 00420 END IF 00421 * 00422 * Call SSYTRD to reduce symmetric matrix to tridiagonal form. 00423 * 00424 INDTAU = 1 00425 INDE = INDTAU + N 00426 INDD = INDE + N 00427 INDWRK = INDD + N 00428 LLWORK = LWORK - INDWRK + 1 00429 CALL SSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ), 00430 $ WORK( INDTAU ), WORK( INDWRK ), LLWORK, IINFO ) 00431 * 00432 * If all eigenvalues are desired and ABSTOL is less than or equal to 00433 * zero, then call SSTERF or SORGTR and SSTEQR. If this fails for 00434 * some eigenvalue, then try SSTEBZ. 00435 * 00436 TEST = .FALSE. 00437 IF( INDEIG ) THEN 00438 IF( IL.EQ.1 .AND. IU.EQ.N ) THEN 00439 TEST = .TRUE. 00440 END IF 00441 END IF 00442 IF( ( ALLEIG .OR. TEST ) .AND. ( ABSTOL.LE.ZERO ) ) THEN 00443 CALL SCOPY( N, WORK( INDD ), 1, W, 1 ) 00444 INDEE = INDWRK + 2*N 00445 IF( .NOT.WANTZ ) THEN 00446 CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 ) 00447 CALL SSTERF( N, W, WORK( INDEE ), INFO ) 00448 ELSE 00449 CALL SLACPY( 'A', N, N, A, LDA, Z, LDZ ) 00450 CALL SORGTR( UPLO, N, Z, LDZ, WORK( INDTAU ), 00451 $ WORK( INDWRK ), LLWORK, IINFO ) 00452 CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 ) 00453 CALL SSTEQR( JOBZ, N, W, WORK( INDEE ), Z, LDZ, 00454 $ WORK( INDWRK ), INFO ) 00455 IF( INFO.EQ.0 ) THEN 00456 DO 30 I = 1, N 00457 IFAIL( I ) = 0 00458 30 CONTINUE 00459 END IF 00460 END IF 00461 IF( INFO.EQ.0 ) THEN 00462 M = N 00463 GO TO 40 00464 END IF 00465 INFO = 0 00466 END IF 00467 * 00468 * Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. 00469 * 00470 IF( WANTZ ) THEN 00471 ORDER = 'B' 00472 ELSE 00473 ORDER = 'E' 00474 END IF 00475 INDIBL = 1 00476 INDISP = INDIBL + N 00477 INDIWO = INDISP + N 00478 CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL, 00479 $ WORK( INDD ), WORK( INDE ), M, NSPLIT, W, 00480 $ IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWRK ), 00481 $ IWORK( INDIWO ), INFO ) 00482 * 00483 IF( WANTZ ) THEN 00484 CALL SSTEIN( N, WORK( INDD ), WORK( INDE ), M, W, 00485 $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ, 00486 $ WORK( INDWRK ), IWORK( INDIWO ), IFAIL, INFO ) 00487 * 00488 * Apply orthogonal matrix used in reduction to tridiagonal 00489 * form to eigenvectors returned by SSTEIN. 00490 * 00491 INDWKN = INDE 00492 LLWRKN = LWORK - INDWKN + 1 00493 CALL SORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z, 00494 $ LDZ, WORK( INDWKN ), LLWRKN, IINFO ) 00495 END IF 00496 * 00497 * If matrix was scaled, then rescale eigenvalues appropriately. 00498 * 00499 40 CONTINUE 00500 IF( ISCALE.EQ.1 ) THEN 00501 IF( INFO.EQ.0 ) THEN 00502 IMAX = M 00503 ELSE 00504 IMAX = INFO - 1 00505 END IF 00506 CALL SSCAL( IMAX, ONE / SIGMA, W, 1 ) 00507 END IF 00508 * 00509 * If eigenvalues are not in order, then sort them, along with 00510 * eigenvectors. 00511 * 00512 IF( WANTZ ) THEN 00513 DO 60 J = 1, M - 1 00514 I = 0 00515 TMP1 = W( J ) 00516 DO 50 JJ = J + 1, M 00517 IF( W( JJ ).LT.TMP1 ) THEN 00518 I = JJ 00519 TMP1 = W( JJ ) 00520 END IF 00521 50 CONTINUE 00522 * 00523 IF( I.NE.0 ) THEN 00524 ITMP1 = IWORK( INDIBL+I-1 ) 00525 W( I ) = W( J ) 00526 IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 ) 00527 W( J ) = TMP1 00528 IWORK( INDIBL+J-1 ) = ITMP1 00529 CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 ) 00530 IF( INFO.NE.0 ) THEN 00531 ITMP1 = IFAIL( I ) 00532 IFAIL( I ) = IFAIL( J ) 00533 IFAIL( J ) = ITMP1 00534 END IF 00535 END IF 00536 60 CONTINUE 00537 END IF 00538 * 00539 * Set WORK(1) to optimal workspace size. 00540 * 00541 WORK( 1 ) = LWKOPT 00542 * 00543 RETURN 00544 * 00545 * End of SSYEVX 00546 * 00547 END