dpprfs.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 353 行 · 第 1/2 页
HTML
353 行
END IF
<span class="comment">*</span><span class="comment">
</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 = N + 1
EPS = <a name="DLAMCH.164"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'Epsilon'</span> )
SAFMIN = <a name="DLAMCH.165"></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 140 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
</span><span class="comment">*</span><span class="comment">
</span> CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
CALL DSPMV( UPLO, N, -ONE, AP, X( 1, J ), 1, ONE, WORK( N+1 ),
$ 1 )
<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> DO 30 I = 1, N
WORK( I ) = ABS( B( I, J ) )
30 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute abs(A)*abs(X) + abs(B).
</span><span class="comment">*</span><span class="comment">
</span> KK = 1
IF( UPPER ) THEN
DO 50 K = 1, N
S = ZERO
XK = ABS( X( K, J ) )
IK = KK
DO 40 I = 1, K - 1
WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
IK = IK + 1
40 CONTINUE
WORK( K ) = WORK( K ) + ABS( AP( KK+K-1 ) )*XK + S
KK = KK + K
50 CONTINUE
ELSE
DO 70 K = 1, N
S = ZERO
XK = ABS( X( K, J ) )
WORK( K ) = WORK( K ) + ABS( AP( KK ) )*XK
IK = KK + 1
DO 60 I = K + 1, N
WORK( I ) = WORK( I ) + ABS( AP( IK ) )*XK
S = S + ABS( AP( IK ) )*ABS( X( I, J ) )
IK = IK + 1
60 CONTINUE
WORK( K ) = WORK( K ) + S
KK = KK + ( N-K+1 )
70 CONTINUE
END IF
S = ZERO
DO 80 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
80 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="DPPTRS.251"></a><a href="dpptrs.f.html#DPPTRS.1">DPPTRS</a>( UPLO, N, 1, AFP, 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><span class="comment">*</span><span class="comment"> Use <a name="DLACN2.276"></a><a href="dlacn2.f.html#DLACN2.1">DLACN2</a> to estimate the infinity-norm of the matrix
</span><span class="comment">*</span><span class="comment"> inv(A) * diag(W),
</span><span class="comment">*</span><span class="comment"> where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
</span><span class="comment">*</span><span class="comment">
</span> DO 90 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
90 CONTINUE
<span class="comment">*</span><span class="comment">
</span> KASE = 0
100 CONTINUE
CALL <a name="DLACN2.290"></a><a href="dlacn2.f.html#DLACN2.1">DLACN2</a>( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
$ KASE, ISAVE )
IF( KASE.NE.0 ) THEN
IF( KASE.EQ.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Multiply by diag(W)*inv(A').
</span><span class="comment">*</span><span class="comment">
</span> CALL <a name="DPPTRS.297"></a><a href="dpptrs.f.html#DPPTRS.1">DPPTRS</a>( UPLO, N, 1, AFP, WORK( N+1 ), N, INFO )
DO 110 I = 1, N
WORK( N+I ) = WORK( I )*WORK( N+I )
110 CONTINUE
ELSE IF( KASE.EQ.2 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Multiply by inv(A)*diag(W).
</span><span class="comment">*</span><span class="comment">
</span> DO 120 I = 1, N
WORK( N+I ) = WORK( I )*WORK( N+I )
120 CONTINUE
CALL <a name="DPPTRS.308"></a><a href="dpptrs.f.html#DPPTRS.1">DPPTRS</a>( UPLO, N, 1, AFP, WORK( N+1 ), N, INFO )
END IF
GO TO 100
END IF
<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 130 I = 1, N
LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
130 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
<span class="comment">*</span><span class="comment">
</span> 140 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="DPPRFS.326"></a><a href="dpprfs.f.html#DPPRFS.1">DPPRFS</a>
</span><span class="comment">*</span><span class="comment">
</span> END
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?