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