LAPACK 3.3.1
Linear Algebra PACKage

chbevx.f

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