1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
SUBROUTINE CGTSV( N, NRHS, DL, D, DU, B, LDB, INFO )
*
* -- LAPACK routine (version 3.2) --
* -- LAPACK is a software package provided by Univ. of Tennessee, --
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
* November 2006
*
* .. Scalar Arguments ..
INTEGER INFO, LDB, N, NRHS
* ..
* .. Array Arguments ..
COMPLEX B( LDB, * ), D( * ), DL( * ), DU( * )
* ..
*
* Purpose
* =======
*
* CGTSV solves the equation
*
* A*X = B,
*
* where A is an N-by-N tridiagonal matrix, by Gaussian elimination with
* partial pivoting.
*
* Note that the equation A'*X = B may be solved by interchanging the
* order of the arguments DU and DL.
*
* Arguments
* =========
*
* N (input) INTEGER
* The order of the matrix A. N >= 0.
*
* NRHS (input) INTEGER
* The number of right hand sides, i.e., the number of columns
* of the matrix B. NRHS >= 0.
*
* DL (input/output) COMPLEX array, dimension (N-1)
* On entry, DL must contain the (n-1) subdiagonal elements of
* A.
* On exit, DL is overwritten by the (n-2) elements of the
* second superdiagonal of the upper triangular matrix U from
* the LU factorization of A, in DL(1), ..., DL(n-2).
*
* D (input/output) COMPLEX array, dimension (N)
* On entry, D must contain the diagonal elements of A.
* On exit, D is overwritten by the n diagonal elements of U.
*
* DU (input/output) COMPLEX array, dimension (N-1)
* On entry, DU must contain the (n-1) superdiagonal elements
* of A.
* On exit, DU is overwritten by the (n-1) elements of the first
* superdiagonal of U.
*
* B (input/output) COMPLEX array, dimension (LDB,NRHS)
* On entry, the N-by-NRHS right hand side matrix B.
* On exit, if INFO = 0, the N-by-NRHS solution matrix X.
*
* LDB (input) INTEGER
* The leading dimension of the array B. LDB >= max(1,N).
*
* INFO (output) INTEGER
* = 0: successful exit
* < 0: if INFO = -i, the i-th argument had an illegal value
* > 0: if INFO = i, U(i,i) is exactly zero, and the solution
* has not been computed. The factorization has not been
* completed unless i = N.
*
* =====================================================================
*
* .. Parameters ..
COMPLEX ZERO
PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
* ..
* .. Local Scalars ..
INTEGER J, K
COMPLEX MULT, TEMP, ZDUM
* ..
* .. Intrinsic Functions ..
INTRINSIC ABS, AIMAG, MAX, REAL
* ..
* .. External Subroutines ..
EXTERNAL XERBLA
* ..
* .. Statement Functions ..
REAL CABS1
* ..
* .. Statement Function definitions ..
CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
* ..
* .. Executable Statements ..
*
INFO = 0
IF( N.LT.0 ) THEN
INFO = -1
ELSE IF( NRHS.LT.0 ) THEN
INFO = -2
ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
INFO = -7
END IF
IF( INFO.NE.0 ) THEN
CALL XERBLA( 'CGTSV ', -INFO )
RETURN
END IF
*
IF( N.EQ.0 )
$ RETURN
*
DO 30 K = 1, N - 1
IF( DL( K ).EQ.ZERO ) THEN
*
* Subdiagonal is zero, no elimination is required.
*
IF( D( K ).EQ.ZERO ) THEN
*
* Diagonal is zero: set INFO = K and return; a unique
* solution can not be found.
*
INFO = K
RETURN
END IF
ELSE IF( CABS1( D( K ) ).GE.CABS1( DL( K ) ) ) THEN
*
* No row interchange required
*
MULT = DL( K ) / D( K )
D( K+1 ) = D( K+1 ) - MULT*DU( K )
DO 10 J = 1, NRHS
B( K+1, J ) = B( K+1, J ) - MULT*B( K, J )
10 CONTINUE
IF( K.LT.( N-1 ) )
$ DL( K ) = ZERO
ELSE
*
* Interchange rows K and K+1
*
MULT = D( K ) / DL( K )
D( K ) = DL( K )
TEMP = D( K+1 )
D( K+1 ) = DU( K ) - MULT*TEMP
IF( K.LT.( N-1 ) ) THEN
DL( K ) = DU( K+1 )
DU( K+1 ) = -MULT*DL( K )
END IF
DU( K ) = TEMP
DO 20 J = 1, NRHS
TEMP = B( K, J )
B( K, J ) = B( K+1, J )
B( K+1, J ) = TEMP - MULT*B( K+1, J )
20 CONTINUE
END IF
30 CONTINUE
IF( D( N ).EQ.ZERO ) THEN
INFO = N
RETURN
END IF
*
* Back solve with the matrix U from the factorization.
*
DO 50 J = 1, NRHS
B( N, J ) = B( N, J ) / D( N )
IF( N.GT.1 )
$ B( N-1, J ) = ( B( N-1, J )-DU( N-1 )*B( N, J ) ) / D( N-1 )
DO 40 K = N - 2, 1, -1
B( K, J ) = ( B( K, J )-DU( K )*B( K+1, J )-DL( K )*
$ B( K+2, J ) ) / D( K )
40 CONTINUE
50 CONTINUE
*
RETURN
*
* End of CGTSV
*
END
|