3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSPTRS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsptrs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsptrs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsptrs.f">
21 * SUBROUTINE DSPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDB, N, NRHS
27 * .. Array Arguments ..
29 * DOUBLE PRECISION AP( * ), B( LDB, * )
38 *> DSPTRS solves a system of linear equations A*X = B with a real
39 *> symmetric matrix A stored in packed format using the factorization
40 *> A = U*D*U**T or A = L*D*L**T computed by DSPTRF.
48 *> UPLO is CHARACTER*1
49 *> Specifies whether the details of the factorization are stored
50 *> as an upper or lower triangular matrix.
51 *> = 'U': Upper triangular, form is A = U*D*U**T;
52 *> = 'L': Lower triangular, form is A = L*D*L**T.
58 *> The order of the matrix A. N >= 0.
64 *> The number of right hand sides, i.e., the number of columns
65 *> of the matrix B. NRHS >= 0.
70 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
71 *> The block diagonal matrix D and the multipliers used to
72 *> obtain the factor U or L as computed by DSPTRF, stored as a
73 *> packed triangular matrix.
78 *> IPIV is INTEGER array, dimension (N)
79 *> Details of the interchanges and the block structure of D
80 *> as determined by DSPTRF.
85 *> B is DOUBLE PRECISION array, dimension (LDB,NRHS)
86 *> On entry, the right hand side matrix B.
87 *> On exit, the solution matrix X.
93 *> The leading dimension of the array B. LDB >= max(1,N).
99 *> = 0: successful exit
100 *> < 0: if INFO = -i, the i-th argument had an illegal value
106 *> \author Univ. of Tennessee
107 *> \author Univ. of California Berkeley
108 *> \author Univ. of Colorado Denver
111 *> \date November 2011
113 *> \ingroup doubleOTHERcomputational
115 * =====================================================================
116 SUBROUTINE DSPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
118 * -- LAPACK computational routine (version 3.4.0) --
119 * -- LAPACK is a software package provided by Univ. of Tennessee, --
120 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
123 * .. Scalar Arguments ..
125 INTEGER INFO, LDB, N, NRHS
127 * .. Array Arguments ..
129 DOUBLE PRECISION AP( * ), B( LDB, * )
132 * =====================================================================
136 PARAMETER ( ONE = 1.0D+0 )
138 * .. Local Scalars ..
141 DOUBLE PRECISION AK, AKM1, AKM1K, BK, BKM1, DENOM
143 * .. External Functions ..
147 * .. External Subroutines ..
148 EXTERNAL DGEMV, DGER, DSCAL, DSWAP, XERBLA
150 * .. Intrinsic Functions ..
153 * .. Executable Statements ..
156 UPPER = LSAME( UPLO, 'U' )
157 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
159 ELSE IF( N.LT.0 ) THEN
161 ELSE IF( NRHS.LT.0 ) THEN
163 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
167 CALL XERBLA( 'DSPTRS', -INFO )
171 * Quick return if possible
173 IF( N.EQ.0 .OR. NRHS.EQ.0 )
178 * Solve A*X = B, where A = U*D*U**T.
180 * First solve U*D*X = B, overwriting B with X.
182 * K is the main loop index, decreasing from N to 1 in steps of
183 * 1 or 2, depending on the size of the diagonal blocks.
186 KC = N*( N+1 ) / 2 + 1
189 * If K < 1, exit from loop.
195 IF( IPIV( K ).GT.0 ) THEN
197 * 1 x 1 diagonal block
199 * Interchange rows K and IPIV(K).
203 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
205 * Multiply by inv(U(K)), where U(K) is the transformation
206 * stored in column K of A.
208 CALL DGER( K-1, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
211 * Multiply by the inverse of the diagonal block.
213 CALL DSCAL( NRHS, ONE / AP( KC+K-1 ), B( K, 1 ), LDB )
217 * 2 x 2 diagonal block
219 * Interchange rows K-1 and -IPIV(K).
223 $ CALL DSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
225 * Multiply by inv(U(K)), where U(K) is the transformation
226 * stored in columns K-1 and K of A.
228 CALL DGER( K-2, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
230 CALL DGER( K-2, NRHS, -ONE, AP( KC-( K-1 ) ), 1,
231 $ B( K-1, 1 ), LDB, B( 1, 1 ), LDB )
233 * Multiply by the inverse of the diagonal block.
236 AKM1 = AP( KC-1 ) / AKM1K
237 AK = AP( KC+K-1 ) / AKM1K
238 DENOM = AKM1*AK - ONE
240 BKM1 = B( K-1, J ) / AKM1K
241 BK = B( K, J ) / AKM1K
242 B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
243 B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
252 * Next solve U**T*X = B, overwriting B with X.
254 * K is the main loop index, increasing from 1 to N in steps of
255 * 1 or 2, depending on the size of the diagonal blocks.
261 * If K > N, exit from loop.
266 IF( IPIV( K ).GT.0 ) THEN
268 * 1 x 1 diagonal block
270 * Multiply by inv(U**T(K)), where U(K) is the transformation
271 * stored in column K of A.
273 CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, AP( KC ),
274 $ 1, ONE, B( K, 1 ), LDB )
276 * Interchange rows K and IPIV(K).
280 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
285 * 2 x 2 diagonal block
287 * Multiply by inv(U**T(K+1)), where U(K+1) is the transformation
288 * stored in columns K and K+1 of A.
290 CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, AP( KC ),
291 $ 1, ONE, B( K, 1 ), LDB )
292 CALL DGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB,
293 $ AP( KC+K ), 1, ONE, B( K+1, 1 ), LDB )
295 * Interchange rows K and -IPIV(K).
299 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
309 * Solve A*X = B, where A = L*D*L**T.
311 * First solve L*D*X = B, overwriting B with X.
313 * K is the main loop index, increasing from 1 to N in steps of
314 * 1 or 2, depending on the size of the diagonal blocks.
320 * If K > N, exit from loop.
325 IF( IPIV( K ).GT.0 ) THEN
327 * 1 x 1 diagonal block
329 * Interchange rows K and IPIV(K).
333 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
335 * Multiply by inv(L(K)), where L(K) is the transformation
336 * stored in column K of A.
339 $ CALL DGER( N-K, NRHS, -ONE, AP( KC+1 ), 1, B( K, 1 ),
340 $ LDB, B( K+1, 1 ), LDB )
342 * Multiply by the inverse of the diagonal block.
344 CALL DSCAL( NRHS, ONE / AP( KC ), B( K, 1 ), LDB )
349 * 2 x 2 diagonal block
351 * Interchange rows K+1 and -IPIV(K).
355 $ CALL DSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
357 * Multiply by inv(L(K)), where L(K) is the transformation
358 * stored in columns K and K+1 of A.
361 CALL DGER( N-K-1, NRHS, -ONE, AP( KC+2 ), 1, B( K, 1 ),
362 $ LDB, B( K+2, 1 ), LDB )
363 CALL DGER( N-K-1, NRHS, -ONE, AP( KC+N-K+2 ), 1,
364 $ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
367 * Multiply by the inverse of the diagonal block.
370 AKM1 = AP( KC ) / AKM1K
371 AK = AP( KC+N-K+1 ) / AKM1K
372 DENOM = AKM1*AK - ONE
374 BKM1 = B( K, J ) / AKM1K
375 BK = B( K+1, J ) / AKM1K
376 B( K, J ) = ( AK*BKM1-BK ) / DENOM
377 B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
379 KC = KC + 2*( N-K ) + 1
386 * Next solve L**T*X = B, overwriting B with X.
388 * K is the main loop index, decreasing from N to 1 in steps of
389 * 1 or 2, depending on the size of the diagonal blocks.
392 KC = N*( N+1 ) / 2 + 1
395 * If K < 1, exit from loop.
401 IF( IPIV( K ).GT.0 ) THEN
403 * 1 x 1 diagonal block
405 * Multiply by inv(L**T(K)), where L(K) is the transformation
406 * stored in column K of A.
409 $ CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
410 $ LDB, AP( KC+1 ), 1, ONE, B( K, 1 ), LDB )
412 * Interchange rows K and IPIV(K).
416 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
420 * 2 x 2 diagonal block
422 * Multiply by inv(L**T(K-1)), where L(K-1) is the transformation
423 * stored in columns K-1 and K of A.
426 CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
427 $ LDB, AP( KC+1 ), 1, ONE, B( K, 1 ), LDB )
428 CALL DGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
429 $ LDB, AP( KC-( N-K ) ), 1, ONE, B( K-1, 1 ),
433 * Interchange rows K and -IPIV(K).
437 $ CALL DSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )