3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DPTRFS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dptrfs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dptrfs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dptrfs.f">
21 * SUBROUTINE DPTRFS( N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR,
24 * .. Scalar Arguments ..
25 * INTEGER INFO, LDB, LDX, N, NRHS
27 * .. Array Arguments ..
28 * DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),
29 * $ E( * ), EF( * ), FERR( * ), WORK( * ),
39 *> DPTRFS improves the computed solution to a system of linear
40 *> equations when the coefficient matrix is symmetric positive definite
41 *> and tridiagonal, and provides error bounds and backward error
42 *> estimates for the solution.
51 *> The order of the matrix A. N >= 0.
57 *> The number of right hand sides, i.e., the number of columns
58 *> of the matrix B. NRHS >= 0.
63 *> D is DOUBLE PRECISION array, dimension (N)
64 *> The n diagonal elements of the tridiagonal matrix A.
69 *> E is DOUBLE PRECISION array, dimension (N-1)
70 *> The (n-1) subdiagonal elements of the tridiagonal matrix A.
75 *> DF is DOUBLE PRECISION array, dimension (N)
76 *> The n diagonal elements of the diagonal matrix D from the
77 *> factorization computed by DPTTRF.
82 *> EF is DOUBLE PRECISION array, dimension (N-1)
83 *> The (n-1) subdiagonal elements of the unit bidiagonal factor
84 *> L from the factorization computed by DPTTRF.
89 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
90 *> The right hand side matrix B.
96 *> The leading dimension of the array B. LDB >= max(1,N).
101 *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
102 *> On entry, the solution matrix X, as computed by DPTTRS.
103 *> On exit, the improved solution matrix X.
109 *> The leading dimension of the array X. LDX >= max(1,N).
114 *> FERR is DOUBLE PRECISION array, dimension (NRHS)
115 *> The forward error bound for each solution vector
116 *> X(j) (the j-th column of the solution matrix X).
117 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
118 *> is an estimated upper bound for the magnitude of the largest
119 *> element in (X(j) - XTRUE) divided by the magnitude of the
120 *> largest element in X(j).
125 *> BERR is DOUBLE PRECISION array, dimension (NRHS)
126 *> The componentwise relative backward error of each solution
127 *> vector X(j) (i.e., the smallest relative change in
128 *> any element of A or B that makes X(j) an exact solution).
133 *> WORK is DOUBLE PRECISION array, dimension (2*N)
139 *> = 0: successful exit
140 *> < 0: if INFO = -i, the i-th argument had an illegal value
143 *> \par Internal Parameters:
144 * =========================
147 *> ITMAX is the maximum number of steps of iterative refinement.
153 *> \author Univ. of Tennessee
154 *> \author Univ. of California Berkeley
155 *> \author Univ. of Colorado Denver
158 *> \date September 2012
160 *> \ingroup doublePTcomputational
162 * =====================================================================
163 SUBROUTINE DPTRFS( N, NRHS, D, E, DF, EF, B, LDB, X, LDX, FERR,
166 * -- LAPACK computational routine (version 3.4.2) --
167 * -- LAPACK is a software package provided by Univ. of Tennessee, --
168 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
171 * .. Scalar Arguments ..
172 INTEGER INFO, LDB, LDX, N, NRHS
174 * .. Array Arguments ..
175 DOUBLE PRECISION B( LDB, * ), BERR( * ), D( * ), DF( * ),
176 $ E( * ), EF( * ), FERR( * ), WORK( * ),
180 * =====================================================================
184 PARAMETER ( ITMAX = 5 )
185 DOUBLE PRECISION ZERO
186 PARAMETER ( ZERO = 0.0D+0 )
188 PARAMETER ( ONE = 1.0D+0 )
190 PARAMETER ( TWO = 2.0D+0 )
191 DOUBLE PRECISION THREE
192 PARAMETER ( THREE = 3.0D+0 )
194 * .. Local Scalars ..
195 INTEGER COUNT, I, IX, J, NZ
196 DOUBLE PRECISION BI, CX, DX, EPS, EX, LSTRES, S, SAFE1, SAFE2,
199 * .. External Subroutines ..
200 EXTERNAL DAXPY, DPTTRS, XERBLA
202 * .. Intrinsic Functions ..
205 * .. External Functions ..
207 DOUBLE PRECISION DLAMCH
208 EXTERNAL IDAMAX, DLAMCH
210 * .. Executable Statements ..
212 * Test the input parameters.
217 ELSE IF( NRHS.LT.0 ) THEN
219 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
221 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
225 CALL XERBLA( 'DPTRFS', -INFO )
229 * Quick return if possible
231 IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
239 * NZ = maximum number of nonzero elements in each row of A, plus 1
242 EPS = DLAMCH( 'Epsilon' )
243 SAFMIN = DLAMCH( 'Safe minimum' )
247 * Do for each right hand side
255 * Loop until stopping criterion is satisfied.
257 * Compute residual R = B - A * X. Also compute
258 * abs(A)*abs(x) + abs(b) for use in the backward error bound.
262 DX = D( 1 )*X( 1, J )
263 WORK( N+1 ) = BI - DX
264 WORK( 1 ) = ABS( BI ) + ABS( DX )
267 DX = D( 1 )*X( 1, J )
268 EX = E( 1 )*X( 2, J )
269 WORK( N+1 ) = BI - DX - EX
270 WORK( 1 ) = ABS( BI ) + ABS( DX ) + ABS( EX )
273 CX = E( I-1 )*X( I-1, J )
274 DX = D( I )*X( I, J )
275 EX = E( I )*X( I+1, J )
276 WORK( N+I ) = BI - CX - DX - EX
277 WORK( I ) = ABS( BI ) + ABS( CX ) + ABS( DX ) + ABS( EX )
280 CX = E( N-1 )*X( N-1, J )
281 DX = D( N )*X( N, J )
282 WORK( N+N ) = BI - CX - DX
283 WORK( N ) = ABS( BI ) + ABS( CX ) + ABS( DX )
286 * Compute componentwise relative backward error from formula
288 * max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
290 * where abs(Z) is the componentwise absolute value of the matrix
291 * or vector Z. If the i-th component of the denominator is less
292 * than SAFE2, then SAFE1 is added to the i-th components of the
293 * numerator and denominator before dividing.
297 IF( WORK( I ).GT.SAFE2 ) THEN
298 S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
300 S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
301 $ ( WORK( I )+SAFE1 ) )
306 * Test stopping criterion. Continue iterating if
307 * 1) The residual BERR(J) is larger than machine epsilon, and
308 * 2) BERR(J) decreased by at least a factor of 2 during the
309 * last iteration, and
310 * 3) At most ITMAX iterations tried.
312 IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
313 $ COUNT.LE.ITMAX ) THEN
315 * Update solution and try again.
317 CALL DPTTRS( N, 1, DF, EF, WORK( N+1 ), N, INFO )
318 CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
324 * Bound error from formula
326 * norm(X - XTRUE) / norm(X) .le. FERR =
328 * ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
331 * norm(Z) is the magnitude of the largest component of Z
332 * inv(A) is the inverse of A
333 * abs(Z) is the componentwise absolute value of the matrix or
335 * NZ is the maximum number of nonzeros in any row of A, plus 1
336 * EPS is machine epsilon
338 * The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
339 * is incremented by SAFE1 if the i-th component of
340 * abs(A)*abs(X) + abs(B) is less than SAFE2.
343 IF( WORK( I ).GT.SAFE2 ) THEN
344 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
346 WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
349 IX = IDAMAX( N, WORK, 1 )
350 FERR( J ) = WORK( IX )
352 * Estimate the norm of inv(A).
354 * Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
356 * m(i,j) = abs(A(i,j)), i = j,
357 * m(i,j) = -abs(A(i,j)), i .ne. j,
359 * and e = [ 1, 1, ..., 1 ]**T. Note M(A) = M(L)*D*M(L)**T.
361 * Solve M(L) * x = e.
365 WORK( I ) = ONE + WORK( I-1 )*ABS( EF( I-1 ) )
368 * Solve D * M(L)**T * x = b.
370 WORK( N ) = WORK( N ) / DF( N )
371 DO 70 I = N - 1, 1, -1
372 WORK( I ) = WORK( I ) / DF( I ) + WORK( I+1 )*ABS( EF( I ) )
375 * Compute norm(inv(A)) = max(x(i)), 1<=i<=n.
377 IX = IDAMAX( N, WORK, 1 )
378 FERR( J ) = FERR( J )*ABS( WORK( IX ) )
384 LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
387 $ FERR( J ) = FERR( J ) / LSTRES