1 *> \brief <b> SGTSVX computes the solution to system of linear equations A * X = B for GT matrices <b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGTSVX + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgtsvx.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgtsvx.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgtsvx.f">
21 * SUBROUTINE SGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF,
22 * DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR,
25 * .. Scalar Arguments ..
26 * CHARACTER FACT, TRANS
27 * INTEGER INFO, LDB, LDX, N, NRHS
30 * .. Array Arguments ..
31 * INTEGER IPIV( * ), IWORK( * )
32 * REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
33 * $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
34 * $ FERR( * ), WORK( * ), X( LDX, * )
43 *> SGTSVX uses the LU factorization to compute the solution to a real
44 *> system of linear equations A * X = B or A**T * X = B,
45 *> where A is a tridiagonal matrix of order N and X and B are N-by-NRHS
48 *> Error bounds on the solution and a condition estimate are also
57 *> The following steps are performed:
59 *> 1. If FACT = 'N', the LU decomposition is used to factor the matrix A
60 *> as A = L * U, where L is a product of permutation and unit lower
61 *> bidiagonal matrices and U is upper triangular with nonzeros in
62 *> only the main diagonal and first two superdiagonals.
64 *> 2. If some U(i,i)=0, so that U is exactly singular, then the routine
65 *> returns with INFO = i. Otherwise, the factored form of A is used
66 *> to estimate the condition number of the matrix A. If the
67 *> reciprocal of the condition number is less than machine precision,
68 *> INFO = N+1 is returned as a warning, but the routine still goes on
69 *> to solve for X and compute error bounds as described below.
71 *> 3. The system of equations is solved for X using the factored form
74 *> 4. Iterative refinement is applied to improve the computed solution
75 *> matrix and calculate error bounds and backward error estimates
84 *> FACT is CHARACTER*1
85 *> Specifies whether or not the factored form of A has been
87 *> = 'F': DLF, DF, DUF, DU2, and IPIV contain the factored
88 *> form of A; DL, D, DU, DLF, DF, DUF, DU2 and IPIV
89 *> will not be modified.
90 *> = 'N': The matrix will be copied to DLF, DF, and DUF
96 *> TRANS is CHARACTER*1
97 *> Specifies the form of the system of equations:
98 *> = 'N': A * X = B (No transpose)
99 *> = 'T': A**T * X = B (Transpose)
100 *> = 'C': A**H * X = B (Conjugate transpose = Transpose)
106 *> The order of the matrix A. N >= 0.
112 *> The number of right hand sides, i.e., the number of columns
113 *> of the matrix B. NRHS >= 0.
118 *> DL is REAL array, dimension (N-1)
119 *> The (n-1) subdiagonal elements of A.
124 *> D is REAL array, dimension (N)
125 *> The n diagonal elements of A.
130 *> DU is REAL array, dimension (N-1)
131 *> The (n-1) superdiagonal elements of A.
134 *> \param[in,out] DLF
136 *> DLF is REAL array, dimension (N-1)
137 *> If FACT = 'F', then DLF is an input argument and on entry
138 *> contains the (n-1) multipliers that define the matrix L from
139 *> the LU factorization of A as computed by SGTTRF.
141 *> If FACT = 'N', then DLF is an output argument and on exit
142 *> contains the (n-1) multipliers that define the matrix L from
143 *> the LU factorization of A.
148 *> DF is REAL array, dimension (N)
149 *> If FACT = 'F', then DF is an input argument and on entry
150 *> contains the n diagonal elements of the upper triangular
151 *> matrix U from the LU factorization of A.
153 *> If FACT = 'N', then DF is an output argument and on exit
154 *> contains the n diagonal elements of the upper triangular
155 *> matrix U from the LU factorization of A.
158 *> \param[in,out] DUF
160 *> DUF is REAL array, dimension (N-1)
161 *> If FACT = 'F', then DUF is an input argument and on entry
162 *> contains the (n-1) elements of the first superdiagonal of U.
164 *> If FACT = 'N', then DUF is an output argument and on exit
165 *> contains the (n-1) elements of the first superdiagonal of U.
168 *> \param[in,out] DU2
170 *> DU2 is REAL array, dimension (N-2)
171 *> If FACT = 'F', then DU2 is an input argument and on entry
172 *> contains the (n-2) elements of the second superdiagonal of
175 *> If FACT = 'N', then DU2 is an output argument and on exit
176 *> contains the (n-2) elements of the second superdiagonal of
180 *> \param[in,out] IPIV
182 *> IPIV is INTEGER array, dimension (N)
183 *> If FACT = 'F', then IPIV is an input argument and on entry
184 *> contains the pivot indices from the LU factorization of A as
185 *> computed by SGTTRF.
187 *> If FACT = 'N', then IPIV is an output argument and on exit
188 *> contains the pivot indices from the LU factorization of A;
189 *> row i of the matrix was interchanged with row IPIV(i).
190 *> IPIV(i) will always be either i or i+1; IPIV(i) = i indicates
191 *> a row interchange was not required.
196 *> B is REAL array, dimension (LDB,NRHS)
197 *> The N-by-NRHS right hand side matrix B.
203 *> The leading dimension of the array B. LDB >= max(1,N).
208 *> X is REAL array, dimension (LDX,NRHS)
209 *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X.
215 *> The leading dimension of the array X. LDX >= max(1,N).
221 *> The estimate of the reciprocal condition number of the matrix
222 *> A. If RCOND is less than the machine precision (in
223 *> particular, if RCOND = 0), the matrix is singular to working
224 *> precision. This condition is indicated by a return code of
230 *> FERR is REAL array, dimension (NRHS)
231 *> The estimated forward error bound for each solution vector
232 *> X(j) (the j-th column of the solution matrix X).
233 *> If XTRUE is the true solution corresponding to X(j), FERR(j)
234 *> is an estimated upper bound for the magnitude of the largest
235 *> element in (X(j) - XTRUE) divided by the magnitude of the
236 *> largest element in X(j). The estimate is as reliable as
237 *> the estimate for RCOND, and is almost always a slight
238 *> overestimate of the true error.
243 *> BERR is REAL array, dimension (NRHS)
244 *> The componentwise relative backward error of each solution
245 *> vector X(j) (i.e., the smallest relative change in
246 *> any element of A or B that makes X(j) an exact solution).
251 *> WORK is REAL array, dimension (3*N)
256 *> IWORK is INTEGER array, dimension (N)
262 *> = 0: successful exit
263 *> < 0: if INFO = -i, the i-th argument had an illegal value
264 *> > 0: if INFO = i, and i is
265 *> <= N: U(i,i) is exactly zero. The factorization
266 *> has not been completed unless i = N, but the
267 *> factor U is exactly singular, so the solution
268 *> and error bounds could not be computed.
269 *> RCOND = 0 is returned.
270 *> = N+1: U is nonsingular, but RCOND is less than machine
271 *> precision, meaning that the matrix is singular
272 *> to working precision. Nevertheless, the
273 *> solution and error bounds are computed because
274 *> there are a number of situations where the
275 *> computed solution can be more accurate than the
276 *> value of RCOND would suggest.
282 *> \author Univ. of Tennessee
283 *> \author Univ. of California Berkeley
284 *> \author Univ. of Colorado Denver
287 *> \date September 2012
289 *> \ingroup realGTsolve
291 * =====================================================================
292 SUBROUTINE SGTSVX( FACT, TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF,
293 $ DU2, IPIV, B, LDB, X, LDX, RCOND, FERR, BERR,
294 $ WORK, IWORK, INFO )
296 * -- LAPACK driver routine (version 3.4.2) --
297 * -- LAPACK is a software package provided by Univ. of Tennessee, --
298 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
301 * .. Scalar Arguments ..
302 CHARACTER FACT, TRANS
303 INTEGER INFO, LDB, LDX, N, NRHS
306 * .. Array Arguments ..
307 INTEGER IPIV( * ), IWORK( * )
308 REAL B( LDB, * ), BERR( * ), D( * ), DF( * ),
309 $ DL( * ), DLF( * ), DU( * ), DU2( * ), DUF( * ),
310 $ FERR( * ), WORK( * ), X( LDX, * )
313 * =====================================================================
317 PARAMETER ( ZERO = 0.0E+0 )
319 * .. Local Scalars ..
320 LOGICAL NOFACT, NOTRAN
324 * .. External Functions ..
327 EXTERNAL LSAME, SLAMCH, SLANGT
329 * .. External Subroutines ..
330 EXTERNAL SCOPY, SGTCON, SGTRFS, SGTTRF, SGTTRS, SLACPY,
333 * .. Intrinsic Functions ..
336 * .. Executable Statements ..
339 NOFACT = LSAME( FACT, 'N' )
340 NOTRAN = LSAME( TRANS, 'N' )
341 IF( .NOT.NOFACT .AND. .NOT.LSAME( FACT, 'F' ) ) THEN
343 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
344 $ LSAME( TRANS, 'C' ) ) THEN
346 ELSE IF( N.LT.0 ) THEN
348 ELSE IF( NRHS.LT.0 ) THEN
350 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
352 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
356 CALL XERBLA( 'SGTSVX', -INFO )
362 * Compute the LU factorization of A.
364 CALL SCOPY( N, D, 1, DF, 1 )
366 CALL SCOPY( N-1, DL, 1, DLF, 1 )
367 CALL SCOPY( N-1, DU, 1, DUF, 1 )
369 CALL SGTTRF( N, DLF, DF, DUF, DU2, IPIV, INFO )
371 * Return if INFO is non-zero.
379 * Compute the norm of the matrix A.
386 ANORM = SLANGT( NORM, N, DL, D, DU )
388 * Compute the reciprocal of the condition number of A.
390 CALL SGTCON( NORM, N, DLF, DF, DUF, DU2, IPIV, ANORM, RCOND, WORK,
393 * Compute the solution vectors X.
395 CALL SLACPY( 'Full', N, NRHS, B, LDB, X, LDX )
396 CALL SGTTRS( TRANS, N, NRHS, DLF, DF, DUF, DU2, IPIV, X, LDX,
399 * Use iterative refinement to improve the computed solutions and
400 * compute error bounds and backward error estimates for them.
402 CALL SGTRFS( TRANS, N, NRHS, DL, D, DU, DLF, DF, DUF, DU2, IPIV,
403 $ B, LDB, X, LDX, FERR, BERR, WORK, IWORK, INFO )
405 * Set INFO = N+1 if the matrix is singular to working precision.
407 IF( RCOND.LT.SLAMCH( 'Epsilon' ) )