LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
zpprfs.f
Go to the documentation of this file.
00001 *> \brief \b ZPPRFS
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download ZPPRFS + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zpprfs.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zpprfs.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zpprfs.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE ZPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
00022 *                          BERR, WORK, RWORK, INFO )
00023 * 
00024 *       .. Scalar Arguments ..
00025 *       CHARACTER          UPLO
00026 *       INTEGER            INFO, LDB, LDX, N, NRHS
00027 *       ..
00028 *       .. Array Arguments ..
00029 *       DOUBLE PRECISION   BERR( * ), FERR( * ), RWORK( * )
00030 *       COMPLEX*16         AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
00031 *      $                   X( LDX, * )
00032 *       ..
00033 *  
00034 *
00035 *> \par Purpose:
00036 *  =============
00037 *>
00038 *> \verbatim
00039 *>
00040 *> ZPPRFS improves the computed solution to a system of linear
00041 *> equations when the coefficient matrix is Hermitian 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 COMPLEX*16 array, dimension (N*(N+1)/2)
00072 *>          The upper or lower triangle of the Hermitian 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 COMPLEX*16 array, dimension (N*(N+1)/2)
00082 *>          The triangular factor U or L from the Cholesky factorization
00083 *>          A = U**H*U or A = L*L**H, 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 COMPLEX*16 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 COMPLEX*16 array, dimension (LDX,NRHS)
00103 *>          On entry, the solution matrix X, as computed by ZPPTRS.
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 COMPLEX*16 array, dimension (2*N)
00137 *> \endverbatim
00138 *>
00139 *> \param[out] RWORK
00140 *> \verbatim
00141 *>          RWORK is DOUBLE PRECISION 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 complex16OTHERcomputational
00169 *
00170 *  =====================================================================
00171       SUBROUTINE ZPPRFS( UPLO, N, NRHS, AP, AFP, B, LDB, X, LDX, FERR,
00172      $                   BERR, WORK, RWORK, 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       DOUBLE PRECISION   BERR( * ), FERR( * ), RWORK( * )
00185       COMPLEX*16         AFP( * ), AP( * ), B( LDB, * ), WORK( * ),
00186      $                   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       COMPLEX*16         CONE
00197       PARAMETER          ( CONE = ( 1.0D+0, 0.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       COMPLEX*16         ZDUM
00208 *     ..
00209 *     .. Local Arrays ..
00210       INTEGER            ISAVE( 3 )
00211 *     ..
00212 *     .. External Subroutines ..
00213       EXTERNAL           XERBLA, ZAXPY, ZCOPY, ZHPMV, ZLACN2, ZPPTRS
00214 *     ..
00215 *     .. Intrinsic Functions ..
00216       INTRINSIC          ABS, DBLE, DIMAG, MAX
00217 *     ..
00218 *     .. External Functions ..
00219       LOGICAL            LSAME
00220       DOUBLE PRECISION   DLAMCH
00221       EXTERNAL           LSAME, DLAMCH
00222 *     ..
00223 *     .. Statement Functions ..
00224       DOUBLE PRECISION   CABS1
00225 *     ..
00226 *     .. Statement Function definitions ..
00227       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
00228 *     ..
00229 *     .. Executable Statements ..
00230 *
00231 *     Test the input parameters.
00232 *
00233       INFO = 0
00234       UPPER = LSAME( UPLO, 'U' )
00235       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00236          INFO = -1
00237       ELSE IF( N.LT.0 ) THEN
00238          INFO = -2
00239       ELSE IF( NRHS.LT.0 ) THEN
00240          INFO = -3
00241       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00242          INFO = -7
00243       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00244          INFO = -9
00245       END IF
00246       IF( INFO.NE.0 ) THEN
00247          CALL XERBLA( 'ZPPRFS', -INFO )
00248          RETURN
00249       END IF
00250 *
00251 *     Quick return if possible
00252 *
00253       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00254          DO 10 J = 1, NRHS
00255             FERR( J ) = ZERO
00256             BERR( J ) = ZERO
00257    10    CONTINUE
00258          RETURN
00259       END IF
00260 *
00261 *     NZ = maximum number of nonzero elements in each row of A, plus 1
00262 *
00263       NZ = N + 1
00264       EPS = DLAMCH( 'Epsilon' )
00265       SAFMIN = DLAMCH( 'Safe minimum' )
00266       SAFE1 = NZ*SAFMIN
00267       SAFE2 = SAFE1 / EPS
00268 *
00269 *     Do for each right hand side
00270 *
00271       DO 140 J = 1, NRHS
00272 *
00273          COUNT = 1
00274          LSTRES = THREE
00275    20    CONTINUE
00276 *
00277 *        Loop until stopping criterion is satisfied.
00278 *
00279 *        Compute residual R = B - A * X
00280 *
00281          CALL ZCOPY( N, B( 1, J ), 1, WORK, 1 )
00282          CALL ZHPMV( UPLO, N, -CONE, AP, X( 1, J ), 1, CONE, WORK, 1 )
00283 *
00284 *        Compute componentwise relative backward error from formula
00285 *
00286 *        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
00287 *
00288 *        where abs(Z) is the componentwise absolute value of the matrix
00289 *        or vector Z.  If the i-th component of the denominator is less
00290 *        than SAFE2, then SAFE1 is added to the i-th components of the
00291 *        numerator and denominator before dividing.
00292 *
00293          DO 30 I = 1, N
00294             RWORK( I ) = CABS1( B( I, J ) )
00295    30    CONTINUE
00296 *
00297 *        Compute abs(A)*abs(X) + abs(B).
00298 *
00299          KK = 1
00300          IF( UPPER ) THEN
00301             DO 50 K = 1, N
00302                S = ZERO
00303                XK = CABS1( X( K, J ) )
00304                IK = KK
00305                DO 40 I = 1, K - 1
00306                   RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
00307                   S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
00308                   IK = IK + 1
00309    40          CONTINUE
00310                RWORK( K ) = RWORK( K ) + ABS( DBLE( AP( KK+K-1 ) ) )*
00311      $                      XK + S
00312                KK = KK + K
00313    50       CONTINUE
00314          ELSE
00315             DO 70 K = 1, N
00316                S = ZERO
00317                XK = CABS1( X( K, J ) )
00318                RWORK( K ) = RWORK( K ) + ABS( DBLE( AP( KK ) ) )*XK
00319                IK = KK + 1
00320                DO 60 I = K + 1, N
00321                   RWORK( I ) = RWORK( I ) + CABS1( AP( IK ) )*XK
00322                   S = S + CABS1( AP( IK ) )*CABS1( X( I, J ) )
00323                   IK = IK + 1
00324    60          CONTINUE
00325                RWORK( K ) = RWORK( K ) + S
00326                KK = KK + ( N-K+1 )
00327    70       CONTINUE
00328          END IF
00329          S = ZERO
00330          DO 80 I = 1, N
00331             IF( RWORK( I ).GT.SAFE2 ) THEN
00332                S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
00333             ELSE
00334                S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
00335      $             ( RWORK( I )+SAFE1 ) )
00336             END IF
00337    80    CONTINUE
00338          BERR( J ) = S
00339 *
00340 *        Test stopping criterion. Continue iterating if
00341 *           1) The residual BERR(J) is larger than machine epsilon, and
00342 *           2) BERR(J) decreased by at least a factor of 2 during the
00343 *              last iteration, and
00344 *           3) At most ITMAX iterations tried.
00345 *
00346          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00347      $       COUNT.LE.ITMAX ) THEN
00348 *
00349 *           Update solution and try again.
00350 *
00351             CALL ZPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
00352             CALL ZAXPY( N, CONE, WORK, 1, X( 1, J ), 1 )
00353             LSTRES = BERR( J )
00354             COUNT = COUNT + 1
00355             GO TO 20
00356          END IF
00357 *
00358 *        Bound error from formula
00359 *
00360 *        norm(X - XTRUE) / norm(X) .le. FERR =
00361 *        norm( abs(inv(A))*
00362 *           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
00363 *
00364 *        where
00365 *          norm(Z) is the magnitude of the largest component of Z
00366 *          inv(A) is the inverse of A
00367 *          abs(Z) is the componentwise absolute value of the matrix or
00368 *             vector Z
00369 *          NZ is the maximum number of nonzeros in any row of A, plus 1
00370 *          EPS is machine epsilon
00371 *
00372 *        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
00373 *        is incremented by SAFE1 if the i-th component of
00374 *        abs(A)*abs(X) + abs(B) is less than SAFE2.
00375 *
00376 *        Use ZLACN2 to estimate the infinity-norm of the matrix
00377 *           inv(A) * diag(W),
00378 *        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) )))
00379 *
00380          DO 90 I = 1, N
00381             IF( RWORK( I ).GT.SAFE2 ) THEN
00382                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
00383             ELSE
00384                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
00385      $                      SAFE1
00386             END IF
00387    90    CONTINUE
00388 *
00389          KASE = 0
00390   100    CONTINUE
00391          CALL ZLACN2( N, WORK( N+1 ), WORK, FERR( J ), KASE, ISAVE )
00392          IF( KASE.NE.0 ) THEN
00393             IF( KASE.EQ.1 ) THEN
00394 *
00395 *              Multiply by diag(W)*inv(A**H).
00396 *
00397                CALL ZPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
00398                DO 110 I = 1, N
00399                   WORK( I ) = RWORK( I )*WORK( I )
00400   110          CONTINUE
00401             ELSE IF( KASE.EQ.2 ) THEN
00402 *
00403 *              Multiply by inv(A)*diag(W).
00404 *
00405                DO 120 I = 1, N
00406                   WORK( I ) = RWORK( I )*WORK( I )
00407   120          CONTINUE
00408                CALL ZPPTRS( UPLO, N, 1, AFP, WORK, N, INFO )
00409             END IF
00410             GO TO 100
00411          END IF
00412 *
00413 *        Normalize error.
00414 *
00415          LSTRES = ZERO
00416          DO 130 I = 1, N
00417             LSTRES = MAX( LSTRES, CABS1( X( I, J ) ) )
00418   130    CONTINUE
00419          IF( LSTRES.NE.ZERO )
00420      $      FERR( J ) = FERR( J ) / LSTRES
00421 *
00422   140 CONTINUE
00423 *
00424       RETURN
00425 *
00426 *     End of ZPPRFS
00427 *
00428       END
 All Files Functions