Annotation of rpl/lapack/lapack/ztbrfs.f, revision 1.17

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

CVSweb interface <joel.bertrand@systella.fr>