File:  [local] / rpl / lapack / lapack / zptrfs.f
Revision 1.11: download - view: text, annotated - select for diffs - revision graph
Wed Aug 22 09:48:39 2012 UTC (11 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_9, rpl-4_1_10, HEAD
Cohérence

    1: *> \brief \b ZPTRFS
    2: *
    3: *  =========== DOCUMENTATION ===========
    4: *
    5: * Online html documentation available at 
    6: *            http://www.netlib.org/lapack/explore-html/ 
    7: *
    8: *> \htmlonly
    9: *> Download ZPTRFS + dependencies 
   10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zptrfs.f"> 
   11: *> [TGZ]</a> 
   12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zptrfs.f"> 
   13: *> [ZIP]</a> 
   14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zptrfs.f"> 
   15: *> [TXT]</a>
   16: *> \endhtmlonly 
   17: *
   18: *  Definition:
   19: *  ===========
   20: *
   21: *       SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
   22: *                          FERR, BERR, WORK, RWORK, INFO )
   23:    24: *       .. Scalar Arguments ..
   25: *       CHARACTER          UPLO
   26: *       INTEGER            INFO, LDB, LDX, N, NRHS
   27: *       ..
   28: *       .. Array Arguments ..
   29: *       DOUBLE PRECISION   BERR( * ), D( * ), DF( * ), FERR( * ),
   30: *      $                   RWORK( * )
   31: *       COMPLEX*16         B( LDB, * ), E( * ), EF( * ), WORK( * ),
   32: *      $                   X( LDX, * )
   33: *       ..
   34: *  
   35: *
   36: *> \par Purpose:
   37: *  =============
   38: *>
   39: *> \verbatim
   40: *>
   41: *> ZPTRFS improves the computed solution to a system of linear
   42: *> equations when the coefficient matrix is Hermitian positive definite
   43: *> and tridiagonal, and provides error bounds and backward error
   44: *> estimates for the solution.
   45: *> \endverbatim
   46: *
   47: *  Arguments:
   48: *  ==========
   49: *
   50: *> \param[in] UPLO
   51: *> \verbatim
   52: *>          UPLO is CHARACTER*1
   53: *>          Specifies whether the superdiagonal or the subdiagonal of the
   54: *>          tridiagonal matrix A is stored and the form of the
   55: *>          factorization:
   56: *>          = 'U':  E is the superdiagonal of A, and A = U**H*D*U;
   57: *>          = 'L':  E is the subdiagonal of A, and A = L*D*L**H.
   58: *>          (The two forms are equivalent if A is real.)
   59: *> \endverbatim
   60: *>
   61: *> \param[in] N
   62: *> \verbatim
   63: *>          N is INTEGER
   64: *>          The order of the matrix A.  N >= 0.
   65: *> \endverbatim
   66: *>
   67: *> \param[in] NRHS
   68: *> \verbatim
   69: *>          NRHS is INTEGER
   70: *>          The number of right hand sides, i.e., the number of columns
   71: *>          of the matrix B.  NRHS >= 0.
   72: *> \endverbatim
   73: *>
   74: *> \param[in] D
   75: *> \verbatim
   76: *>          D is DOUBLE PRECISION array, dimension (N)
   77: *>          The n real diagonal elements of the tridiagonal matrix A.
   78: *> \endverbatim
   79: *>
   80: *> \param[in] E
   81: *> \verbatim
   82: *>          E is COMPLEX*16 array, dimension (N-1)
   83: *>          The (n-1) off-diagonal elements of the tridiagonal matrix A
   84: *>          (see UPLO).
   85: *> \endverbatim
   86: *>
   87: *> \param[in] DF
   88: *> \verbatim
   89: *>          DF is DOUBLE PRECISION array, dimension (N)
   90: *>          The n diagonal elements of the diagonal matrix D from
   91: *>          the factorization computed by ZPTTRF.
   92: *> \endverbatim
   93: *>
   94: *> \param[in] EF
   95: *> \verbatim
   96: *>          EF is COMPLEX*16 array, dimension (N-1)
   97: *>          The (n-1) off-diagonal elements of the unit bidiagonal
   98: *>          factor U or L from the factorization computed by ZPTTRF
   99: *>          (see UPLO).
  100: *> \endverbatim
  101: *>
  102: *> \param[in] B
  103: *> \verbatim
  104: *>          B is COMPLEX*16 array, dimension (LDB,NRHS)
  105: *>          The right hand side matrix B.
  106: *> \endverbatim
  107: *>
  108: *> \param[in] LDB
  109: *> \verbatim
  110: *>          LDB is INTEGER
  111: *>          The leading dimension of the array B.  LDB >= max(1,N).
  112: *> \endverbatim
  113: *>
  114: *> \param[in,out] X
  115: *> \verbatim
  116: *>          X is COMPLEX*16 array, dimension (LDX,NRHS)
  117: *>          On entry, the solution matrix X, as computed by ZPTTRS.
  118: *>          On exit, the improved solution matrix X.
  119: *> \endverbatim
  120: *>
  121: *> \param[in] LDX
  122: *> \verbatim
  123: *>          LDX is INTEGER
  124: *>          The leading dimension of the array X.  LDX >= max(1,N).
  125: *> \endverbatim
  126: *>
  127: *> \param[out] FERR
  128: *> \verbatim
  129: *>          FERR is DOUBLE PRECISION array, dimension (NRHS)
  130: *>          The forward error bound for each solution vector
  131: *>          X(j) (the j-th column of the solution matrix X).
  132: *>          If XTRUE is the true solution corresponding to X(j), FERR(j)
  133: *>          is an estimated upper bound for the magnitude of the largest
  134: *>          element in (X(j) - XTRUE) divided by the magnitude of the
  135: *>          largest element in X(j).
  136: *> \endverbatim
  137: *>
  138: *> \param[out] BERR
  139: *> \verbatim
  140: *>          BERR is DOUBLE PRECISION array, dimension (NRHS)
  141: *>          The componentwise relative backward error of each solution
  142: *>          vector X(j) (i.e., the smallest relative change in
  143: *>          any element of A or B that makes X(j) an exact solution).
  144: *> \endverbatim
  145: *>
  146: *> \param[out] WORK
  147: *> \verbatim
  148: *>          WORK is COMPLEX*16 array, dimension (N)
  149: *> \endverbatim
  150: *>
  151: *> \param[out] RWORK
  152: *> \verbatim
  153: *>          RWORK is DOUBLE PRECISION array, dimension (N)
  154: *> \endverbatim
  155: *>
  156: *> \param[out] INFO
  157: *> \verbatim
  158: *>          INFO is INTEGER
  159: *>          = 0:  successful exit
  160: *>          < 0:  if INFO = -i, the i-th argument had an illegal value
  161: *> \endverbatim
  162: *
  163: *> \par Internal Parameters:
  164: *  =========================
  165: *>
  166: *> \verbatim
  167: *>  ITMAX is the maximum number of steps of iterative refinement.
  168: *> \endverbatim
  169: *
  170: *  Authors:
  171: *  ========
  172: *
  173: *> \author Univ. of Tennessee 
  174: *> \author Univ. of California Berkeley 
  175: *> \author Univ. of Colorado Denver 
  176: *> \author NAG Ltd. 
  177: *
  178: *> \date November 2011
  179: *
  180: *> \ingroup complex16OTHERcomputational
  181: *
  182: *  =====================================================================
  183:       SUBROUTINE ZPTRFS( UPLO, N, NRHS, D, E, DF, EF, B, LDB, X, LDX,
  184:      $                   FERR, BERR, WORK, RWORK, INFO )
  185: *
  186: *  -- LAPACK computational routine (version 3.4.0) --
  187: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  188: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  189: *     November 2011
  190: *
  191: *     .. Scalar Arguments ..
  192:       CHARACTER          UPLO
  193:       INTEGER            INFO, LDB, LDX, N, NRHS
  194: *     ..
  195: *     .. Array Arguments ..
  196:       DOUBLE PRECISION   BERR( * ), D( * ), DF( * ), FERR( * ),
  197:      $                   RWORK( * )
  198:       COMPLEX*16         B( LDB, * ), E( * ), EF( * ), WORK( * ),
  199:      $                   X( LDX, * )
  200: *     ..
  201: *
  202: *  =====================================================================
  203: *
  204: *     .. Parameters ..
  205:       INTEGER            ITMAX
  206:       PARAMETER          ( ITMAX = 5 )
  207:       DOUBLE PRECISION   ZERO
  208:       PARAMETER          ( ZERO = 0.0D+0 )
  209:       DOUBLE PRECISION   ONE
  210:       PARAMETER          ( ONE = 1.0D+0 )
  211:       DOUBLE PRECISION   TWO
  212:       PARAMETER          ( TWO = 2.0D+0 )
  213:       DOUBLE PRECISION   THREE
  214:       PARAMETER          ( THREE = 3.0D+0 )
  215: *     ..
  216: *     .. Local Scalars ..
  217:       LOGICAL            UPPER
  218:       INTEGER            COUNT, I, IX, J, NZ
  219:       DOUBLE PRECISION   EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
  220:       COMPLEX*16         BI, CX, DX, EX, ZDUM
  221: *     ..
  222: *     .. External Functions ..
  223:       LOGICAL            LSAME
  224:       INTEGER            IDAMAX
  225:       DOUBLE PRECISION   DLAMCH
  226:       EXTERNAL           LSAME, IDAMAX, DLAMCH
  227: *     ..
  228: *     .. External Subroutines ..
  229:       EXTERNAL           XERBLA, ZAXPY, ZPTTRS
  230: *     ..
  231: *     .. Intrinsic Functions ..
  232:       INTRINSIC          ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX
  233: *     ..
  234: *     .. Statement Functions ..
  235:       DOUBLE PRECISION   CABS1
  236: *     ..
  237: *     .. Statement Function definitions ..
  238:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
  239: *     ..
  240: *     .. Executable Statements ..
  241: *
  242: *     Test the input parameters.
  243: *
  244:       INFO = 0
  245:       UPPER = LSAME( UPLO, 'U' )
  246:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  247:          INFO = -1
  248:       ELSE IF( N.LT.0 ) THEN
  249:          INFO = -2
  250:       ELSE IF( NRHS.LT.0 ) THEN
  251:          INFO = -3
  252:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
  253:          INFO = -9
  254:       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  255:          INFO = -11
  256:       END IF
  257:       IF( INFO.NE.0 ) THEN
  258:          CALL XERBLA( 'ZPTRFS', -INFO )
  259:          RETURN
  260:       END IF
  261: *
  262: *     Quick return if possible
  263: *
  264:       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
  265:          DO 10 J = 1, NRHS
  266:             FERR( J ) = ZERO
  267:             BERR( J ) = ZERO
  268:    10    CONTINUE
  269:          RETURN
  270:       END IF
  271: *
  272: *     NZ = maximum number of nonzero elements in each row of A, plus 1
  273: *
  274:       NZ = 4
  275:       EPS = DLAMCH( 'Epsilon' )
  276:       SAFMIN = DLAMCH( 'Safe minimum' )
  277:       SAFE1 = NZ*SAFMIN
  278:       SAFE2 = SAFE1 / EPS
  279: *
  280: *     Do for each right hand side
  281: *
  282:       DO 100 J = 1, NRHS
  283: *
  284:          COUNT = 1
  285:          LSTRES = THREE
  286:    20    CONTINUE
  287: *
  288: *        Loop until stopping criterion is satisfied.
  289: *
  290: *        Compute residual R = B - A * X.  Also compute
  291: *        abs(A)*abs(x) + abs(b) for use in the backward error bound.
  292: *
  293:          IF( UPPER ) THEN
  294:             IF( N.EQ.1 ) THEN
  295:                BI = B( 1, J )
  296:                DX = D( 1 )*X( 1, J )
  297:                WORK( 1 ) = BI - DX
  298:                RWORK( 1 ) = CABS1( BI ) + CABS1( DX )
  299:             ELSE
  300:                BI = B( 1, J )
  301:                DX = D( 1 )*X( 1, J )
  302:                EX = E( 1 )*X( 2, J )
  303:                WORK( 1 ) = BI - DX - EX
  304:                RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) +
  305:      $                      CABS1( E( 1 ) )*CABS1( X( 2, J ) )
  306:                DO 30 I = 2, N - 1
  307:                   BI = B( I, J )
  308:                   CX = DCONJG( E( I-1 ) )*X( I-1, J )
  309:                   DX = D( I )*X( I, J )
  310:                   EX = E( I )*X( I+1, J )
  311:                   WORK( I ) = BI - CX - DX - EX
  312:                   RWORK( I ) = CABS1( BI ) +
  313:      $                         CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) +
  314:      $                         CABS1( DX ) + CABS1( E( I ) )*
  315:      $                         CABS1( X( I+1, J ) )
  316:    30          CONTINUE
  317:                BI = B( N, J )
  318:                CX = DCONJG( E( N-1 ) )*X( N-1, J )
  319:                DX = D( N )*X( N, J )
  320:                WORK( N ) = BI - CX - DX
  321:                RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )*
  322:      $                      CABS1( X( N-1, J ) ) + CABS1( DX )
  323:             END IF
  324:          ELSE
  325:             IF( N.EQ.1 ) THEN
  326:                BI = B( 1, J )
  327:                DX = D( 1 )*X( 1, J )
  328:                WORK( 1 ) = BI - DX
  329:                RWORK( 1 ) = CABS1( BI ) + CABS1( DX )
  330:             ELSE
  331:                BI = B( 1, J )
  332:                DX = D( 1 )*X( 1, J )
  333:                EX = DCONJG( E( 1 ) )*X( 2, J )
  334:                WORK( 1 ) = BI - DX - EX
  335:                RWORK( 1 ) = CABS1( BI ) + CABS1( DX ) +
  336:      $                      CABS1( E( 1 ) )*CABS1( X( 2, J ) )
  337:                DO 40 I = 2, N - 1
  338:                   BI = B( I, J )
  339:                   CX = E( I-1 )*X( I-1, J )
  340:                   DX = D( I )*X( I, J )
  341:                   EX = DCONJG( E( I ) )*X( I+1, J )
  342:                   WORK( I ) = BI - CX - DX - EX
  343:                   RWORK( I ) = CABS1( BI ) +
  344:      $                         CABS1( E( I-1 ) )*CABS1( X( I-1, J ) ) +
  345:      $                         CABS1( DX ) + CABS1( E( I ) )*
  346:      $                         CABS1( X( I+1, J ) )
  347:    40          CONTINUE
  348:                BI = B( N, J )
  349:                CX = E( N-1 )*X( N-1, J )
  350:                DX = D( N )*X( N, J )
  351:                WORK( N ) = BI - CX - DX
  352:                RWORK( N ) = CABS1( BI ) + CABS1( E( N-1 ) )*
  353:      $                      CABS1( X( N-1, J ) ) + CABS1( DX )
  354:             END IF
  355:          END IF
  356: *
  357: *        Compute componentwise relative backward error from formula
  358: *
  359: *        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) )
  360: *
  361: *        where abs(Z) is the componentwise absolute value of the matrix
  362: *        or vector Z.  If the i-th component of the denominator is less
  363: *        than SAFE2, then SAFE1 is added to the i-th components of the
  364: *        numerator and denominator before dividing.
  365: *
  366:          S = ZERO
  367:          DO 50 I = 1, N
  368:             IF( RWORK( I ).GT.SAFE2 ) THEN
  369:                S = MAX( S, CABS1( WORK( I ) ) / RWORK( I ) )
  370:             ELSE
  371:                S = MAX( S, ( CABS1( WORK( I ) )+SAFE1 ) /
  372:      $             ( RWORK( I )+SAFE1 ) )
  373:             END IF
  374:    50    CONTINUE
  375:          BERR( J ) = S
  376: *
  377: *        Test stopping criterion. Continue iterating if
  378: *           1) The residual BERR(J) is larger than machine epsilon, and
  379: *           2) BERR(J) decreased by at least a factor of 2 during the
  380: *              last iteration, and
  381: *           3) At most ITMAX iterations tried.
  382: *
  383:          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
  384:      $       COUNT.LE.ITMAX ) THEN
  385: *
  386: *           Update solution and try again.
  387: *
  388:             CALL ZPTTRS( UPLO, N, 1, DF, EF, WORK, N, INFO )
  389:             CALL ZAXPY( N, DCMPLX( ONE ), WORK, 1, X( 1, J ), 1 )
  390:             LSTRES = BERR( J )
  391:             COUNT = COUNT + 1
  392:             GO TO 20
  393:          END IF
  394: *
  395: *        Bound error from formula
  396: *
  397: *        norm(X - XTRUE) / norm(X) .le. FERR =
  398: *        norm( abs(inv(A))*
  399: *           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X)
  400: *
  401: *        where
  402: *          norm(Z) is the magnitude of the largest component of Z
  403: *          inv(A) is the inverse of A
  404: *          abs(Z) is the componentwise absolute value of the matrix or
  405: *             vector Z
  406: *          NZ is the maximum number of nonzeros in any row of A, plus 1
  407: *          EPS is machine epsilon
  408: *
  409: *        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B))
  410: *        is incremented by SAFE1 if the i-th component of
  411: *        abs(A)*abs(X) + abs(B) is less than SAFE2.
  412: *
  413:          DO 60 I = 1, N
  414:             IF( RWORK( I ).GT.SAFE2 ) THEN
  415:                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I )
  416:             ELSE
  417:                RWORK( I ) = CABS1( WORK( I ) ) + NZ*EPS*RWORK( I ) +
  418:      $                      SAFE1
  419:             END IF
  420:    60    CONTINUE
  421:          IX = IDAMAX( N, RWORK, 1 )
  422:          FERR( J ) = RWORK( IX )
  423: *
  424: *        Estimate the norm of inv(A).
  425: *
  426: *        Solve M(A) * x = e, where M(A) = (m(i,j)) is given by
  427: *
  428: *           m(i,j) =  abs(A(i,j)), i = j,
  429: *           m(i,j) = -abs(A(i,j)), i .ne. j,
  430: *
  431: *        and e = [ 1, 1, ..., 1 ]**T.  Note M(A) = M(L)*D*M(L)**H.
  432: *
  433: *        Solve M(L) * x = e.
  434: *
  435:          RWORK( 1 ) = ONE
  436:          DO 70 I = 2, N
  437:             RWORK( I ) = ONE + RWORK( I-1 )*ABS( EF( I-1 ) )
  438:    70    CONTINUE
  439: *
  440: *        Solve D * M(L)**H * x = b.
  441: *
  442:          RWORK( N ) = RWORK( N ) / DF( N )
  443:          DO 80 I = N - 1, 1, -1
  444:             RWORK( I ) = RWORK( I ) / DF( I ) +
  445:      $                   RWORK( I+1 )*ABS( EF( I ) )
  446:    80    CONTINUE
  447: *
  448: *        Compute norm(inv(A)) = max(x(i)), 1<=i<=n.
  449: *
  450:          IX = IDAMAX( N, RWORK, 1 )
  451:          FERR( J ) = FERR( J )*ABS( RWORK( IX ) )
  452: *
  453: *        Normalize error.
  454: *
  455:          LSTRES = ZERO
  456:          DO 90 I = 1, N
  457:             LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
  458:    90    CONTINUE
  459:          IF( LSTRES.NE.ZERO )
  460:      $      FERR( J ) = FERR( J ) / LSTRES
  461: *
  462:   100 CONTINUE
  463: *
  464:       RETURN
  465: *
  466: *     End of ZPTRFS
  467: *
  468:       END

CVSweb interface <joel.bertrand@systella.fr>