2
SUBROUTINE STRSV (UPLO, TRANS, DIAG, N, A, LDA, X, INCX)
3
C***BEGIN PROLOGUE STRSV
4
C***PURPOSE Solve a real triangular system of linear equations.
5
C***LIBRARY SLATEC (BLAS)
7
C***TYPE SINGLE PRECISION (STRSV-S, DTRSV-D, CTRSV-C)
8
C***KEYWORDS LEVEL 2 BLAS, LINEAR ALGEBRA
9
C***AUTHOR Dongarra, J. J., (ANL)
11
C Hammarling, S., (NAG)
12
C Hanson, R. J., (SNLA)
15
C STRSV solves one of the systems of equations
17
C A*x = b, or A'*x = b,
19
C where b and x are n element vectors and A is an n by n unit, or
20
C non-unit, upper or lower triangular matrix.
22
C No test for singularity or near-singularity is included in this
23
C routine. Such tests must be performed before calling this routine.
29
C On entry, UPLO specifies whether the matrix is an upper or
30
C lower triangular matrix as follows:
32
C UPLO = 'U' or 'u' A is an upper triangular matrix.
34
C UPLO = 'L' or 'l' A is a lower triangular matrix.
38
C TRANS - CHARACTER*1.
39
C On entry, TRANS specifies the equations to be solved as
42
C TRANS = 'N' or 'n' A*x = b.
44
C TRANS = 'T' or 't' A'*x = b.
46
C TRANS = 'C' or 'c' A'*x = b.
51
C On entry, DIAG specifies whether or not A is unit
52
C triangular as follows:
54
C DIAG = 'U' or 'u' A is assumed to be unit triangular.
56
C DIAG = 'N' or 'n' A is not assumed to be unit
62
C On entry, N specifies the order of the matrix A.
63
C N must be at least zero.
66
C A - REAL array of DIMENSION ( LDA, n).
67
C Before entry with UPLO = 'U' or 'u', the leading n by n
68
C upper triangular part of the array A must contain the upper
69
C triangular matrix and the strictly lower triangular part of
70
C A is not referenced.
71
C Before entry with UPLO = 'L' or 'l', the leading n by n
72
C lower triangular part of the array A must contain the lower
73
C triangular matrix and the strictly upper triangular part of
74
C A is not referenced.
75
C Note that when DIAG = 'U' or 'u', the diagonal elements of
76
C A are not referenced either, but are assumed to be unity.
80
C On entry, LDA specifies the first dimension of A as declared
81
C in the calling (sub) program. LDA must be at least
85
C X - REAL array of dimension at least
86
C ( 1 + ( n - 1 )*abs( INCX ) ).
87
C Before entry, the incremented array X must contain the n
88
C element right-hand side vector b. On exit, X is overwritten
89
C with the solution vector x.
92
C On entry, INCX specifies the increment for the elements of
93
C X. INCX must not be zero.
96
C***REFERENCES Dongarra, J. J., Du Croz, J., Hammarling, S., and
97
C Hanson, R. J. An extended set of Fortran basic linear
98
C algebra subprograms. ACM TOMS, Vol. 14, No. 1,
99
C pp. 1-17, March 1988.
100
C***ROUTINES CALLED LSAME, XERBLA
101
C***REVISION HISTORY (YYMMDD)
102
C 861022 DATE WRITTEN
103
C 910605 Modified to meet SLATEC prologue standards. Only comment
104
C lines were modified. (BKS)
105
C***END PROLOGUE STRSV
106
C .. Scalar Arguments ..
108
CHARACTER*1 DIAG, TRANS, UPLO
109
C .. Array Arguments ..
110
REAL A( LDA, * ), X( * )
113
PARAMETER ( ZERO = 0.0E+0 )
114
C .. Local Scalars ..
116
INTEGER I, INFO, IX, J, JX, KX
118
C .. External Functions ..
121
C .. External Subroutines ..
123
C .. Intrinsic Functions ..
125
C***FIRST EXECUTABLE STATEMENT STRSV
127
C Test the input parameters.
130
IF ( .NOT.LSAME( UPLO , 'U' ).AND.
131
$ .NOT.LSAME( UPLO , 'L' ) )THEN
133
ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND.
134
$ .NOT.LSAME( TRANS, 'T' ).AND.
135
$ .NOT.LSAME( TRANS, 'C' ) )THEN
137
ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND.
138
$ .NOT.LSAME( DIAG , 'N' ) )THEN
140
ELSE IF( N.LT.0 )THEN
142
ELSE IF( LDA.LT.MAX( 1, N ) )THEN
144
ELSE IF( INCX.EQ.0 )THEN
148
CALL XERBLA( 'STRSV ', INFO )
152
C Quick return if possible.
157
NOUNIT = LSAME( DIAG, 'N' )
159
C Set up the start point in X if the increment is not unity. This
160
C will be ( N - 1 )*INCX too small for descending loops.
163
KX = 1 - ( N - 1 )*INCX
164
ELSE IF( INCX.NE.1 )THEN
168
C Start the operations. In this version the elements of A are
169
C accessed sequentially with one pass through A.
171
IF( LSAME( TRANS, 'N' ) )THEN
173
C Form x := inv( A )*x.
175
IF( LSAME( UPLO, 'U' ) )THEN
178
IF( X( J ).NE.ZERO )THEN
180
$ X( J ) = X( J )/A( J, J )
182
DO 10, I = J - 1, 1, -1
183
X( I ) = X( I ) - TEMP*A( I, J )
188
JX = KX + ( N - 1 )*INCX
190
IF( X( JX ).NE.ZERO )THEN
192
$ X( JX ) = X( JX )/A( J, J )
195
DO 30, I = J - 1, 1, -1
197
X( IX ) = X( IX ) - TEMP*A( I, J )
206
IF( X( J ).NE.ZERO )THEN
208
$ X( J ) = X( J )/A( J, J )
211
X( I ) = X( I ) - TEMP*A( I, J )
218
IF( X( JX ).NE.ZERO )THEN
220
$ X( JX ) = X( JX )/A( J, J )
225
X( IX ) = X( IX ) - TEMP*A( I, J )
234
C Form x := inv( A' )*x.
236
IF( LSAME( UPLO, 'U' ) )THEN
241
TEMP = TEMP - A( I, J )*X( I )
244
$ TEMP = TEMP/A( J, J )
253
TEMP = TEMP - A( I, J )*X( IX )
257
$ TEMP = TEMP/A( J, J )
266
DO 130, I = N, J + 1, -1
267
TEMP = TEMP - A( I, J )*X( I )
270
$ TEMP = TEMP/A( J, J )
274
KX = KX + ( N - 1 )*INCX
279
DO 150, I = N, J + 1, -1
280
TEMP = TEMP - A( I, J )*X( IX )
284
$ TEMP = TEMP/A( J, J )