LAPACK 3.3.0

dgbrfs.f

Go to the documentation of this file.
00001       SUBROUTINE DGBRFS( TRANS, N, KL, KU, NRHS, AB, LDAB, AFB, LDAFB,
00002      $                   IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
00003      $                   INFO )
00004 *
00005 *  -- LAPACK routine (version 3.2) --
00006 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00007 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00008 *     November 2006
00009 *
00010 *     Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH.
00011 *
00012 *     .. Scalar Arguments ..
00013       CHARACTER          TRANS
00014       INTEGER            INFO, KL, KU, LDAB, LDAFB, LDB, LDX, N, NRHS
00015 *     ..
00016 *     .. Array Arguments ..
00017       INTEGER            IPIV( * ), IWORK( * )
00018       DOUBLE PRECISION   AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
00019      $                   BERR( * ), FERR( * ), WORK( * ), X( LDX, * )
00020 *     ..
00021 *
00022 *  Purpose
00023 *  =======
00024 *
00025 *  DGBRFS improves the computed solution to a system of linear
00026 *  equations when the coefficient matrix is banded, and provides
00027 *  error bounds and backward error estimates for the solution.
00028 *
00029 *  Arguments
00030 *  =========
00031 *
00032 *  TRANS   (input) CHARACTER*1
00033 *          Specifies the form of the system of equations:
00034 *          = 'N':  A * X = B     (No transpose)
00035 *          = 'T':  A**T * X = B  (Transpose)
00036 *          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
00037 *
00038 *  N       (input) INTEGER
00039 *          The order of the matrix A.  N >= 0.
00040 *
00041 *  KL      (input) INTEGER
00042 *          The number of subdiagonals within the band of A.  KL >= 0.
00043 *
00044 *  KU      (input) INTEGER
00045 *          The number of superdiagonals within the band of A.  KU >= 0.
00046 *
00047 *  NRHS    (input) INTEGER
00048 *          The number of right hand sides, i.e., the number of columns
00049 *          of the matrices B and X.  NRHS >= 0.
00050 *
00051 *  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N)
00052 *          The original band matrix A, stored in rows 1 to KL+KU+1.
00053 *          The j-th column of A is stored in the j-th column of the
00054 *          array AB as follows:
00055 *          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
00056 *
00057 *  LDAB    (input) INTEGER
00058 *          The leading dimension of the array AB.  LDAB >= KL+KU+1.
00059 *
00060 *  AFB     (input) DOUBLE PRECISION array, dimension (LDAFB,N)
00061 *          Details of the LU factorization of the band matrix A, as
00062 *          computed by DGBTRF.  U is stored as an upper triangular band
00063 *          matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and
00064 *          the multipliers used during the factorization are stored in
00065 *          rows KL+KU+2 to 2*KL+KU+1.
00066 *
00067 *  LDAFB   (input) INTEGER
00068 *          The leading dimension of the array AFB.  LDAFB >= 2*KL*KU+1.
00069 *
00070 *  IPIV    (input) INTEGER array, dimension (N)
00071 *          The pivot indices from DGBTRF; for 1<=i<=N, row i of the
00072 *          matrix was interchanged with row IPIV(i).
00073 *
00074 *  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS)
00075 *          The right hand side matrix B.
00076 *
00077 *  LDB     (input) INTEGER
00078 *          The leading dimension of the array B.  LDB >= max(1,N).
00079 *
00080 *  X       (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS)
00081 *          On entry, the solution matrix X, as computed by DGBTRS.
00082 *          On exit, the improved solution matrix X.
00083 *
00084 *  LDX     (input) INTEGER
00085 *          The leading dimension of the array X.  LDX >= max(1,N).
00086 *
00087 *  FERR    (output) DOUBLE PRECISION array, dimension (NRHS)
00088 *          The estimated forward error bound for each solution vector
00089 *          X(j) (the j-th column of the solution matrix X).
00090 *          If XTRUE is the true solution corresponding to X(j), FERR(j)
00091 *          is an estimated upper bound for the magnitude of the largest
00092 *          element in (X(j) - XTRUE) divided by the magnitude of the
00093 *          largest element in X(j).  The estimate is as reliable as
00094 *          the estimate for RCOND, and is almost always a slight
00095 *          overestimate of the true error.
00096 *
00097 *  BERR    (output) DOUBLE PRECISION array, dimension (NRHS)
00098 *          The componentwise relative backward error of each solution
00099 *          vector X(j) (i.e., the smallest relative change in
00100 *          any element of A or B that makes X(j) an exact solution).
00101 *
00102 *  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N)
00103 *
00104 *  IWORK   (workspace) INTEGER array, dimension (N)
00105 *
00106 *  INFO    (output) INTEGER
00107 *          = 0:  successful exit
00108 *          < 0:  if INFO = -i, the i-th argument had an illegal value
00109 *
00110 *  Internal Parameters
00111 *  ===================
00112 *
00113 *  ITMAX is the maximum number of steps of iterative refinement.
00114 *
00115 *  =====================================================================
00116 *
00117 *     .. Parameters ..
00118       INTEGER            ITMAX
00119       PARAMETER          ( ITMAX = 5 )
00120       DOUBLE PRECISION   ZERO
00121       PARAMETER          ( ZERO = 0.0D+0 )
00122       DOUBLE PRECISION   ONE
00123       PARAMETER          ( ONE = 1.0D+0 )
00124       DOUBLE PRECISION   TWO
00125       PARAMETER          ( TWO = 2.0D+0 )
00126       DOUBLE PRECISION   THREE
00127       PARAMETER          ( THREE = 3.0D+0 )
00128 *     ..
00129 *     .. Local Scalars ..
00130       LOGICAL            NOTRAN
00131       CHARACTER          TRANST
00132       INTEGER            COUNT, I, J, K, KASE, KK, NZ
00133       DOUBLE PRECISION   EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN, XK
00134 *     ..
00135 *     .. Local Arrays ..
00136       INTEGER            ISAVE( 3 )
00137 *     ..
00138 *     .. External Subroutines ..
00139       EXTERNAL           DAXPY, DCOPY, DGBMV, DGBTRS, DLACN2, XERBLA
00140 *     ..
00141 *     .. Intrinsic Functions ..
00142       INTRINSIC          ABS, MAX, MIN
00143 *     ..
00144 *     .. External Functions ..
00145       LOGICAL            LSAME
00146       DOUBLE PRECISION   DLAMCH
00147       EXTERNAL           LSAME, DLAMCH
00148 *     ..
00149 *     .. Executable Statements ..
00150 *
00151 *     Test the input parameters.
00152 *
00153       INFO = 0
00154       NOTRAN = LSAME( TRANS, 'N' )
00155       IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00156      $    LSAME( TRANS, 'C' ) ) THEN
00157          INFO = -1
00158       ELSE IF( N.LT.0 ) THEN
00159          INFO = -2
00160       ELSE IF( KL.LT.0 ) THEN
00161          INFO = -3
00162       ELSE IF( KU.LT.0 ) THEN
00163          INFO = -4
00164       ELSE IF( NRHS.LT.0 ) THEN
00165          INFO = -5
00166       ELSE IF( LDAB.LT.KL+KU+1 ) THEN
00167          INFO = -7
00168       ELSE IF( LDAFB.LT.2*KL+KU+1 ) THEN
00169          INFO = -9
00170       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00171          INFO = -12
00172       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00173          INFO = -14
00174       END IF
00175       IF( INFO.NE.0 ) THEN
00176          CALL XERBLA( 'DGBRFS', -INFO )
00177          RETURN
00178       END IF
00179 *
00180 *     Quick return if possible
00181 *
00182       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00183          DO 10 J = 1, NRHS
00184             FERR( J ) = ZERO
00185             BERR( J ) = ZERO
00186    10    CONTINUE
00187          RETURN
00188       END IF
00189 *
00190       IF( NOTRAN ) THEN
00191          TRANST = 'T'
00192       ELSE
00193          TRANST = 'N'
00194       END IF
00195 *
00196 *     NZ = maximum number of nonzero elements in each row of A, plus 1
00197 *
00198       NZ = MIN( KL+KU+2, N+1 )
00199       EPS = DLAMCH( 'Epsilon' )
00200       SAFMIN = DLAMCH( 'Safe minimum' )
00201       SAFE1 = NZ*SAFMIN
00202       SAFE2 = SAFE1 / EPS
00203 *
00204 *     Do for each right hand side
00205 *
00206       DO 140 J = 1, NRHS
00207 *
00208          COUNT = 1
00209          LSTRES = THREE
00210    20    CONTINUE
00211 *
00212 *        Loop until stopping criterion is satisfied.
00213 *
00214 *        Compute residual R = B - op(A) * X,
00215 *        where op(A) = A, A**T, or A**H, depending on TRANS.
00216 *
00217          CALL DCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
00218          CALL DGBMV( TRANS, N, N, KL, KU, -ONE, AB, LDAB, X( 1, J ), 1,
00219      $               ONE, WORK( N+1 ), 1 )
00220 *
00221 *        Compute componentwise relative backward error from formula
00222 *
00223 *        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
00224 *
00225 *        where abs(Z) is the componentwise absolute value of the matrix
00226 *        or vector Z.  If the i-th component of the denominator is less
00227 *        than SAFE2, then SAFE1 is added to the i-th components of the
00228 *        numerator and denominator before dividing.
00229 *
00230          DO 30 I = 1, N
00231             WORK( I ) = ABS( B( I, J ) )
00232    30    CONTINUE
00233 *
00234 *        Compute abs(op(A))*abs(X) + abs(B).
00235 *
00236          IF( NOTRAN ) THEN
00237             DO 50 K = 1, N
00238                KK = KU + 1 - K
00239                XK = ABS( X( K, J ) )
00240                DO 40 I = MAX( 1, K-KU ), MIN( N, K+KL )
00241                   WORK( I ) = WORK( I ) + ABS( AB( KK+I, K ) )*XK
00242    40          CONTINUE
00243    50       CONTINUE
00244          ELSE
00245             DO 70 K = 1, N
00246                S = ZERO
00247                KK = KU + 1 - K
00248                DO 60 I = MAX( 1, K-KU ), MIN( N, K+KL )
00249                   S = S + ABS( AB( KK+I, K ) )*ABS( X( I, J ) )
00250    60          CONTINUE
00251                WORK( K ) = WORK( K ) + S
00252    70       CONTINUE
00253          END IF
00254          S = ZERO
00255          DO 80 I = 1, N
00256             IF( WORK( I ).GT.SAFE2 ) THEN
00257                S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
00258             ELSE
00259                S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
00260      $             ( WORK( I )+SAFE1 ) )
00261             END IF
00262    80    CONTINUE
00263          BERR( J ) = S
00264 *
00265 *        Test stopping criterion. Continue iterating if
00266 *           1) The residual BERR(J) is larger than machine epsilon, and
00267 *           2) BERR(J) decreased by at least a factor of 2 during the
00268 *              last iteration, and
00269 *           3) At most ITMAX iterations tried.
00270 *
00271          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00272      $       COUNT.LE.ITMAX ) THEN
00273 *
00274 *           Update solution and try again.
00275 *
00276             CALL DGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
00277      $                   WORK( N+1 ), N, INFO )
00278             CALL DAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
00279             LSTRES = BERR( J )
00280             COUNT = COUNT + 1
00281             GO TO 20
00282          END IF
00283 *
00284 *        Bound error from formula
00285 *
00286 *        norm(X - XTRUE) / norm(X) .le. FERR =
00287 *        norm( abs(inv(op(A)))*
00288 *           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
00289 *
00290 *        where
00291 *          norm(Z) is the magnitude of the largest component of Z
00292 *          inv(op(A)) is the inverse of op(A)
00293 *          abs(Z) is the componentwise absolute value of the matrix or
00294 *             vector Z
00295 *          NZ is the maximum number of nonzeros in any row of A, plus 1
00296 *          EPS is machine epsilon
00297 *
00298 *        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
00299 *        is incremented by SAFE1 if the i-th component of
00300 *        abs(op(A))*abs(X) + abs(B) is less than SAFE2.
00301 *
00302 *        Use DLACN2 to estimate the infinity-norm of the matrix
00303 *           inv(op(A)) * diag(W),
00304 *        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
00305 *
00306          DO 90 I = 1, N
00307             IF( WORK( I ).GT.SAFE2 ) THEN
00308                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
00309             ELSE
00310                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
00311             END IF
00312    90    CONTINUE
00313 *
00314          KASE = 0
00315   100    CONTINUE
00316          CALL DLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
00317      $                KASE, ISAVE )
00318          IF( KASE.NE.0 ) THEN
00319             IF( KASE.EQ.1 ) THEN
00320 *
00321 *              Multiply by diag(W)*inv(op(A)**T).
00322 *
00323                CALL DGBTRS( TRANST, N, KL, KU, 1, AFB, LDAFB, IPIV,
00324      $                      WORK( N+1 ), N, INFO )
00325                DO 110 I = 1, N
00326                   WORK( N+I ) = WORK( N+I )*WORK( I )
00327   110          CONTINUE
00328             ELSE
00329 *
00330 *              Multiply by inv(op(A))*diag(W).
00331 *
00332                DO 120 I = 1, N
00333                   WORK( N+I ) = WORK( N+I )*WORK( I )
00334   120          CONTINUE
00335                CALL DGBTRS( TRANS, N, KL, KU, 1, AFB, LDAFB, IPIV,
00336      $                      WORK( N+1 ), N, INFO )
00337             END IF
00338             GO TO 100
00339          END IF
00340 *
00341 *        Normalize error.
00342 *
00343          LSTRES = ZERO
00344          DO 130 I = 1, N
00345             LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
00346   130    CONTINUE
00347          IF( LSTRES.NE.ZERO )
00348      $      FERR( J ) = FERR( J ) / LSTRES
00349 *
00350   140 CONTINUE
00351 *
00352       RETURN
00353 *
00354 *     End of DGBRFS
00355 *
00356       END
 All Files Functions