LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
dgerfs.f
Go to the documentation of this file.
00001 *> \brief \b DGERFS
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download DGERFS + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgerfs.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgerfs.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgerfs.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE DGERFS( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
00022 *                          X, LDX, FERR, BERR, WORK, IWORK, INFO )
00023 * 
00024 *       .. Scalar Arguments ..
00025 *       CHARACTER          TRANS
00026 *       INTEGER            INFO, LDA, LDAF, LDB, LDX, N, NRHS
00027 *       ..
00028 *       .. Array Arguments ..
00029 *       INTEGER            IPIV( * ), IWORK( * )
00030 *       DOUBLE PRECISION   A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
00031 *      $                   BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
00032 *       ..
00033 *  
00034 *
00035 *> \par Purpose:
00036 *  =============
00037 *>
00038 *> \verbatim
00039 *>
00040 *> DGERFS improves the computed solution to a system of linear
00041 *> equations and provides error bounds and backward error estimates for
00042 *> the solution.
00043 *> \endverbatim
00044 *
00045 *  Arguments:
00046 *  ==========
00047 *
00048 *> \param[in] TRANS
00049 *> \verbatim
00050 *>          TRANS is CHARACTER*1
00051 *>          Specifies the form of the system of equations:
00052 *>          = 'N':  A * X = B     (No transpose)
00053 *>          = 'T':  A**T * X = B  (Transpose)
00054 *>          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
00055 *> \endverbatim
00056 *>
00057 *> \param[in] N
00058 *> \verbatim
00059 *>          N is INTEGER
00060 *>          The order of the matrix A.  N >= 0.
00061 *> \endverbatim
00062 *>
00063 *> \param[in] NRHS
00064 *> \verbatim
00065 *>          NRHS is INTEGER
00066 *>          The number of right hand sides, i.e., the number of columns
00067 *>          of the matrices B and X.  NRHS >= 0.
00068 *> \endverbatim
00069 *>
00070 *> \param[in] A
00071 *> \verbatim
00072 *>          A is DOUBLE PRECISION array, dimension (LDA,N)
00073 *>          The original N-by-N matrix A.
00074 *> \endverbatim
00075 *>
00076 *> \param[in] LDA
00077 *> \verbatim
00078 *>          LDA is INTEGER
00079 *>          The leading dimension of the array A.  LDA >= max(1,N).
00080 *> \endverbatim
00081 *>
00082 *> \param[in] AF
00083 *> \verbatim
00084 *>          AF is DOUBLE PRECISION array, dimension (LDAF,N)
00085 *>          The factors L and U from the factorization A = P*L*U
00086 *>          as computed by DGETRF.
00087 *> \endverbatim
00088 *>
00089 *> \param[in] LDAF
00090 *> \verbatim
00091 *>          LDAF is INTEGER
00092 *>          The leading dimension of the array AF.  LDAF >= max(1,N).
00093 *> \endverbatim
00094 *>
00095 *> \param[in] IPIV
00096 *> \verbatim
00097 *>          IPIV is INTEGER array, dimension (N)
00098 *>          The pivot indices from DGETRF; for 1<=i<=N, row i of the
00099 *>          matrix was interchanged with row IPIV(i).
00100 *> \endverbatim
00101 *>
00102 *> \param[in] B
00103 *> \verbatim
00104 *>          B is DOUBLE PRECISION array, dimension (LDB,NRHS)
00105 *>          The right hand side matrix B.
00106 *> \endverbatim
00107 *>
00108 *> \param[in] LDB
00109 *> \verbatim
00110 *>          LDB is INTEGER
00111 *>          The leading dimension of the array B.  LDB >= max(1,N).
00112 *> \endverbatim
00113 *>
00114 *> \param[in,out] X
00115 *> \verbatim
00116 *>          X is DOUBLE PRECISION array, dimension (LDX,NRHS)
00117 *>          On entry, the solution matrix X, as computed by DGETRS.
00118 *>          On exit, the improved solution matrix X.
00119 *> \endverbatim
00120 *>
00121 *> \param[in] LDX
00122 *> \verbatim
00123 *>          LDX is INTEGER
00124 *>          The leading dimension of the array X.  LDX >= max(1,N).
00125 *> \endverbatim
00126 *>
00127 *> \param[out] FERR
00128 *> \verbatim
00129 *>          FERR is DOUBLE PRECISION array, dimension (NRHS)
00130 *>          The estimated forward error bound for each solution vector
00131 *>          X(j) (the j-th column of the solution matrix X).
00132 *>          If XTRUE is the true solution corresponding to X(j), FERR(j)
00133 *>          is an estimated upper bound for the magnitude of the largest
00134 *>          element in (X(j) - XTRUE) divided by the magnitude of the
00135 *>          largest element in X(j).  The estimate is as reliable as
00136 *>          the estimate for RCOND, and is almost always a slight
00137 *>          overestimate of the true error.
00138 *> \endverbatim
00139 *>
00140 *> \param[out] BERR
00141 *> \verbatim
00142 *>          BERR is DOUBLE PRECISION array, dimension (NRHS)
00143 *>          The componentwise relative backward error of each solution
00144 *>          vector X(j) (i.e., the smallest relative change in
00145 *>          any element of A or B that makes X(j) an exact solution).
00146 *> \endverbatim
00147 *>
00148 *> \param[out] WORK
00149 *> \verbatim
00150 *>          WORK is DOUBLE PRECISION array, dimension (3*N)
00151 *> \endverbatim
00152 *>
00153 *> \param[out] IWORK
00154 *> \verbatim
00155 *>          IWORK is INTEGER array, dimension (N)
00156 *> \endverbatim
00157 *>
00158 *> \param[out] INFO
00159 *> \verbatim
00160 *>          INFO is INTEGER
00161 *>          = 0:  successful exit
00162 *>          < 0:  if INFO = -i, the i-th argument had an illegal value
00163 *> \endverbatim
00164 *
00165 *> \par Internal Parameters:
00166 *  =========================
00167 *>
00168 *> \verbatim
00169 *>  ITMAX is the maximum number of steps of iterative refinement.
00170 *> \endverbatim
00171 *
00172 *  Authors:
00173 *  ========
00174 *
00175 *> \author Univ. of Tennessee 
00176 *> \author Univ. of California Berkeley 
00177 *> \author Univ. of Colorado Denver 
00178 *> \author NAG Ltd. 
00179 *
00180 *> \date November 2011
00181 *
00182 *> \ingroup doubleGEcomputational
00183 *
00184 *  =====================================================================
00185       SUBROUTINE DGERFS( TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, B, LDB,
00186      $                   X, LDX, FERR, BERR, WORK, IWORK, INFO )
00187 *
00188 *  -- LAPACK computational routine (version 3.4.0) --
00189 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00190 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00191 *     November 2011
00192 *
00193 *     .. Scalar Arguments ..
00194       CHARACTER          TRANS
00195       INTEGER            INFO, LDA, LDAF, LDB, LDX, N, NRHS
00196 *     ..
00197 *     .. Array Arguments ..
00198       INTEGER            IPIV( * ), IWORK( * )
00199       DOUBLE PRECISION   A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
00200      $                   BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
00201 *     ..
00202 *
00203 *  =====================================================================
00204 *
00205 *     .. Parameters ..
00206       INTEGER            ITMAX
00207       PARAMETER          ( ITMAX = 5 )
00208       DOUBLE PRECISION   ZERO
00209       PARAMETER          ( ZERO = 0.0D+0 )
00210       DOUBLE PRECISION   ONE
00211       PARAMETER          ( ONE = 1.0D+0 )
00212       DOUBLE PRECISION   TWO
00213       PARAMETER          ( TWO = 2.0D+0 )
00214       DOUBLE PRECISION   THREE
00215       PARAMETER          ( THREE = 3.0D+0 )
00216 *     ..
00217 *     .. Local Scalars ..
00218       LOGICAL            NOTRAN
00219       CHARACTER          TRANST
00220       INTEGER            COUNT, I, J, K, KASE, NZ
00221       DOUBLE PRECISION   EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
00222 *     ..
00223 *     .. Local Arrays ..
00224       INTEGER            ISAVE( 3 )
00225 *     ..
00226 *     .. External Subroutines ..
00227       EXTERNAL           DAXPY, DCOPY, DGEMV, DGETRS, DLACN2, XERBLA
00228 *     ..
00229 *     .. Intrinsic Functions ..
00230       INTRINSIC          ABS, MAX
00231 *     ..
00232 *     .. External Functions ..
00233       LOGICAL            LSAME
00234       DOUBLE PRECISION   DLAMCH
00235       EXTERNAL           LSAME, DLAMCH
00236 *     ..
00237 *     .. Executable Statements ..
00238 *
00239 *     Test the input parameters.
00240 *
00241       INFO = 0
00242       NOTRAN = LSAME( TRANS, 'N' )
00243       IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00244      $    LSAME( TRANS, 'C' ) ) THEN
00245          INFO = -1
00246       ELSE IF( N.LT.0 ) THEN
00247          INFO = -2
00248       ELSE IF( NRHS.LT.0 ) THEN
00249          INFO = -3
00250       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00251          INFO = -5
00252       ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN
00253          INFO = -7
00254       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00255          INFO = -10
00256       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00257          INFO = -12
00258       END IF
00259       IF( INFO.NE.0 ) THEN
00260          CALL XERBLA( 'DGERFS', -INFO )
00261          RETURN
00262       END IF
00263 *
00264 *     Quick return if possible
00265 *
00266       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00267          DO 10 J = 1, NRHS
00268             FERR( J ) = ZERO
00269             BERR( J ) = ZERO
00270    10    CONTINUE
00271          RETURN
00272       END IF
00273 *
00274       IF( NOTRAN ) THEN
00275          TRANST = 'T'
00276       ELSE
00277          TRANST = 'N'
00278       END IF
00279 *
00280 *     NZ = maximum number of nonzero elements in each row of A, plus 1
00281 *
00282       NZ = N + 1
00283       EPS = DLAMCH( 'Epsilon' )
00284       SAFMIN = DLAMCH( 'Safe minimum' )
00285       SAFE1 = NZ*SAFMIN
00286       SAFE2 = SAFE1 / EPS
00287 *
00288 *     Do for each right hand side
00289 *
00290       DO 140 J = 1, NRHS
00291 *
00292          COUNT = 1
00293          LSTRES = THREE
00294    20    CONTINUE
00295 *
00296 *        Loop until stopping criterion is satisfied.
00297 *
00298 *        Compute residual R = B - op(A) * X,
00299 *        where op(A) = A, A**T, or A**H, depending on TRANS.
00300 *
00301          CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
00302          CALL DGEMV( TRANS, N, N, -ONE, A, LDA, X( 1, J ), 1, ONE,
00303      $               WORK( N+1 ), 1 )
00304 *
00305 *        Compute componentwise relative backward error from formula
00306 *
00307 *        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
00308 *
00309 *        where abs(Z) is the componentwise absolute value of the matrix
00310 *        or vector Z.  If the i-th component of the denominator is less
00311 *        than SAFE2, then SAFE1 is added to the i-th components of the
00312 *        numerator and denominator before dividing.
00313 *
00314          DO 30 I = 1, N
00315             WORK( I ) = ABS( B( I, J ) )
00316    30    CONTINUE
00317 *
00318 *        Compute abs(op(A))*abs(X) + abs(B).
00319 *
00320          IF( NOTRAN ) THEN
00321             DO 50 K = 1, N
00322                XK = ABS( X( K, J ) )
00323                DO 40 I = 1, N
00324                   WORK( I ) = WORK( I ) + ABS( A( I, K ) )*XK
00325    40          CONTINUE
00326    50       CONTINUE
00327          ELSE
00328             DO 70 K = 1, N
00329                S = ZERO
00330                DO 60 I = 1, N
00331                   S = S + ABS( A( I, K ) )*ABS( X( I, J ) )
00332    60          CONTINUE
00333                WORK( K ) = WORK( K ) + S
00334    70       CONTINUE
00335          END IF
00336          S = ZERO
00337          DO 80 I = 1, N
00338             IF( WORK( I ).GT.SAFE2 ) THEN
00339                S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
00340             ELSE
00341                S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
00342      $             ( WORK( I )+SAFE1 ) )
00343             END IF
00344    80    CONTINUE
00345          BERR( J ) = S
00346 *
00347 *        Test stopping criterion. Continue iterating if
00348 *           1) The residual BERR(J) is larger than machine epsilon, and
00349 *           2) BERR(J) decreased by at least a factor of 2 during the
00350 *              last iteration, and
00351 *           3) At most ITMAX iterations tried.
00352 *
00353          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00354      $       COUNT.LE.ITMAX ) THEN
00355 *
00356 *           Update solution and try again.
00357 *
00358             CALL DGETRS( TRANS, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
00359      $                   INFO )
00360             CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
00361             LSTRES = BERR( J )
00362             COUNT = COUNT + 1
00363             GO TO 20
00364          END IF
00365 *
00366 *        Bound error from formula
00367 *
00368 *        norm(X - XTRUE) / norm(X) .le. FERR =
00369 *        norm( abs(inv(op(A)))*
00370 *           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
00371 *
00372 *        where
00373 *          norm(Z) is the magnitude of the largest component of Z
00374 *          inv(op(A)) is the inverse of op(A)
00375 *          abs(Z) is the componentwise absolute value of the matrix or
00376 *             vector Z
00377 *          NZ is the maximum number of nonzeros in any row of A, plus 1
00378 *          EPS is machine epsilon
00379 *
00380 *        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
00381 *        is incremented by SAFE1 if the i-th component of
00382 *        abs(op(A))*abs(X) + abs(B) is less than SAFE2.
00383 *
00384 *        Use DLACN2 to estimate the infinity-norm of the matrix
00385 *           inv(op(A)) * diag(W),
00386 *        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
00387 *
00388          DO 90 I = 1, N
00389             IF( WORK( I ).GT.SAFE2 ) THEN
00390                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
00391             ELSE
00392                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
00393             END IF
00394    90    CONTINUE
00395 *
00396          KASE = 0
00397   100    CONTINUE
00398          CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
00399      $                KASE, ISAVE )
00400          IF( KASE.NE.0 ) THEN
00401             IF( KASE.EQ.1 ) THEN
00402 *
00403 *              Multiply by diag(W)*inv(op(A)**T).
00404 *
00405                CALL DGETRS( TRANST, N, 1, AF, LDAF, IPIV, WORK( N+1 ),
00406      $                      N, INFO )
00407                DO 110 I = 1, N
00408                   WORK( N+I ) = WORK( I )*WORK( N+I )
00409   110          CONTINUE
00410             ELSE
00411 *
00412 *              Multiply by inv(op(A))*diag(W).
00413 *
00414                DO 120 I = 1, N
00415                   WORK( N+I ) = WORK( I )*WORK( N+I )
00416   120          CONTINUE
00417                CALL DGETRS( TRANS, N, 1, AF, LDAF, IPIV, WORK( N+1 ), N,
00418      $                      INFO )
00419             END IF
00420             GO TO 100
00421          END IF
00422 *
00423 *        Normalize error.
00424 *
00425          LSTRES = ZERO
00426          DO 130 I = 1, N
00427             LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
00428   130    CONTINUE
00429          IF( LSTRES.NE.ZERO )
00430      $      FERR( J ) = FERR( J ) / LSTRES
00431 *
00432   140 CONTINUE
00433 *
00434       RETURN
00435 *
00436 *     End of DGERFS
00437 *
00438       END
 All Files Functions