dptrfs.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 326 行 · 第 1/2 页
HTML
326 行
</span><span class="comment">*</span><span class="comment"> NZ = maximum number of nonzero elements in each row of A, plus 1
</span><span class="comment">*</span><span class="comment">
</span> NZ = 4
EPS = <a name="DLAMCH.148"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'Epsilon'</span> )
SAFMIN = <a name="DLAMCH.149"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'Safe minimum'</span> )
SAFE1 = NZ*SAFMIN
SAFE2 = SAFE1 / EPS
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Do for each right hand side
</span><span class="comment">*</span><span class="comment">
</span> DO 90 J = 1, NRHS
<span class="comment">*</span><span class="comment">
</span> COUNT = 1
LSTRES = THREE
20 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Loop until stopping criterion is satisfied.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute residual R = B - A * X. Also compute
</span><span class="comment">*</span><span class="comment"> abs(A)*abs(x) + abs(b) for use in the backward error bound.
</span><span class="comment">*</span><span class="comment">
</span> IF( N.EQ.1 ) THEN
BI = B( 1, J )
DX = D( 1 )*X( 1, J )
WORK( N+1 ) = BI - DX
WORK( 1 ) = ABS( BI ) + ABS( DX )
ELSE
BI = B( 1, J )
DX = D( 1 )*X( 1, J )
EX = E( 1 )*X( 2, J )
WORK( N+1 ) = BI - DX - EX
WORK( 1 ) = ABS( BI ) + ABS( DX ) + ABS( EX )
DO 30 I = 2, N - 1
BI = B( I, J )
CX = E( I-1 )*X( I-1, J )
DX = D( I )*X( I, J )
EX = E( I )*X( I+1, J )
WORK( N+I ) = BI - CX - DX - EX
WORK( I ) = ABS( BI ) + ABS( CX ) + ABS( DX ) + ABS( EX )
30 CONTINUE
BI = B( N, J )
CX = E( N-1 )*X( N-1, J )
DX = D( N )*X( N, J )
WORK( N+N ) = BI - CX - DX
WORK( N ) = ABS( BI ) + ABS( CX ) + ABS( DX )
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute componentwise relative backward error from formula
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> where abs(Z) is the componentwise absolute value of the matrix
</span><span class="comment">*</span><span class="comment"> or vector Z. If the i-th component of the denominator is less
</span><span class="comment">*</span><span class="comment"> than SAFE2, then SAFE1 is added to the i-th components of the
</span><span class="comment">*</span><span class="comment"> numerator and denominator before dividing.
</span><span class="comment">*</span><span class="comment">
</span> S = ZERO
DO 40 I = 1, N
IF( WORK( I ).GT.SAFE2 ) THEN
S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
ELSE
S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
$ ( WORK( I )+SAFE1 ) )
END IF
40 CONTINUE
BERR( J ) = S
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Test stopping criterion. Continue iterating if
</span><span class="comment">*</span><span class="comment"> 1) The residual BERR(J) is larger than machine epsilon, and
</span><span class="comment">*</span><span class="comment"> 2) BERR(J) decreased by at least a factor of 2 during the
</span><span class="comment">*</span><span class="comment"> last iteration, and
</span><span class="comment">*</span><span class="comment"> 3) At most ITMAX iterations tried.
</span><span class="comment">*</span><span class="comment">
</span> IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
$ COUNT.LE.ITMAX ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Update solution and try again.
</span><span class="comment">*</span><span class="comment">
</span> CALL <a name="DPTTRS.223"></a><a href="dpttrs.f.html#DPTTRS.1">DPTTRS</a>( N, 1, DF, EF, WORK( N+1 ), N, INFO )
CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
LSTRES = BERR( J )
COUNT = COUNT + 1
GO TO 20
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Bound error from formula
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> norm(X - XTRUE) / norm(X) .le. FERR =
</span><span class="comment">*</span><span class="comment"> norm( abs(inv(A))*
</span><span class="comment">*</span><span class="comment"> ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> where
</span><span class="comment">*</span><span class="comment"> norm(Z) is the magnitude of the largest component of Z
</span><span class="comment">*</span><span class="comment"> inv(A) is the inverse of A
</span><span class="comment">*</span><span class="comment"> abs(Z) is the componentwise absolute value of the matrix or
</span><span class="comment">*</span><span class="comment"> vector Z
</span><span class="comment">*</span><span class="comment"> NZ is the maximum number of nonzeros in any row of A, plus 1
</span><span class="comment">*</span><span class="comment"> EPS is machine epsilon
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
</span><span class="comment">*</span><span class="comment"> is incremented by SAFE1 if the i-th component of
</span><span class="comment">*</span><span class="comment"> abs(A)*abs(X) + abs(B) is less than SAFE2.
</span><span class="comment">*</span><span class="comment">
</span> DO 50 I = 1, N
IF( WORK( I ).GT.SAFE2 ) THEN
WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
ELSE
WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
END IF
50 CONTINUE
IX = IDAMAX( N, WORK, 1 )
FERR( J ) = WORK( IX )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Estimate the norm of inv(A).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> m(i,j) = abs(A(i,j)), i = j,
</span><span class="comment">*</span><span class="comment"> m(i,j) = -abs(A(i,j)), i .ne. j,
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> and e = [ 1, 1, ..., 1 ]'. Note M(A) = M(L)*D*M(L)'.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Solve M(L) * x = e.
</span><span class="comment">*</span><span class="comment">
</span> WORK( 1 ) = ONE
DO 60 I = 2, N
WORK( I ) = ONE + WORK( I-1 )*ABS( EF( I-1 ) )
60 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Solve D * M(L)' * x = b.
</span><span class="comment">*</span><span class="comment">
</span> WORK( N ) = WORK( N ) / DF( N )
DO 70 I = N - 1, 1, -1
WORK( I ) = WORK( I ) / DF( I ) + WORK( I+1 )*ABS( EF( I ) )
70 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute norm(inv(A)) = max(x(i)), 1<=i<=n.
</span><span class="comment">*</span><span class="comment">
</span> IX = IDAMAX( N, WORK, 1 )
FERR( J ) = FERR( J )*ABS( WORK( IX ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Normalize error.
</span><span class="comment">*</span><span class="comment">
</span> LSTRES = ZERO
DO 80 I = 1, N
LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
80 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
<span class="comment">*</span><span class="comment">
</span> 90 CONTINUE
<span class="comment">*</span><span class="comment">
</span> RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> End of <a name="DPTRFS.299"></a><a href="dptrfs.f.html#DPTRFS.1">DPTRFS</a>
</span><span class="comment">*</span><span class="comment">
</span> END
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?