LAPACK 3.3.0

dtrsv.f

Go to the documentation of this file.
00001       SUBROUTINE DTRSV(UPLO,TRANS,DIAG,N,A,LDA,X,INCX)
00002 *     .. Scalar Arguments ..
00003       INTEGER INCX,LDA,N
00004       CHARACTER DIAG,TRANS,UPLO
00005 *     ..
00006 *     .. Array Arguments ..
00007       DOUBLE PRECISION A(LDA,*),X(*)
00008 *     ..
00009 *
00010 *  Purpose
00011 *  =======
00012 *
00013 *  DTRSV  solves one of the systems of equations
00014 *
00015 *     A*x = b,   or   A'*x = b,
00016 *
00017 *  where b and x are n element vectors and A is an n by n unit, or
00018 *  non-unit, upper or lower triangular matrix.
00019 *
00020 *  No test for singularity or near-singularity is included in this
00021 *  routine. Such tests must be performed before calling this routine.
00022 *
00023 *  Arguments
00024 *  ==========
00025 *
00026 *  UPLO   - CHARACTER*1.
00027 *           On entry, UPLO specifies whether the matrix is an upper or
00028 *           lower triangular matrix as follows:
00029 *
00030 *              UPLO = 'U' or 'u'   A is an upper triangular matrix.
00031 *
00032 *              UPLO = 'L' or 'l'   A is a lower triangular matrix.
00033 *
00034 *           Unchanged on exit.
00035 *
00036 *  TRANS  - CHARACTER*1.
00037 *           On entry, TRANS specifies the equations to be solved as
00038 *           follows:
00039 *
00040 *              TRANS = 'N' or 'n'   A*x = b.
00041 *
00042 *              TRANS = 'T' or 't'   A'*x = b.
00043 *
00044 *              TRANS = 'C' or 'c'   A'*x = b.
00045 *
00046 *           Unchanged on exit.
00047 *
00048 *  DIAG   - CHARACTER*1.
00049 *           On entry, DIAG specifies whether or not A is unit
00050 *           triangular as follows:
00051 *
00052 *              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
00053 *
00054 *              DIAG = 'N' or 'n'   A is not assumed to be unit
00055 *                                  triangular.
00056 *
00057 *           Unchanged on exit.
00058 *
00059 *  N      - INTEGER.
00060 *           On entry, N specifies the order of the matrix A.
00061 *           N must be at least zero.
00062 *           Unchanged on exit.
00063 *
00064 *  A      - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
00065 *           Before entry with  UPLO = 'U' or 'u', the leading n by n
00066 *           upper triangular part of the array A must contain the upper
00067 *           triangular matrix and the strictly lower triangular part of
00068 *           A is not referenced.
00069 *           Before entry with UPLO = 'L' or 'l', the leading n by n
00070 *           lower triangular part of the array A must contain the lower
00071 *           triangular matrix and the strictly upper triangular part of
00072 *           A is not referenced.
00073 *           Note that when  DIAG = 'U' or 'u', the diagonal elements of
00074 *           A are not referenced either, but are assumed to be unity.
00075 *           Unchanged on exit.
00076 *
00077 *  LDA    - INTEGER.
00078 *           On entry, LDA specifies the first dimension of A as declared
00079 *           in the calling (sub) program. LDA must be at least
00080 *           max( 1, n ).
00081 *           Unchanged on exit.
00082 *
00083 *  X      - DOUBLE PRECISION array of dimension at least
00084 *           ( 1 + ( n - 1 )*abs( INCX ) ).
00085 *           Before entry, the incremented array X must contain the n
00086 *           element right-hand side vector b. On exit, X is overwritten
00087 *           with the solution vector x.
00088 *
00089 *  INCX   - INTEGER.
00090 *           On entry, INCX specifies the increment for the elements of
00091 *           X. INCX must not be zero.
00092 *           Unchanged on exit.
00093 *
00094 *
00095 *  Level 2 Blas routine.
00096 *
00097 *  -- Written on 22-October-1986.
00098 *     Jack Dongarra, Argonne National Lab.
00099 *     Jeremy Du Croz, Nag Central Office.
00100 *     Sven Hammarling, Nag Central Office.
00101 *     Richard Hanson, Sandia National Labs.
00102 *
00103 *  =====================================================================
00104 *
00105 *     .. Parameters ..
00106       DOUBLE PRECISION ZERO
00107       PARAMETER (ZERO=0.0D+0)
00108 *     ..
00109 *     .. Local Scalars ..
00110       DOUBLE PRECISION TEMP
00111       INTEGER I,INFO,IX,J,JX,KX
00112       LOGICAL NOUNIT
00113 *     ..
00114 *     .. External Functions ..
00115       LOGICAL LSAME
00116       EXTERNAL LSAME
00117 *     ..
00118 *     .. External Subroutines ..
00119       EXTERNAL XERBLA
00120 *     ..
00121 *     .. Intrinsic Functions ..
00122       INTRINSIC MAX
00123 *     ..
00124 *
00125 *     Test the input parameters.
00126 *
00127       INFO = 0
00128       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
00129           INFO = 1
00130       ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
00131      +         .NOT.LSAME(TRANS,'C')) THEN
00132           INFO = 2
00133       ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
00134           INFO = 3
00135       ELSE IF (N.LT.0) THEN
00136           INFO = 4
00137       ELSE IF (LDA.LT.MAX(1,N)) THEN
00138           INFO = 6
00139       ELSE IF (INCX.EQ.0) THEN
00140           INFO = 8
00141       END IF
00142       IF (INFO.NE.0) THEN
00143           CALL XERBLA('DTRSV ',INFO)
00144           RETURN
00145       END IF
00146 *
00147 *     Quick return if possible.
00148 *
00149       IF (N.EQ.0) RETURN
00150 *
00151       NOUNIT = LSAME(DIAG,'N')
00152 *
00153 *     Set up the start point in X if the increment is not unity. This
00154 *     will be  ( N - 1 )*INCX  too small for descending loops.
00155 *
00156       IF (INCX.LE.0) THEN
00157           KX = 1 - (N-1)*INCX
00158       ELSE IF (INCX.NE.1) THEN
00159           KX = 1
00160       END IF
00161 *
00162 *     Start the operations. In this version the elements of A are
00163 *     accessed sequentially with one pass through A.
00164 *
00165       IF (LSAME(TRANS,'N')) THEN
00166 *
00167 *        Form  x := inv( A )*x.
00168 *
00169           IF (LSAME(UPLO,'U')) THEN
00170               IF (INCX.EQ.1) THEN
00171                   DO 20 J = N,1,-1
00172                       IF (X(J).NE.ZERO) THEN
00173                           IF (NOUNIT) X(J) = X(J)/A(J,J)
00174                           TEMP = X(J)
00175                           DO 10 I = J - 1,1,-1
00176                               X(I) = X(I) - TEMP*A(I,J)
00177    10                     CONTINUE
00178                       END IF
00179    20             CONTINUE
00180               ELSE
00181                   JX = KX + (N-1)*INCX
00182                   DO 40 J = N,1,-1
00183                       IF (X(JX).NE.ZERO) THEN
00184                           IF (NOUNIT) X(JX) = X(JX)/A(J,J)
00185                           TEMP = X(JX)
00186                           IX = JX
00187                           DO 30 I = J - 1,1,-1
00188                               IX = IX - INCX
00189                               X(IX) = X(IX) - TEMP*A(I,J)
00190    30                     CONTINUE
00191                       END IF
00192                       JX = JX - INCX
00193    40             CONTINUE
00194               END IF
00195           ELSE
00196               IF (INCX.EQ.1) THEN
00197                   DO 60 J = 1,N
00198                       IF (X(J).NE.ZERO) THEN
00199                           IF (NOUNIT) X(J) = X(J)/A(J,J)
00200                           TEMP = X(J)
00201                           DO 50 I = J + 1,N
00202                               X(I) = X(I) - TEMP*A(I,J)
00203    50                     CONTINUE
00204                       END IF
00205    60             CONTINUE
00206               ELSE
00207                   JX = KX
00208                   DO 80 J = 1,N
00209                       IF (X(JX).NE.ZERO) THEN
00210                           IF (NOUNIT) X(JX) = X(JX)/A(J,J)
00211                           TEMP = X(JX)
00212                           IX = JX
00213                           DO 70 I = J + 1,N
00214                               IX = IX + INCX
00215                               X(IX) = X(IX) - TEMP*A(I,J)
00216    70                     CONTINUE
00217                       END IF
00218                       JX = JX + INCX
00219    80             CONTINUE
00220               END IF
00221           END IF
00222       ELSE
00223 *
00224 *        Form  x := inv( A' )*x.
00225 *
00226           IF (LSAME(UPLO,'U')) THEN
00227               IF (INCX.EQ.1) THEN
00228                   DO 100 J = 1,N
00229                       TEMP = X(J)
00230                       DO 90 I = 1,J - 1
00231                           TEMP = TEMP - A(I,J)*X(I)
00232    90                 CONTINUE
00233                       IF (NOUNIT) TEMP = TEMP/A(J,J)
00234                       X(J) = TEMP
00235   100             CONTINUE
00236               ELSE
00237                   JX = KX
00238                   DO 120 J = 1,N
00239                       TEMP = X(JX)
00240                       IX = KX
00241                       DO 110 I = 1,J - 1
00242                           TEMP = TEMP - A(I,J)*X(IX)
00243                           IX = IX + INCX
00244   110                 CONTINUE
00245                       IF (NOUNIT) TEMP = TEMP/A(J,J)
00246                       X(JX) = TEMP
00247                       JX = JX + INCX
00248   120             CONTINUE
00249               END IF
00250           ELSE
00251               IF (INCX.EQ.1) THEN
00252                   DO 140 J = N,1,-1
00253                       TEMP = X(J)
00254                       DO 130 I = N,J + 1,-1
00255                           TEMP = TEMP - A(I,J)*X(I)
00256   130                 CONTINUE
00257                       IF (NOUNIT) TEMP = TEMP/A(J,J)
00258                       X(J) = TEMP
00259   140             CONTINUE
00260               ELSE
00261                   KX = KX + (N-1)*INCX
00262                   JX = KX
00263                   DO 160 J = N,1,-1
00264                       TEMP = X(JX)
00265                       IX = KX
00266                       DO 150 I = N,J + 1,-1
00267                           TEMP = TEMP - A(I,J)*X(IX)
00268                           IX = IX - INCX
00269   150                 CONTINUE
00270                       IF (NOUNIT) TEMP = TEMP/A(J,J)
00271                       X(JX) = TEMP
00272                       JX = JX - INCX
00273   160             CONTINUE
00274               END IF
00275           END IF
00276       END IF
00277 *
00278       RETURN
00279 *
00280 *     End of DTRSV .
00281 *
00282       END
 All Files Functions