cgtrfs.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 398 行 · 第 1/2 页
HTML
398 行
DO 10 J = 1, NRHS
FERR( J ) = ZERO
BERR( J ) = ZERO
10 CONTINUE
RETURN
END IF
<span class="comment">*</span><span class="comment">
</span> IF( NOTRAN ) THEN
TRANSN = <span class="string">'N'</span>
TRANST = <span class="string">'C'</span>
ELSE
TRANSN = <span class="string">'C'</span>
TRANST = <span class="string">'N'</span>
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 = 4
EPS = <a name="SLAMCH.199"></a><a href="slamch.f.html#SLAMCH.1">SLAMCH</a>( <span class="string">'Epsilon'</span> )
SAFMIN = <a name="SLAMCH.200"></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 110 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 - 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, B( 1, J ), 1, WORK, 1 )
CALL <a name="CLAGTM.218"></a><a href="clagtm.f.html#CLAGTM.1">CLAGTM</a>( TRANS, N, 1, -ONE, DL, D, DU, X( 1, J ), LDX, ONE,
$ WORK, N )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Compute abs(op(A))*abs(x) + abs(b) for use in the backward
</span><span class="comment">*</span><span class="comment"> error bound.
</span><span class="comment">*</span><span class="comment">
</span> IF( NOTRAN ) THEN
IF( N.EQ.1 ) THEN
RWORK( 1 ) = CABS1( B( 1, J ) ) +
$ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
ELSE
RWORK( 1 ) = CABS1( B( 1, J ) ) +
$ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
$ CABS1( DU( 1 ) )*CABS1( X( 2, J ) )
DO 30 I = 2, N - 1
RWORK( I ) = CABS1( B( I, J ) ) +
$ CABS1( DL( I-1 ) )*CABS1( X( I-1, J ) ) +
$ CABS1( D( I ) )*CABS1( X( I, J ) ) +
$ CABS1( DU( I ) )*CABS1( X( I+1, J ) )
30 CONTINUE
RWORK( N ) = CABS1( B( N, J ) ) +
$ CABS1( DL( N-1 ) )*CABS1( X( N-1, J ) ) +
$ CABS1( D( N ) )*CABS1( X( N, J ) )
END IF
ELSE
IF( N.EQ.1 ) THEN
RWORK( 1 ) = CABS1( B( 1, J ) ) +
$ CABS1( D( 1 ) )*CABS1( X( 1, J ) )
ELSE
RWORK( 1 ) = CABS1( B( 1, J ) ) +
$ CABS1( D( 1 ) )*CABS1( X( 1, J ) ) +
$ CABS1( DL( 1 ) )*CABS1( X( 2, J ) )
DO 40 I = 2, N - 1
RWORK( I ) = CABS1( B( I, J ) ) +
$ CABS1( DU( I-1 ) )*CABS1( X( I-1, J ) ) +
$ CABS1( D( I ) )*CABS1( X( I, J ) ) +
$ CABS1( DL( I ) )*CABS1( X( I+1, J ) )
40 CONTINUE
RWORK( N ) = CABS1( B( N, J ) ) +
$ CABS1( DU( N-1 ) )*CABS1( X( N-1, J ) ) +
$ CABS1( D( N ) )*CABS1( X( N, J ) )
END IF
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(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> S = ZERO
DO 50 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
50 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="CGTTRS.293"></a><a href="cgttrs.f.html#CGTTRS.1">CGTTRS</a>( TRANS, N, 1, DLF, DF, DUF, DU2, IPIV, WORK, N,
$ INFO )
CALL CAXPY( N, CMPLX( ONE ), WORK, 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(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.319"></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 60 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
60 CONTINUE
<span class="comment">*</span><span class="comment">
</span> KASE = 0
70 CONTINUE
CALL <a name="CLACN2.334"></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 <a name="CGTTRS.340"></a><a href="cgttrs.f.html#CGTTRS.1">CGTTRS</a>( TRANST, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
$ N, INFO )
DO 80 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
80 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 90 I = 1, N
WORK( I ) = RWORK( I )*WORK( I )
90 CONTINUE
CALL <a name="CGTTRS.352"></a><a href="cgttrs.f.html#CGTTRS.1">CGTTRS</a>( TRANSN, N, 1, DLF, DF, DUF, DU2, IPIV, WORK,
$ N, INFO )
END IF
GO TO 70
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 100 I = 1, N
LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
100 CONTINUE
IF( LSTRES.NE.ZERO )
$ FERR( J ) = FERR( J ) / LSTRES
<span class="comment">*</span><span class="comment">
</span> 110 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="CGTRFS.371"></a><a href="cgtrfs.f.html#CGTRFS.1">CGTRFS</a>
</span><span class="comment">*</span><span class="comment">
</span> END
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?