3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZSYTRS + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsytrs.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsytrs.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsytrs.f">
21 * SUBROUTINE ZSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LDB, N, NRHS
27 * .. Array Arguments ..
29 * COMPLEX*16 A( LDA, * ), B( LDB, * )
38 *> ZSYTRS solves a system of linear equations A*X = B with a complex
39 *> symmetric matrix A using the factorization A = U*D*U**T or
40 *> A = L*D*L**T computed by ZSYTRF.
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 *> A is COMPLEX*16 array, dimension (LDA,N)
71 *> The block diagonal matrix D and the multipliers used to
72 *> obtain the factor U or L as computed by ZSYTRF.
78 *> The leading dimension of the array A. LDA >= max(1,N).
83 *> IPIV is INTEGER array, dimension (N)
84 *> Details of the interchanges and the block structure of D
85 *> as determined by ZSYTRF.
90 *> B is COMPLEX*16 array, dimension (LDB,NRHS)
91 *> On entry, the right hand side matrix B.
92 *> On exit, the solution matrix X.
98 *> The leading dimension of the array B. LDB >= max(1,N).
104 *> = 0: successful exit
105 *> < 0: if INFO = -i, the i-th argument had an illegal value
111 *> \author Univ. of Tennessee
112 *> \author Univ. of California Berkeley
113 *> \author Univ. of Colorado Denver
116 *> \date November 2011
118 *> \ingroup complex16SYcomputational
120 * =====================================================================
121 SUBROUTINE ZSYTRS( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, INFO )
123 * -- LAPACK computational routine (version 3.4.0) --
124 * -- LAPACK is a software package provided by Univ. of Tennessee, --
125 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
128 * .. Scalar Arguments ..
130 INTEGER INFO, LDA, LDB, N, NRHS
132 * .. Array Arguments ..
134 COMPLEX*16 A( LDA, * ), B( LDB, * )
137 * =====================================================================
141 PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) )
143 * .. Local Scalars ..
146 COMPLEX*16 AK, AKM1, AKM1K, BK, BKM1, DENOM
148 * .. External Functions ..
152 * .. External Subroutines ..
153 EXTERNAL XERBLA, ZGEMV, ZGERU, ZSCAL, ZSWAP
155 * .. Intrinsic Functions ..
158 * .. Executable Statements ..
161 UPPER = LSAME( UPLO, 'U' )
162 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
164 ELSE IF( N.LT.0 ) THEN
166 ELSE IF( NRHS.LT.0 ) THEN
168 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
170 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
174 CALL XERBLA( 'ZSYTRS', -INFO )
178 * Quick return if possible
180 IF( N.EQ.0 .OR. NRHS.EQ.0 )
185 * Solve A*X = B, where A = U*D*U**T.
187 * First solve U*D*X = B, overwriting B with X.
189 * K is the main loop index, decreasing from N to 1 in steps of
190 * 1 or 2, depending on the size of the diagonal blocks.
195 * If K < 1, exit from loop.
200 IF( IPIV( K ).GT.0 ) THEN
202 * 1 x 1 diagonal block
204 * Interchange rows K and IPIV(K).
208 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
210 * Multiply by inv(U(K)), where U(K) is the transformation
211 * stored in column K of A.
213 CALL ZGERU( K-1, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
216 * Multiply by the inverse of the diagonal block.
218 CALL ZSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
222 * 2 x 2 diagonal block
224 * Interchange rows K-1 and -IPIV(K).
228 $ CALL ZSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
230 * Multiply by inv(U(K)), where U(K) is the transformation
231 * stored in columns K-1 and K of A.
233 CALL ZGERU( K-2, NRHS, -ONE, A( 1, K ), 1, B( K, 1 ), LDB,
235 CALL ZGERU( K-2, NRHS, -ONE, A( 1, K-1 ), 1, B( K-1, 1 ),
236 $ LDB, B( 1, 1 ), LDB )
238 * Multiply by the inverse of the diagonal block.
241 AKM1 = A( K-1, K-1 ) / AKM1K
242 AK = A( K, K ) / AKM1K
243 DENOM = AKM1*AK - ONE
245 BKM1 = B( K-1, J ) / AKM1K
246 BK = B( K, J ) / AKM1K
247 B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
248 B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
256 * Next solve U**T *X = B, overwriting B with X.
258 * K is the main loop index, increasing from 1 to N in steps of
259 * 1 or 2, depending on the size of the diagonal blocks.
264 * If K > N, exit from loop.
269 IF( IPIV( K ).GT.0 ) THEN
271 * 1 x 1 diagonal block
273 * Multiply by inv(U**T(K)), where U(K) is the transformation
274 * stored in column K of A.
276 CALL ZGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
277 $ 1, ONE, B( K, 1 ), LDB )
279 * Interchange rows K and IPIV(K).
283 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
287 * 2 x 2 diagonal block
289 * Multiply by inv(U**T(K+1)), where U(K+1) is the transformation
290 * stored in columns K and K+1 of A.
292 CALL ZGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB, A( 1, K ),
293 $ 1, ONE, B( K, 1 ), LDB )
294 CALL ZGEMV( 'Transpose', K-1, NRHS, -ONE, B, LDB,
295 $ A( 1, K+1 ), 1, ONE, B( K+1, 1 ), LDB )
297 * Interchange rows K and -IPIV(K).
301 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
310 * Solve A*X = B, where A = L*D*L**T.
312 * First solve L*D*X = B, overwriting B with X.
314 * K is the main loop index, increasing from 1 to N in steps of
315 * 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 ZSWAP( 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 ZGERU( N-K, NRHS, -ONE, A( K+1, K ), 1, B( K, 1 ),
340 $ LDB, B( K+1, 1 ), LDB )
342 * Multiply by the inverse of the diagonal block.
344 CALL ZSCAL( NRHS, ONE / A( K, K ), B( K, 1 ), LDB )
348 * 2 x 2 diagonal block
350 * Interchange rows K+1 and -IPIV(K).
354 $ CALL ZSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
356 * Multiply by inv(L(K)), where L(K) is the transformation
357 * stored in columns K and K+1 of A.
360 CALL ZGERU( N-K-1, NRHS, -ONE, A( K+2, K ), 1, B( K, 1 ),
361 $ LDB, B( K+2, 1 ), LDB )
362 CALL ZGERU( N-K-1, NRHS, -ONE, A( K+2, K+1 ), 1,
363 $ B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
366 * Multiply by the inverse of the diagonal block.
369 AKM1 = A( K, K ) / AKM1K
370 AK = A( K+1, K+1 ) / AKM1K
371 DENOM = AKM1*AK - ONE
373 BKM1 = B( K, J ) / AKM1K
374 BK = B( K+1, J ) / AKM1K
375 B( K, J ) = ( AK*BKM1-BK ) / DENOM
376 B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
384 * Next solve L**T *X = B, overwriting B with X.
386 * K is the main loop index, decreasing from N to 1 in steps of
387 * 1 or 2, depending on the size of the diagonal blocks.
392 * If K < 1, exit from loop.
397 IF( IPIV( K ).GT.0 ) THEN
399 * 1 x 1 diagonal block
401 * Multiply by inv(L**T(K)), where L(K) is the transformation
402 * stored in column K of A.
405 $ CALL ZGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
406 $ LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
408 * Interchange rows K and IPIV(K).
412 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
416 * 2 x 2 diagonal block
418 * Multiply by inv(L**T(K-1)), where L(K-1) is the transformation
419 * stored in columns K-1 and K of A.
422 CALL ZGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
423 $ LDB, A( K+1, K ), 1, ONE, B( K, 1 ), LDB )
424 CALL ZGEMV( 'Transpose', N-K, NRHS, -ONE, B( K+1, 1 ),
425 $ LDB, A( K+1, K-1 ), 1, ONE, B( K-1, 1 ),
429 * Interchange rows K and -IPIV(K).
433 $ CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )