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