001:       SUBROUTINE DPTSVX( FACT, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
002:      $                   RCOND, FERR, BERR, WORK, INFO )
003: *
004: *  -- LAPACK routine (version 3.2) --
005: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
006: *     November 2006
007: *
008: *     .. Scalar Arguments ..
009:       CHARACTER          FACT
010:       INTEGER            INFO, LDB, LDX, N, NRHS
011:       DOUBLE PRECISION   RCOND
012: *     ..
013: *     .. Array Arguments ..
014:       DOUBLE PRECISION   B( LDB, * ), BERR( * ), D( * ), DF( * ),
015:      $                   E( * ), EF( * ), FERR( * ), WORK( * ),
016:      $                   X( LDX, * )
017: *     ..
018: *
019: *  Purpose
020: *  =======
021: *
022: *  DPTSVX uses the factorization A = L*D*L**T to compute the solution
023: *  to a real system of linear equations A*X = B, where A is an N-by-N
024: *  symmetric positive definite tridiagonal matrix and X and B are
025: *  N-by-NRHS matrices.
026: *
027: *  Error bounds on the solution and a condition estimate are also
028: *  provided.
029: *
030: *  Description
031: *  ===========
032: *
033: *  The following steps are performed:
034: *
035: *  1. If FACT = 'N', the matrix A is factored as A = L*D*L**T, where L
036: *     is a unit lower bidiagonal matrix and D is diagonal.  The
037: *     factorization can also be regarded as having the form
038: *     A = U**T*D*U.
039: *
040: *  2. If the leading i-by-i principal minor is not positive definite,
041: *     then the routine returns with INFO = i. Otherwise, the factored
042: *     form of A is used to estimate the condition number of the matrix
043: *     A.  If the reciprocal of the condition number is less than machine
044: *     precision, INFO = N+1 is returned as a warning, but the routine
045: *     still goes on to solve for X and compute error bounds as
046: *     described below.
047: *
048: *  3. The system of equations is solved for X using the factored form
049: *     of A.
050: *
051: *  4. Iterative refinement is applied to improve the computed solution
052: *     matrix and calculate error bounds and backward error estimates
053: *     for it.
054: *
055: *  Arguments
056: *  =========
057: *
058: *  FACT    (input) CHARACTER*1
059: *          Specifies whether or not the factored form of A has been
060: *          supplied on entry.
061: *          = 'F':  On entry, DF and EF contain the factored form of A.
062: *                  D, E, DF, and EF will not be modified.
063: *          = 'N':  The matrix A will be copied to DF and EF and
064: *                  factored.
065: *
066: *  N       (input) INTEGER
067: *          The order of the matrix A.  N >= 0.
068: *
069: *  NRHS    (input) INTEGER
070: *          The number of right hand sides, i.e., the number of columns
071: *          of the matrices B and X.  NRHS >= 0.
072: *
073: *  D       (input) DOUBLE PRECISION array, dimension (N)
074: *          The n diagonal elements of the tridiagonal matrix A.
075: *
076: *  E       (input) DOUBLE PRECISION array, dimension (N-1)
077: *          The (n-1) subdiagonal elements of the tridiagonal matrix A.
078: *
079: *  DF      (input or output) DOUBLE PRECISION array, dimension (N)
080: *          If FACT = 'F', then DF is an input argument and on entry
081: *          contains the n diagonal elements of the diagonal matrix D
082: *          from the L*D*L**T factorization of A.
083: *          If FACT = 'N', then DF is an output argument and on exit
084: *          contains the n diagonal elements of the diagonal matrix D
085: *          from the L*D*L**T factorization of A.
086: *
087: *  EF      (input or output) DOUBLE PRECISION array, dimension (N-1)
088: *          If FACT = 'F', then EF is an input argument and on entry
089: *          contains the (n-1) subdiagonal elements of the unit
090: *          bidiagonal factor L from the L*D*L**T factorization of A.
091: *          If FACT = 'N', then EF is an output argument and on exit
092: *          contains the (n-1) subdiagonal elements of the unit
093: *          bidiagonal factor L from the L*D*L**T factorization of A.
094: *
095: *  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS)
096: *          The N-by-NRHS right hand side matrix B.
097: *
098: *  LDB     (input) INTEGER
099: *          The leading dimension of the array B.  LDB >= max(1,N).
100: *
101: *  X       (output) DOUBLE PRECISION array, dimension (LDX,NRHS)
102: *          If INFO = 0 of INFO = N+1, the N-by-NRHS solution matrix X.
103: *
104: *  LDX     (input) INTEGER
105: *          The leading dimension of the array X.  LDX >= max(1,N).
106: *
107: *  RCOND   (output) DOUBLE PRECISION
108: *          The reciprocal condition number of the matrix A.  If RCOND
109: *          is less than the machine precision (in particular, if
110: *          RCOND = 0), the matrix is singular to working precision.
111: *          This condition is indicated by a return code of INFO > 0.
112: *
113: *  FERR    (output) DOUBLE PRECISION array, dimension (NRHS)
114: *          The forward error bound for each solution vector
115: *          X(j) (the j-th column of the solution matrix X).
116: *          If XTRUE is the true solution corresponding to X(j), FERR(j)
117: *          is an estimated upper bound for the magnitude of the largest
118: *          element in (X(j) - XTRUE) divided by the magnitude of the
119: *          largest element in X(j).
120: *
121: *  BERR    (output) DOUBLE PRECISION array, dimension (NRHS)
122: *          The componentwise relative backward error of each solution
123: *          vector X(j) (i.e., the smallest relative change in any
124: *          element of A or B that makes X(j) an exact solution).
125: *
126: *  WORK    (workspace) DOUBLE PRECISION array, dimension (2*N)
127: *
128: *  INFO    (output) INTEGER
129: *          = 0:  successful exit
130: *          < 0:  if INFO = -i, the i-th argument had an illegal value
131: *          > 0:  if INFO = i, and i is
132: *                <= N:  the leading minor of order i of A is
133: *                       not positive definite, so the factorization
134: *                       could not be completed, and the solution has not
135: *                       been computed. RCOND = 0 is returned.
136: *                = N+1: U is nonsingular, but RCOND is less than machine
137: *                       precision, meaning that the matrix is singular
138: *                       to working precision.  Nevertheless, the
139: *                       solution and error bounds are computed because
140: *                       there are a number of situations where the
141: *                       computed solution can be more accurate than the
142: *                       value of RCOND would suggest.
143: *
144: *  =====================================================================
145: *
146: *     .. Parameters ..
147:       DOUBLE PRECISION   ZERO
148:       PARAMETER          ( ZERO = 0.0D+0 )
149: *     ..
150: *     .. Local Scalars ..
151:       LOGICAL            NOFACT
152:       DOUBLE PRECISION   ANORM
153: *     ..
154: *     .. External Functions ..
155:       LOGICAL            LSAME
156:       DOUBLE PRECISION   DLAMCH, DLANST
157:       EXTERNAL           LSAME, DLAMCH, DLANST
158: *     ..
159: *     .. External Subroutines ..
160:       EXTERNAL           DCOPY, DLACPY, DPTCON, DPTRFS, DPTTRF, DPTTRS,
161:      $                   XERBLA
162: *     ..
163: *     .. Intrinsic Functions ..
164:       INTRINSIC          MAX
165: *     ..
166: *     .. Executable Statements ..
167: *
168: *     Test the input parameters.
169: *
170:       INFO = 0
171:       NOFACT = LSAME( FACT, 'N' )
172:       IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN
173:          INFO = -1
174:       ELSE IF( N.LT.0 ) THEN
175:          INFO = -2
176:       ELSE IF( NRHS.LT.0 ) THEN
177:          INFO = -3
178:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
179:          INFO = -9
180:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
181:          INFO = -11
182:       END IF
183:       IF( INFO.NE.0 ) THEN
184:          CALL XERBLA( 'DPTSVX', -INFO )
185:          RETURN
186:       END IF
187: *
188:       IF( NOFACT ) THEN
189: *
190: *        Compute the L*D*L' (or U'*D*U) factorization of A.
191: *
192:          CALL DCOPY( N, D, 1, DF, 1 )
193:          IF( N.GT.1 )
194:      $      CALL DCOPY( N-1, E, 1, EF, 1 )
195:          CALL DPTTRF( N, DF, EF, INFO )
196: *
197: *        Return if INFO is non-zero.
198: *
199:          IF( INFO.GT.0 )THEN
200:             RCOND = ZERO
201:             RETURN
202:          END IF
203:       END IF
204: *
205: *     Compute the norm of the matrix A.
206: *
207:       ANORM = DLANST( '1', N, D, E )
208: *
209: *     Compute the reciprocal of the condition number of A.
210: *
211:       CALL DPTCON( N, DF, EF, ANORM, RCOND, WORK, INFO )
212: *
213: *     Compute the solution vectors X.
214: *
215:       CALL DLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
216:       CALL DPTTRS( N, NRHS, DF, EF, X, LDX, INFO )
217: *
218: *     Use iterative refinement to improve the computed solutions and
219: *     compute error bounds and backward error estimates for them.
220: *
221:       CALL DPTRFS( N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR, BERR,
222:      $             WORK, INFO )
223: *
224: *     Set INFO = N+1 if the matrix is singular to working precision.
225: *
226:       IF( RCOND.LT.DLAMCH( 'Epsilon' ) )
227:      $   INFO = N + 1
228: *
229:       RETURN
230: *
231: *     End of DPTSVX
232: *
233:       END
234: