ctbrfs.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 422 行 · 第 1/2 页
HTML
422 行
</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 = KD + 2
EPS = <a name="SLAMCH.196"></a><a href="slamch.f.html#SLAMCH.1">SLAMCH</a>( <span class="string">'Epsilon'</span> )
SAFMIN = <a name="SLAMCH.197"></a><a href="slamch.f.html#SLAMCH.1">SLAMCH</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 250 J = 1, NRHS
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute residual R = B - op(A) * X,
</span><span class="comment">*</span><span class="comment"> where op(A) = A, A**T, or A**H, depending on TRANS.
</span><span class="comment">*</span><span class="comment">
</span> CALL CCOPY( N, X( 1, J ), 1, WORK, 1 )
CALL CTBMV( UPLO, TRANS, DIAG, N, KD, AB, LDAB, WORK, 1 )
CALL CAXPY( N, -ONE, B( 1, J ), 1, WORK, 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(op(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 20 I = 1, N
RWORK( I ) = CABS1( B( I, J ) )
20 CONTINUE
<span class="comment">*</span><span class="comment">
</span> IF( NOTRAN ) THEN
<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> IF( UPPER ) THEN
IF( NOUNIT ) THEN
DO 40 K = 1, N
XK = CABS1( X( K, J ) )
DO 30 I = MAX( 1, K-KD ), K
RWORK( I ) = RWORK( I ) +
$ CABS1( AB( KD+1+I-K, K ) )*XK
30 CONTINUE
40 CONTINUE
ELSE
DO 60 K = 1, N
XK = CABS1( X( K, J ) )
DO 50 I = MAX( 1, K-KD ), K - 1
RWORK( I ) = RWORK( I ) +
$ CABS1( AB( KD+1+I-K, K ) )*XK
50 CONTINUE
RWORK( K ) = RWORK( K ) + XK
60 CONTINUE
END IF
ELSE
IF( NOUNIT ) THEN
DO 80 K = 1, N
XK = CABS1( X( K, J ) )
DO 70 I = K, MIN( N, K+KD )
RWORK( I ) = RWORK( I ) +
$ CABS1( AB( 1+I-K, K ) )*XK
70 CONTINUE
80 CONTINUE
ELSE
DO 100 K = 1, N
XK = CABS1( X( K, J ) )
DO 90 I = K + 1, MIN( N, K+KD )
RWORK( I ) = RWORK( I ) +
$ CABS1( AB( 1+I-K, K ) )*XK
90 CONTINUE
RWORK( K ) = RWORK( K ) + XK
100 CONTINUE
END IF
END IF
ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute abs(A**H)*abs(X) + abs(B).
</span><span class="comment">*</span><span class="comment">
</span> IF( UPPER ) THEN
IF( NOUNIT ) THEN
DO 120 K = 1, N
S = ZERO
DO 110 I = MAX( 1, K-KD ), K
S = S + CABS1( AB( KD+1+I-K, K ) )*
$ CABS1( X( I, J ) )
110 CONTINUE
RWORK( K ) = RWORK( K ) + S
120 CONTINUE
ELSE
DO 140 K = 1, N
S = CABS1( X( K, J ) )
DO 130 I = MAX( 1, K-KD ), K - 1
S = S + CABS1( AB( KD+1+I-K, K ) )*
$ CABS1( X( I, J ) )
130 CONTINUE
RWORK( K ) = RWORK( K ) + S
140 CONTINUE
END IF
ELSE
IF( NOUNIT ) THEN
DO 160 K = 1, N
S = ZERO
DO 150 I = K, MIN( N, K+KD )
S = S + CABS1( AB( 1+I-K, K ) )*
$ CABS1( X( I, J ) )
150 CONTINUE
RWORK( K ) = RWORK( K ) + S
160 CONTINUE
ELSE
DO 180 K = 1, N
S = CABS1( X( K, J ) )
DO 170 I = K + 1, MIN( N, K+KD )
S = S + CABS1( AB( 1+I-K, K ) )*
$ CABS1( X( I, J ) )
170 CONTINUE
RWORK( K ) = RWORK( K ) + S
180 CONTINUE
END IF
END IF
END IF
S = ZERO
DO 190 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
ELSE
S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
$ ( RWORK( I )+SAFE1 ) )
END IF
190 CONTINUE
BERR( J ) = S
<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(op(A)))*
</span><span class="comment">*</span><span class="comment"> ( abs(R) + NZ*EPS*( abs(op(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(op(A)) is the inverse of op(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(op(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(op(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="CLACN2.343"></a><a href="clacn2.f.html#CLACN2.1">CLACN2</a> to estimate the infinity-norm of the matrix
</span><span class="comment">*</span><span class="comment"> inv(op(A)) * diag(W),
</span><span class="comment">*</span><span class="comment"> where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
</span><span class="comment">*</span><span class="comment">
</span> DO 200 I = 1, N
IF( RWORK( I ).GT.SAFE2 ) THEN
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
ELSE
RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
$ SAFE1
END IF
200 CONTINUE
<span class="comment">*</span><span class="comment">
</span> KASE = 0
210 CONTINUE
CALL <a name="CLACN2.358"></a><a href="clacn2.f.html#CLACN2.1">CLACN2</a>( N, WORK( N+1 ), WORK, 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(op(A)**H).
</span><span class="comment">*</span><span class="comment">
</span> CALL CTBSV( UPLO, TRANST, DIAG, N, KD, AB, LDAB, WORK,
$ 1 )
DO 220 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
220 CONTINUE
ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Multiply by inv(op(A))*diag(W).
</span><span class="comment">*</span><span class="comment">
</span> DO 230 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
230 CONTINUE
CALL CTBSV( UPLO, TRANSN, DIAG, N, KD, AB, LDAB, WORK,
$ 1 )
END IF
GO TO 210
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 240 I = 1, N
LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
240 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
<span class="comment">*</span><span class="comment">
</span> 250 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="CTBRFS.395"></a><a href="ctbrfs.f.html#CTBRFS.1">CTBRFS</a>
</span><span class="comment">*</span><span class="comment">
</span> END
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?