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