001:       SUBROUTINE SPTEQR( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
005: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          COMPZ
010:       INTEGER            INFO, LDZ, N
011: *     ..
012: *     .. Array Arguments ..
013:       REAL               D( * ), E( * ), WORK( * ), Z( LDZ, * )
014: *     ..
015: *
016: *  Purpose
017: *  =======
018: *
019: *  SPTEQR computes all eigenvalues and, optionally, eigenvectors of a
020: *  symmetric positive definite tridiagonal matrix by first factoring the
021: *  matrix using SPTTRF, and then calling SBDSQR to compute the singular
022: *  values of the bidiagonal factor.
023: *
024: *  This routine computes the eigenvalues of the positive definite
025: *  tridiagonal matrix to high relative accuracy.  This means that if the
026: *  eigenvalues range over many orders of magnitude in size, then the
027: *  small eigenvalues and corresponding eigenvectors will be computed
028: *  more accurately than, for example, with the standard QR method.
029: *
030: *  The eigenvectors of a full or band symmetric positive definite matrix
031: *  can also be found if SSYTRD, SSPTRD, or SSBTRD has been used to
032: *  reduce this matrix to tridiagonal form. (The reduction to tridiagonal
033: *  form, however, may preclude the possibility of obtaining high
034: *  relative accuracy in the small eigenvalues of the original matrix, if
035: *  these eigenvalues range over many orders of magnitude.)
036: *
037: *  Arguments
038: *  =========
039: *
040: *  COMPZ   (input) CHARACTER*1
041: *          = 'N':  Compute eigenvalues only.
042: *          = 'V':  Compute eigenvectors of original symmetric
043: *                  matrix also.  Array Z contains the orthogonal
044: *                  matrix used to reduce the original matrix to
045: *                  tridiagonal form.
046: *          = 'I':  Compute eigenvectors of tridiagonal matrix also.
047: *
048: *  N       (input) INTEGER
049: *          The order of the matrix.  N >= 0.
050: *
051: *  D       (input/output) REAL array, dimension (N)
052: *          On entry, the n diagonal elements of the tridiagonal
053: *          matrix.
054: *          On normal exit, D contains the eigenvalues, in descending
055: *          order.
056: *
057: *  E       (input/output) REAL array, dimension (N-1)
058: *          On entry, the (n-1) subdiagonal elements of the tridiagonal
059: *          matrix.
060: *          On exit, E has been destroyed.
061: *
062: *  Z       (input/output) REAL array, dimension (LDZ, N)
063: *          On entry, if COMPZ = 'V', the orthogonal matrix used in the
064: *          reduction to tridiagonal form.
065: *          On exit, if COMPZ = 'V', the orthonormal eigenvectors of the
066: *          original symmetric matrix;
067: *          if COMPZ = 'I', the orthonormal eigenvectors of the
068: *          tridiagonal matrix.
069: *          If INFO > 0 on exit, Z contains the eigenvectors associated
070: *          with only the stored eigenvalues.
071: *          If  COMPZ = 'N', then Z is not referenced.
072: *
073: *  LDZ     (input) INTEGER
074: *          The leading dimension of the array Z.  LDZ >= 1, and if
075: *          COMPZ = 'V' or 'I', LDZ >= max(1,N).
076: *
077: *  WORK    (workspace) REAL array, dimension (4*N)
078: *
079: *  INFO    (output) INTEGER
080: *          = 0:  successful exit.
081: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
082: *          > 0:  if INFO = i, and i is:
083: *                <= N  the Cholesky factorization of the matrix could
084: *                      not be performed because the i-th principal minor
085: *                      was not positive definite.
086: *                > N   the SVD algorithm failed to converge;
087: *                      if INFO = N+i, i off-diagonal elements of the
088: *                      bidiagonal factor did not converge to zero.
089: *
090: *  =====================================================================
091: *
092: *     .. Parameters ..
093:       REAL               ZERO, ONE
094:       PARAMETER          ( ZERO = 0.0E0, ONE = 1.0E0 )
095: *     ..
096: *     .. External Functions ..
097:       LOGICAL            LSAME
098:       EXTERNAL           LSAME
099: *     ..
100: *     .. External Subroutines ..
101:       EXTERNAL           SBDSQR, SLASET, SPTTRF, XERBLA
102: *     ..
103: *     .. Local Arrays ..
104:       REAL               C( 1, 1 ), VT( 1, 1 )
105: *     ..
106: *     .. Local Scalars ..
107:       INTEGER            I, ICOMPZ, NRU
108: *     ..
109: *     .. Intrinsic Functions ..
110:       INTRINSIC          MAX, SQRT
111: *     ..
112: *     .. Executable Statements ..
113: *
114: *     Test the input parameters.
115: *
116:       INFO = 0
117: *
118:       IF( LSAME( COMPZ, 'N' ) ) THEN
119:          ICOMPZ = 0
120:       ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
121:          ICOMPZ = 1
122:       ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
123:          ICOMPZ = 2
124:       ELSE
125:          ICOMPZ = -1
126:       END IF
127:       IF( ICOMPZ.LT.0 ) THEN
128:          INFO = -1
129:       ELSE IF( N.LT.0 ) THEN
130:          INFO = -2
131:       ELSE IF( ( LDZ.LT.1 ) .OR. ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1,
132:      $         N ) ) ) THEN
133:          INFO = -6
134:       END IF
135:       IF( INFO.NE.0 ) THEN
136:          CALL XERBLA( 'SPTEQR', -INFO )
137:          RETURN
138:       END IF
139: *
140: *     Quick return if possible
141: *
142:       IF( N.EQ.0 )
143:      $   RETURN
144: *
145:       IF( N.EQ.1 ) THEN
146:          IF( ICOMPZ.GT.0 )
147:      $      Z( 1, 1 ) = ONE
148:          RETURN
149:       END IF
150:       IF( ICOMPZ.EQ.2 )
151:      $   CALL SLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
152: *
153: *     Call SPTTRF to factor the matrix.
154: *
155:       CALL SPTTRF( N, D, E, INFO )
156:       IF( INFO.NE.0 )
157:      $   RETURN
158:       DO 10 I = 1, N
159:          D( I ) = SQRT( D( I ) )
160:    10 CONTINUE
161:       DO 20 I = 1, N - 1
162:          E( I ) = E( I )*D( I )
163:    20 CONTINUE
164: *
165: *     Call SBDSQR to compute the singular values/vectors of the
166: *     bidiagonal factor.
167: *
168:       IF( ICOMPZ.GT.0 ) THEN
169:          NRU = N
170:       ELSE
171:          NRU = 0
172:       END IF
173:       CALL SBDSQR( 'Lower', N, 0, NRU, 0, D, E, VT, 1, Z, LDZ, C, 1,
174:      $             WORK, INFO )
175: *
176: *     Square the singular values.
177: *
178:       IF( INFO.EQ.0 ) THEN
179:          DO 30 I = 1, N
180:             D( I ) = D( I )*D( I )
181:    30    CONTINUE
182:       ELSE
183:          INFO = N + INFO
184:       END IF
185: *
186:       RETURN
187: *
188: *     End of SPTEQR
189: *
190:       END
191: