sgbrfs.f.html

来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 380 行 · 第 1/2 页

HTML
380
字号
         INFO = -14
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.175"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="SGBRFS.175"></a><a href="sgbrfs.f.html#SGBRFS.1">SGBRFS</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
         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
         TRANST = <span class="string">'T'</span>
      ELSE
         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 = MIN( KL+KU+2, N+1 )
      EPS = <a name="SLAMCH.198"></a><a href="slamch.f.html#SLAMCH.1">SLAMCH</a>( <span class="string">'Epsilon'</span> )
      SAFMIN = <a name="SLAMCH.199"></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 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 - 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 SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
         CALL SGBMV( TRANS, N, N, KL, KU, -ONE, AB, LDAB, 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(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 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(op(A))*abs(X) + abs(B).
</span><span class="comment">*</span><span class="comment">
</span>         IF( NOTRAN ) THEN
            DO 50 K = 1, N
               KK = KU + 1 - K
               XK = ABS( X( K, J ) )
               DO 40 I = MAX( 1, K-KU ), MIN( N, K+KL )
                  WORK( I ) = WORK( I ) + ABS( AB( KK+I, K ) )*XK
   40          CONTINUE
   50       CONTINUE
         ELSE
            DO 70 K = 1, N
               S = ZERO
               KK = KU + 1 - K
               DO 60 I = MAX( 1, K-KU ), MIN( N, K+KL )
                  S = S + ABS( AB( KK+I, K ) )*ABS( X( I, J ) )
   60          CONTINUE
               WORK( K ) = WORK( K ) + S
   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="SGBTRS.275"></a><a href="sgbtrs.f.html#SGBTRS.1">SGBTRS</a>( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
     $                   WORK( N+1 ), N, INFO )
            CALL SAXPY( 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(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="SLACN2.301"></a><a href="slacn2.f.html#SLACN2.1">SLACN2</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 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="SLACN2.315"></a><a href="slacn2.f.html#SLACN2.1">SLACN2</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(op(A)**T).
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="SGBTRS.322"></a><a href="sgbtrs.f.html#SGBTRS.1">SGBTRS</a>( TRANST, N, KL, KU, 1, AFB, LDAFB, IPIV,
     $                      WORK( N+1 ), N, INFO )
               DO 110 I = 1, N
                  WORK( N+I ) = WORK( N+I )*WORK( I )
  110          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 120 I = 1, N
                  WORK( N+I ) = WORK( N+I )*WORK( I )
  120          CONTINUE
               CALL <a name="SGBTRS.334"></a><a href="sgbtrs.f.html#SGBTRS.1">SGBTRS</a>( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
     $                      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="SGBRFS.353"></a><a href="sgbrfs.f.html#SGBRFS.1">SGBRFS</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?