LAPACK 3.3.0

stpsv.f

Go to the documentation of this file.
00001       SUBROUTINE STPSV(UPLO,TRANS,DIAG,N,AP,X,INCX)
00002 *     .. Scalar Arguments ..
00003       INTEGER INCX,N
00004       CHARACTER DIAG,TRANS,UPLO
00005 *     ..
00006 *     .. Array Arguments ..
00007       REAL AP(*),X(*)
00008 *     ..
00009 *
00010 *  Purpose
00011 *  =======
00012 *
00013 *  STPSV  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, supplied in packed form.
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 *  AP     - REAL             array of DIMENSION at least
00065 *           ( ( n*( n + 1 ) )/2 ).
00066 *           Before entry with  UPLO = 'U' or 'u', the array AP must
00067 *           contain the upper triangular matrix packed sequentially,
00068 *           column by column, so that AP( 1 ) contains a( 1, 1 ),
00069 *           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 )
00070 *           respectively, and so on.
00071 *           Before entry with UPLO = 'L' or 'l', the array AP must
00072 *           contain the lower triangular matrix packed sequentially,
00073 *           column by column, so that AP( 1 ) contains a( 1, 1 ),
00074 *           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 )
00075 *           respectively, and so on.
00076 *           Note that when  DIAG = 'U' or 'u', the diagonal elements of
00077 *           A are not referenced, but are assumed to be unity.
00078 *           Unchanged on exit.
00079 *
00080 *  X      - REAL             array of dimension at least
00081 *           ( 1 + ( n - 1 )*abs( INCX ) ).
00082 *           Before entry, the incremented array X must contain the n
00083 *           element right-hand side vector b. On exit, X is overwritten
00084 *           with the solution vector x.
00085 *
00086 *  INCX   - INTEGER.
00087 *           On entry, INCX specifies the increment for the elements of
00088 *           X. INCX must not be zero.
00089 *           Unchanged on exit.
00090 *
00091 *  Further Details
00092 *  ===============
00093 *
00094 *  Level 2 Blas routine.
00095 *
00096 *  -- Written on 22-October-1986.
00097 *     Jack Dongarra, Argonne National Lab.
00098 *     Jeremy Du Croz, Nag Central Office.
00099 *     Sven Hammarling, Nag Central Office.
00100 *     Richard Hanson, Sandia National Labs.
00101 *
00102 *  =====================================================================
00103 *
00104 *     .. Parameters ..
00105       REAL ZERO
00106       PARAMETER (ZERO=0.0E+0)
00107 *     ..
00108 *     .. Local Scalars ..
00109       REAL TEMP
00110       INTEGER I,INFO,IX,J,JX,K,KK,KX
00111       LOGICAL NOUNIT
00112 *     ..
00113 *     .. External Functions ..
00114       LOGICAL LSAME
00115       EXTERNAL LSAME
00116 *     ..
00117 *     .. External Subroutines ..
00118       EXTERNAL XERBLA
00119 *     ..
00120 *
00121 *     Test the input parameters.
00122 *
00123       INFO = 0
00124       IF (.NOT.LSAME(UPLO,'U') .AND. .NOT.LSAME(UPLO,'L')) THEN
00125           INFO = 1
00126       ELSE IF (.NOT.LSAME(TRANS,'N') .AND. .NOT.LSAME(TRANS,'T') .AND.
00127      +         .NOT.LSAME(TRANS,'C')) THEN
00128           INFO = 2
00129       ELSE IF (.NOT.LSAME(DIAG,'U') .AND. .NOT.LSAME(DIAG,'N')) THEN
00130           INFO = 3
00131       ELSE IF (N.LT.0) THEN
00132           INFO = 4
00133       ELSE IF (INCX.EQ.0) THEN
00134           INFO = 7
00135       END IF
00136       IF (INFO.NE.0) THEN
00137           CALL XERBLA('STPSV ',INFO)
00138           RETURN
00139       END IF
00140 *
00141 *     Quick return if possible.
00142 *
00143       IF (N.EQ.0) RETURN
00144 *
00145       NOUNIT = LSAME(DIAG,'N')
00146 *
00147 *     Set up the start point in X if the increment is not unity. This
00148 *     will be  ( N - 1 )*INCX  too small for descending loops.
00149 *
00150       IF (INCX.LE.0) THEN
00151           KX = 1 - (N-1)*INCX
00152       ELSE IF (INCX.NE.1) THEN
00153           KX = 1
00154       END IF
00155 *
00156 *     Start the operations. In this version the elements of AP are
00157 *     accessed sequentially with one pass through AP.
00158 *
00159       IF (LSAME(TRANS,'N')) THEN
00160 *
00161 *        Form  x := inv( A )*x.
00162 *
00163           IF (LSAME(UPLO,'U')) THEN
00164               KK = (N* (N+1))/2
00165               IF (INCX.EQ.1) THEN
00166                   DO 20 J = N,1,-1
00167                       IF (X(J).NE.ZERO) THEN
00168                           IF (NOUNIT) X(J) = X(J)/AP(KK)
00169                           TEMP = X(J)
00170                           K = KK - 1
00171                           DO 10 I = J - 1,1,-1
00172                               X(I) = X(I) - TEMP*AP(K)
00173                               K = K - 1
00174    10                     CONTINUE
00175                       END IF
00176                       KK = KK - J
00177    20             CONTINUE
00178               ELSE
00179                   JX = KX + (N-1)*INCX
00180                   DO 40 J = N,1,-1
00181                       IF (X(JX).NE.ZERO) THEN
00182                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
00183                           TEMP = X(JX)
00184                           IX = JX
00185                           DO 30 K = KK - 1,KK - J + 1,-1
00186                               IX = IX - INCX
00187                               X(IX) = X(IX) - TEMP*AP(K)
00188    30                     CONTINUE
00189                       END IF
00190                       JX = JX - INCX
00191                       KK = KK - J
00192    40             CONTINUE
00193               END IF
00194           ELSE
00195               KK = 1
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)/AP(KK)
00200                           TEMP = X(J)
00201                           K = KK + 1
00202                           DO 50 I = J + 1,N
00203                               X(I) = X(I) - TEMP*AP(K)
00204                               K = K + 1
00205    50                     CONTINUE
00206                       END IF
00207                       KK = KK + (N-J+1)
00208    60             CONTINUE
00209               ELSE
00210                   JX = KX
00211                   DO 80 J = 1,N
00212                       IF (X(JX).NE.ZERO) THEN
00213                           IF (NOUNIT) X(JX) = X(JX)/AP(KK)
00214                           TEMP = X(JX)
00215                           IX = JX
00216                           DO 70 K = KK + 1,KK + N - J
00217                               IX = IX + INCX
00218                               X(IX) = X(IX) - TEMP*AP(K)
00219    70                     CONTINUE
00220                       END IF
00221                       JX = JX + INCX
00222                       KK = KK + (N-J+1)
00223    80             CONTINUE
00224               END IF
00225           END IF
00226       ELSE
00227 *
00228 *        Form  x := inv( A' )*x.
00229 *
00230           IF (LSAME(UPLO,'U')) THEN
00231               KK = 1
00232               IF (INCX.EQ.1) THEN
00233                   DO 100 J = 1,N
00234                       TEMP = X(J)
00235                       K = KK
00236                       DO 90 I = 1,J - 1
00237                           TEMP = TEMP - AP(K)*X(I)
00238                           K = K + 1
00239    90                 CONTINUE
00240                       IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
00241                       X(J) = TEMP
00242                       KK = KK + J
00243   100             CONTINUE
00244               ELSE
00245                   JX = KX
00246                   DO 120 J = 1,N
00247                       TEMP = X(JX)
00248                       IX = KX
00249                       DO 110 K = KK,KK + J - 2
00250                           TEMP = TEMP - AP(K)*X(IX)
00251                           IX = IX + INCX
00252   110                 CONTINUE
00253                       IF (NOUNIT) TEMP = TEMP/AP(KK+J-1)
00254                       X(JX) = TEMP
00255                       JX = JX + INCX
00256                       KK = KK + J
00257   120             CONTINUE
00258               END IF
00259           ELSE
00260               KK = (N* (N+1))/2
00261               IF (INCX.EQ.1) THEN
00262                   DO 140 J = N,1,-1
00263                       TEMP = X(J)
00264                       K = KK
00265                       DO 130 I = N,J + 1,-1
00266                           TEMP = TEMP - AP(K)*X(I)
00267                           K = K - 1
00268   130                 CONTINUE
00269                       IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
00270                       X(J) = TEMP
00271                       KK = KK - (N-J+1)
00272   140             CONTINUE
00273               ELSE
00274                   KX = KX + (N-1)*INCX
00275                   JX = KX
00276                   DO 160 J = N,1,-1
00277                       TEMP = X(JX)
00278                       IX = KX
00279                       DO 150 K = KK,KK - (N- (J+1)),-1
00280                           TEMP = TEMP - AP(K)*X(IX)
00281                           IX = IX - INCX
00282   150                 CONTINUE
00283                       IF (NOUNIT) TEMP = TEMP/AP(KK-N+J)
00284                       X(JX) = TEMP
00285                       JX = JX - INCX
00286                       KK = KK - (N-J+1)
00287   160             CONTINUE
00288               END IF
00289           END IF
00290       END IF
00291 *
00292       RETURN
00293 *
00294 *     End of STPSV .
00295 *
00296       END
 All Files Functions