dporfs.f.html

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

HTML
356
字号
<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><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.174"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'Epsilon'</span> )
      SAFMIN = <a name="DLAMCH.175"></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 DSYMV( UPLO, N, -ONE, A, LDA, 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>         IF( UPPER ) THEN
            DO 50 K = 1, N
               S = ZERO
               XK = ABS( X( K, J ) )
               DO 40 I = 1, K - 1
                  WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
                  S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
   40          CONTINUE
               WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK + S
   50       CONTINUE
         ELSE
            DO 70 K = 1, N
               S = ZERO
               XK = ABS( X( K, J ) )
               WORK( K ) = WORK( K ) + ABS( A( K, K ) )*XK
               DO 60 I = K + 1, N
                  WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
                  S = S + ABS( A( 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="DPOTRS.254"></a><a href="dpotrs.f.html#DPOTRS.1">DPOTRS</a>( UPLO, N, 1, AF, LDAF, 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.279"></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.293"></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="DPOTRS.300"></a><a href="dpotrs.f.html#DPOTRS.1">DPOTRS</a>( UPLO, N, 1, AF, LDAF, 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="DPOTRS.311"></a><a href="dpotrs.f.html#DPOTRS.1">DPOTRS</a>( UPLO, N, 1, AF, LDAF, 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="DPORFS.329"></a><a href="dporfs.f.html#DPORFS.1">DPORFS</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>

⌨️ 快捷键说明

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