LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
sgtrfs.f
Go to the documentation of this file.
00001 *> \brief \b SGTRFS
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download SGTRFS + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtrfs.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtrfs.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtrfs.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
00022 *                          IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
00023 *                          INFO )
00024 * 
00025 *       .. Scalar Arguments ..
00026 *       CHARACTER          TRANS
00027 *       INTEGER            INFO, LDB, LDX, N, NRHS
00028 *       ..
00029 *       .. Array Arguments ..
00030 *       INTEGER            IPIV( * ), IWORK( * )
00031 *       REAL               B( LDB, * ), BERR( * ), D( * ), DF( * ),
00032 *      $                   DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
00033 *      $                   FERR( * ), WORK( * ), X( LDX, * )
00034 *       ..
00035 *  
00036 *
00037 *> \par Purpose:
00038 *  =============
00039 *>
00040 *> \verbatim
00041 *>
00042 *> SGTRFS improves the computed solution to a system of linear
00043 *> equations when the coefficient matrix is tridiagonal, and provides
00044 *> error bounds and backward error estimates for the solution.
00045 *> \endverbatim
00046 *
00047 *  Arguments:
00048 *  ==========
00049 *
00050 *> \param[in] TRANS
00051 *> \verbatim
00052 *>          TRANS is CHARACTER*1
00053 *>          Specifies the form of the system of equations:
00054 *>          = 'N':  A * X = B     (No transpose)
00055 *>          = 'T':  A**T * X = B  (Transpose)
00056 *>          = 'C':  A**H * X = B  (Conjugate transpose = Transpose)
00057 *> \endverbatim
00058 *>
00059 *> \param[in] N
00060 *> \verbatim
00061 *>          N is INTEGER
00062 *>          The order of the matrix A.  N >= 0.
00063 *> \endverbatim
00064 *>
00065 *> \param[in] NRHS
00066 *> \verbatim
00067 *>          NRHS is INTEGER
00068 *>          The number of right hand sides, i.e., the number of columns
00069 *>          of the matrix B.  NRHS >= 0.
00070 *> \endverbatim
00071 *>
00072 *> \param[in] DL
00073 *> \verbatim
00074 *>          DL is REAL array, dimension (N-1)
00075 *>          The (n-1) subdiagonal elements of A.
00076 *> \endverbatim
00077 *>
00078 *> \param[in] D
00079 *> \verbatim
00080 *>          D is REAL array, dimension (N)
00081 *>          The diagonal elements of A.
00082 *> \endverbatim
00083 *>
00084 *> \param[in] DU
00085 *> \verbatim
00086 *>          DU is REAL array, dimension (N-1)
00087 *>          The (n-1) superdiagonal elements of A.
00088 *> \endverbatim
00089 *>
00090 *> \param[in] DLF
00091 *> \verbatim
00092 *>          DLF is REAL array, dimension (N-1)
00093 *>          The (n-1) multipliers that define the matrix L from the
00094 *>          LU factorization of A as computed by SGTTRF.
00095 *> \endverbatim
00096 *>
00097 *> \param[in] DF
00098 *> \verbatim
00099 *>          DF is REAL array, dimension (N)
00100 *>          The n diagonal elements of the upper triangular matrix U from
00101 *>          the LU factorization of A.
00102 *> \endverbatim
00103 *>
00104 *> \param[in] DUF
00105 *> \verbatim
00106 *>          DUF is REAL array, dimension (N-1)
00107 *>          The (n-1) elements of the first superdiagonal of U.
00108 *> \endverbatim
00109 *>
00110 *> \param[in] DU2
00111 *> \verbatim
00112 *>          DU2 is REAL array, dimension (N-2)
00113 *>          The (n-2) elements of the second superdiagonal of U.
00114 *> \endverbatim
00115 *>
00116 *> \param[in] IPIV
00117 *> \verbatim
00118 *>          IPIV is INTEGER array, dimension (N)
00119 *>          The pivot indices; for 1 <= i <= n, row i of the matrix was
00120 *>          interchanged with row IPIV(i).  IPIV(i) will always be either
00121 *>          i or i+1; IPIV(i) = i indicates a row interchange was not
00122 *>          required.
00123 *> \endverbatim
00124 *>
00125 *> \param[in] B
00126 *> \verbatim
00127 *>          B is REAL array, dimension (LDB,NRHS)
00128 *>          The right hand side matrix B.
00129 *> \endverbatim
00130 *>
00131 *> \param[in] LDB
00132 *> \verbatim
00133 *>          LDB is INTEGER
00134 *>          The leading dimension of the array B.  LDB >= max(1,N).
00135 *> \endverbatim
00136 *>
00137 *> \param[in,out] X
00138 *> \verbatim
00139 *>          X is REAL array, dimension (LDX,NRHS)
00140 *>          On entry, the solution matrix X, as computed by SGTTRS.
00141 *>          On exit, the improved solution matrix X.
00142 *> \endverbatim
00143 *>
00144 *> \param[in] LDX
00145 *> \verbatim
00146 *>          LDX is INTEGER
00147 *>          The leading dimension of the array X.  LDX >= max(1,N).
00148 *> \endverbatim
00149 *>
00150 *> \param[out] FERR
00151 *> \verbatim
00152 *>          FERR is REAL array, dimension (NRHS)
00153 *>          The estimated forward error bound for each solution vector
00154 *>          X(j) (the j-th column of the solution matrix X).
00155 *>          If XTRUE is the true solution corresponding to X(j), FERR(j)
00156 *>          is an estimated upper bound for the magnitude of the largest
00157 *>          element in (X(j) - XTRUE) divided by the magnitude of the
00158 *>          largest element in X(j).  The estimate is as reliable as
00159 *>          the estimate for RCOND, and is almost always a slight
00160 *>          overestimate of the true error.
00161 *> \endverbatim
00162 *>
00163 *> \param[out] BERR
00164 *> \verbatim
00165 *>          BERR is REAL array, dimension (NRHS)
00166 *>          The componentwise relative backward error of each solution
00167 *>          vector X(j) (i.e., the smallest relative change in
00168 *>          any element of A or B that makes X(j) an exact solution).
00169 *> \endverbatim
00170 *>
00171 *> \param[out] WORK
00172 *> \verbatim
00173 *>          WORK is REAL array, dimension (3*N)
00174 *> \endverbatim
00175 *>
00176 *> \param[out] IWORK
00177 *> \verbatim
00178 *>          IWORK is INTEGER array, dimension (N)
00179 *> \endverbatim
00180 *>
00181 *> \param[out] INFO
00182 *> \verbatim
00183 *>          INFO is INTEGER
00184 *>          = 0:  successful exit
00185 *>          < 0:  if INFO = -i, the i-th argument had an illegal value
00186 *> \endverbatim
00187 *
00188 *> \par Internal Parameters:
00189 *  =========================
00190 *>
00191 *> \verbatim
00192 *>  ITMAX is the maximum number of steps of iterative refinement.
00193 *> \endverbatim
00194 *
00195 *  Authors:
00196 *  ========
00197 *
00198 *> \author Univ. of Tennessee 
00199 *> \author Univ. of California Berkeley 
00200 *> \author Univ. of Colorado Denver 
00201 *> \author NAG Ltd. 
00202 *
00203 *> \date November 2011
00204 *
00205 *> \ingroup realOTHERcomputational
00206 *
00207 *  =====================================================================
00208       SUBROUTINE SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2,
00209      $                   IPIV, B, LDB, X, LDX, FERR, BERR, WORK, IWORK,
00210      $                   INFO )
00211 *
00212 *  -- LAPACK computational routine (version 3.4.0) --
00213 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00214 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00215 *     November 2011
00216 *
00217 *     .. Scalar Arguments ..
00218       CHARACTER          TRANS
00219       INTEGER            INFO, LDB, LDX, N, NRHS
00220 *     ..
00221 *     .. Array Arguments ..
00222       INTEGER            IPIV( * ), IWORK( * )
00223       REAL               B( LDB, * ), BERR( * ), D( * ), DF( * ),
00224      $                   DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
00225      $                   FERR( * ), WORK( * ), X( LDX, * )
00226 *     ..
00227 *
00228 *  =====================================================================
00229 *
00230 *     .. Parameters ..
00231       INTEGER            ITMAX
00232       PARAMETER          ( ITMAX = 5 )
00233       REAL               ZERO, ONE
00234       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
00235       REAL               TWO
00236       PARAMETER          ( TWO = 2.0E+0 )
00237       REAL               THREE
00238       PARAMETER          ( THREE = 3.0E+0 )
00239 *     ..
00240 *     .. Local Scalars ..
00241       LOGICAL            NOTRAN
00242       CHARACTER          TRANSN, TRANST
00243       INTEGER            COUNT, I, J, KASE, NZ
00244       REAL               EPS, LSTRES, S, SAFE1, SAFE2, SAFMIN
00245 *     ..
00246 *     .. Local Arrays ..
00247       INTEGER            ISAVE( 3 )
00248 *     ..
00249 *     .. External Subroutines ..
00250       EXTERNAL           SAXPY, SCOPY, SGTTRS, SLACN2, SLAGTM, XERBLA
00251 *     ..
00252 *     .. Intrinsic Functions ..
00253       INTRINSIC          ABS, MAX
00254 *     ..
00255 *     .. External Functions ..
00256       LOGICAL            LSAME
00257       REAL               SLAMCH
00258       EXTERNAL           LSAME, SLAMCH
00259 *     ..
00260 *     .. Executable Statements ..
00261 *
00262 *     Test the input parameters.
00263 *
00264       INFO = 0
00265       NOTRAN = LSAME( TRANS, 'N' )
00266       IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
00267      $    LSAME( TRANS, 'C' ) ) THEN
00268          INFO = -1
00269       ELSE IF( N.LT.0 ) THEN
00270          INFO = -2
00271       ELSE IF( NRHS.LT.0 ) THEN
00272          INFO = -3
00273       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
00274          INFO = -13
00275       ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
00276          INFO = -15
00277       END IF
00278       IF( INFO.NE.0 ) THEN
00279          CALL XERBLA( 'SGTRFS', -INFO )
00280          RETURN
00281       END IF
00282 *
00283 *     Quick return if possible
00284 *
00285       IF( N.EQ.0 .OR. NRHS.EQ.0 ) THEN
00286          DO 10 J = 1, NRHS
00287             FERR( J ) = ZERO
00288             BERR( J ) = ZERO
00289    10    CONTINUE
00290          RETURN
00291       END IF
00292 *
00293       IF( NOTRAN ) THEN
00294          TRANSN = 'N'
00295          TRANST = 'T'
00296       ELSE
00297          TRANSN = 'T'
00298          TRANST = 'N'
00299       END IF
00300 *
00301 *     NZ = maximum number of nonzero elements in each row of A, plus 1
00302 *
00303       NZ = 4
00304       EPS = SLAMCH( 'Epsilon' )
00305       SAFMIN = SLAMCH( 'Safe minimum' )
00306       SAFE1 = NZ*SAFMIN
00307       SAFE2 = SAFE1 / EPS
00308 *
00309 *     Do for each right hand side
00310 *
00311       DO 110 J = 1, NRHS
00312 *
00313          COUNT = 1
00314          LSTRES = THREE
00315    20    CONTINUE
00316 *
00317 *        Loop until stopping criterion is satisfied.
00318 *
00319 *        Compute residual R = B - op(A) * X,
00320 *        where op(A) = A, A**T, or A**H, depending on TRANS.
00321 *
00322          CALL SCOPY( N, B( 1, J ), 1, WORK( N+1 ), 1 )
00323          CALL SLAGTM( TRANS, N, 1, -ONE, DL, D, DU, X( 1, J ), LDX, ONE,
00324      $                WORK( N+1 ), N )
00325 *
00326 *        Compute abs(op(A))*abs(x) + abs(b) for use in the backward
00327 *        error bound.
00328 *
00329          IF( NOTRAN ) THEN
00330             IF( N.EQ.1 ) THEN
00331                WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) )
00332             ELSE
00333                WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) ) +
00334      $                     ABS( DU( 1 )*X( 2, J ) )
00335                DO 30 I = 2, N - 1
00336                   WORK( I ) = ABS( B( I, J ) ) +
00337      $                        ABS( DL( I-1 )*X( I-1, J ) ) +
00338      $                        ABS( D( I )*X( I, J ) ) +
00339      $                        ABS( DU( I )*X( I+1, J ) )
00340    30          CONTINUE
00341                WORK( N ) = ABS( B( N, J ) ) +
00342      $                     ABS( DL( N-1 )*X( N-1, J ) ) +
00343      $                     ABS( D( N )*X( N, J ) )
00344             END IF
00345          ELSE
00346             IF( N.EQ.1 ) THEN
00347                WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) )
00348             ELSE
00349                WORK( 1 ) = ABS( B( 1, J ) ) + ABS( D( 1 )*X( 1, J ) ) +
00350      $                     ABS( DL( 1 )*X( 2, J ) )
00351                DO 40 I = 2, N - 1
00352                   WORK( I ) = ABS( B( I, J ) ) +
00353      $                        ABS( DU( I-1 )*X( I-1, J ) ) +
00354      $                        ABS( D( I )*X( I, J ) ) +
00355      $                        ABS( DL( I )*X( I+1, J ) )
00356    40          CONTINUE
00357                WORK( N ) = ABS( B( N, J ) ) +
00358      $                     ABS( DU( N-1 )*X( N-1, J ) ) +
00359      $                     ABS( D( N )*X( N, J ) )
00360             END IF
00361          END IF
00362 *
00363 *        Compute componentwise relative backward error from formula
00364 *
00365 *        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) )
00366 *
00367 *        where abs(Z) is the componentwise absolute value of the matrix
00368 *        or vector Z.  If the i-th component of the denominator is less
00369 *        than SAFE2, then SAFE1 is added to the i-th components of the
00370 *        numerator and denominator before dividing.
00371 *
00372          S = ZERO
00373          DO 50 I = 1, N
00374             IF( WORK( I ).GT.SAFE2 ) THEN
00375                S = MAX( S, ABS( WORK( N+I ) ) / WORK( I ) )
00376             ELSE
00377                S = MAX( S, ( ABS( WORK( N+I ) )+SAFE1 ) /
00378      $             ( WORK( I )+SAFE1 ) )
00379             END IF
00380    50    CONTINUE
00381          BERR( J ) = S
00382 *
00383 *        Test stopping criterion. Continue iterating if
00384 *           1) The residual BERR(J) is larger than machine epsilon, and
00385 *           2) BERR(J) decreased by at least a factor of 2 during the
00386 *              last iteration, and
00387 *           3) At most ITMAX iterations tried.
00388 *
00389          IF( BERR( J ).GT.EPS .AND. TWO*BERR( J ).LE.LSTRES .AND.
00390      $       COUNT.LE.ITMAX ) THEN
00391 *
00392 *           Update solution and try again.
00393 *
00394             CALL SGTTRS( TRANS, N, 1, DLF, DF, DUF, DU2, IPIV,
00395      $                   WORK( N+1 ), N, INFO )
00396             CALL SAXPY( N, ONE, WORK( N+1 ), 1, X( 1, J ), 1 )
00397             LSTRES = BERR( J )
00398             COUNT = COUNT + 1
00399             GO TO 20
00400          END IF
00401 *
00402 *        Bound error from formula
00403 *
00404 *        norm(X - XTRUE) / norm(X) .le. FERR =
00405 *        norm( abs(inv(op(A)))*
00406 *           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X)
00407 *
00408 *        where
00409 *          norm(Z) is the magnitude of the largest component of Z
00410 *          inv(op(A)) is the inverse of op(A)
00411 *          abs(Z) is the componentwise absolute value of the matrix or
00412 *             vector Z
00413 *          NZ is the maximum number of nonzeros in any row of A, plus 1
00414 *          EPS is machine epsilon
00415 *
00416 *        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B))
00417 *        is incremented by SAFE1 if the i-th component of
00418 *        abs(op(A))*abs(X) + abs(B) is less than SAFE2.
00419 *
00420 *        Use SLACN2 to estimate the infinity-norm of the matrix
00421 *           inv(op(A)) * diag(W),
00422 *        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) )))
00423 *
00424          DO 60 I = 1, N
00425             IF( WORK( I ).GT.SAFE2 ) THEN
00426                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I )
00427             ELSE
00428                WORK( I ) = ABS( WORK( N+I ) ) + NZ*EPS*WORK( I ) + SAFE1
00429             END IF
00430    60    CONTINUE
00431 *
00432          KASE = 0
00433    70    CONTINUE
00434          CALL SLACN2( N, WORK( 2*N+1 ), WORK( N+1 ), IWORK, FERR( J ),
00435      $                KASE, ISAVE )
00436          IF( KASE.NE.0 ) THEN
00437             IF( KASE.EQ.1 ) THEN
00438 *
00439 *              Multiply by diag(W)*inv(op(A)**T).
00440 *
00441                CALL SGTTRS( TRANST, N, 1, DLF, DF, DUF, DU2, IPIV,
00442      $                      WORK( N+1 ), N, INFO )
00443                DO 80 I = 1, N
00444                   WORK( N+I ) = WORK( I )*WORK( N+I )
00445    80          CONTINUE
00446             ELSE
00447 *
00448 *              Multiply by inv(op(A))*diag(W).
00449 *
00450                DO 90 I = 1, N
00451                   WORK( N+I ) = WORK( I )*WORK( N+I )
00452    90          CONTINUE
00453                CALL SGTTRS( TRANSN, N, 1, DLF, DF, DUF, DU2, IPIV,
00454      $                      WORK( N+1 ), N, INFO )
00455             END IF
00456             GO TO 70
00457          END IF
00458 *
00459 *        Normalize error.
00460 *
00461          LSTRES = ZERO
00462          DO 100 I = 1, N
00463             LSTRES = MAX( LSTRES, ABS( X( I, J ) ) )
00464   100    CONTINUE
00465          IF( LSTRES.NE.ZERO )
00466      $      FERR( J ) = FERR( J ) / LSTRES
00467 *
00468   110 CONTINUE
00469 *
00470       RETURN
00471 *
00472 *     End of SGTRFS
00473 *
00474       END
 All Files Functions