LAPACK 3.3.1
Linear Algebra PACKage

dsyevx.f

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