Tridiagonal in a, b, c 4 4 for\tbtri.wpj

advertisement
Tridiagonal in a, b, c 441 for\tbtri.wpj
 b1 c1 0 0  u1   r1 

   
 a2 b2 c2 0  u2    r2 
(1)
 0 a3 b3 c3  u3   r3 

   
 0 0 a4 b4  u4   r4 
Note that a1 and c4 are not in equation (1). Write the set of equations
eqn #
col1
col2
col3
Col4
Rhs1
b1 u1
c1 u2
0
0
=
r1
1
a2 u1
b2 u2
c2 u3
0
=
r2
2
0
a3 u2
b3 u3
c3 u4
=
r3
3
0
0
a4 u3
b4 u4
=
r4
4
Divide equation 1 by b1
eqn #
col1
col2
col3
Col4
Rhs1
u1
c1/b1 u2 0
0
=
r1/b1
1
a2 u1
b2 u2
c2 u3
0
=
r2
2
0
a3 u2
b3 u3
c3 u4
=
r3
3
0
0
a4 u3
b4 u4
=
r4
4
Define U1 =r1/bt and Define 1 = c1 /b1.
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
a2 u1
b2 u2
c2 u3
0
=
r2
2
0
a3 u2
b3 u3
c3 u4
=
r3
3
0
0
a4 u3
b4 u4
=
r4
4
Multiply the first equation by a2 and subtract it from the second equation.
eqn #
col1
col2
col3 Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
=
r2-a2U1
2
(b2-a21)u2 c2 u3 0
0
a3 u2
b3 u3 c3 u4
=
r3
3
0
0
a4 u3 b4 u4
=
r4
4
Define new bt = (b2-a21) and divide equation 2 by this
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
u2
(c2/bt) u3 0
=
(r22
a2U1)/bt
0
a3 u2
b3 u3
c3 u4
=
r3
3
0
0
a4 u3
b4 u4
=
r4
4
Define U2 =(r2-a2U1)/bt and Define 2 = c2 /bt
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
u2
0
=
U2
2
2u3
0
a3 u2
b3 u3
c3 u4
=
r3
3
0
0
a4 u3
b4 u4
=
r4
4
Multiply the second equation by a3 and subtract it from the third equation.
eqn #
col1
col2
col3
Col4
Rhs1
u
0
0
=
U1
1
1
1u2
0
u2
0
=
U2
2
2u3
0
0
c3 u4
=
r3-a3U2
3
(b3-a32)
u3
0
0
a4 u3
b4 u4
=
r4
4
Define new bt = (b3-a32) and divide equation 3 by this
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
u2
0
=
U2
2
2u3
0
0
u3
(c3/bt) u4
=
(r3-a3U2)/bt
3
0
0
a4 u3
b4 u4
=
r4
4
Define U3 =(r3-a3U2)/bt and Define 3 = c3 /bt
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
u2
0
=
U2
2
2u3
0
0
u3
=
U3
3
3u4
0
0
a4 u3
b4 u4
=
r4
4
Define U4 =(r4-a4U3)/bt and Define 4 = c4 /bt – skip a few steps
eqn #
col1
col2
col3
Col4
Rhs1
u1
0
0
=
U1
1
1u2
0
u2
0
=
U2
2
2u3
0
0
u3
=
U3
3
3u4
0
0
u4
=
U4
4
This last is the N’th term and we have found u4. Then u3 = U3-3u4 and so on back to u1.
Note that U and u can share the same storage locations. This is the Press code from
section 2.6 with the addition of real*8 and some comments TRIDAG.FOR. Note that
gamma needs to be stored in a work space dimensioned 500.
In Weighted Fourier Series.doc the limitation on the size of an array is determined
by the storage. If the H’ terms are all one or zero the equation set involves the same a, b,
and c for each term. Thus for\tbtri.wpj uses inputs of a, b, and c as numbers and creates a
direct access temporary file for gamma.
Tridiagonal Matrices2
 1  1

 

2
2

A 1

2
N 


N N 

To solve Ax=b, for i = 2,…,N
i  i 
i 1

i 1 i 1
bi  bi 
i 1
b
i 1 i 1
Then back substitute for i = N-1, … ,1
b   i xi 1
xi  i
i
“You might expect that we would next assemble a program to compute the inverse of a
tridiagonal matrix. There is only one problem: The inverse of a tridiagonal matrix is not
necessarily sparse.”
Diagonal in a, b, c,d,e 88
eqn #
1
2
3
4
5
6
col1
c A11
b A11
a A11
0
0
0
col2
dA21
c A21
b A21
a A21
0
0
col3
eA31
dA31
c A31
b A31
a A21
0
Col4
0
eA41
dA41
c A41
b A41
a A41
C5
0
0
eA51
dA51
cA51
b A51
C6
0
0
0
eA61
dA61
cA61
C7
0
0
0
0
eA71
dA71
7
0
0
0
0
a A51
8
0
0
0
0
0
b
cA71
A61
a A61 b
A71
C8
0
0
0
0
0
eA8
=
=
=
=
=
=
Rhs1
I11
I12
I13
I14
I15
I16
1
Multiply 1 by b/c and subtract from 2, then by a/c and subtract from 3
eqn #
col1
col2
col3
Col4 C5
C6
c A11
dA21
eA31
0
0
0
1
0
(c-d b/c)
(d-e b/c)A31 eA41 0
0
2
A21
0
(b-d b/a)
(c –e
dA41 eA51 0
3
A21
b/a)A31
0
a A21
b A31
c A41 dA51 eA61
4
0
0
a A21
b
cA51 dA61
5
A41
0
0
0
a A41 b
cA61
6
A51
0
0
0
0
a A51 b
7
A61
0
0
0
0
0
a A61
8
dA8
= I17
1
cA8
= I18
1
C7
0
0
C8
0
0
=
=
Rhs1
I11
I12-b/c I11
0
0
=
I13-b/a I11
0
eA71
0
0
=
=
I14
I15
dA71
eA81
=
I16
cA71
dA81
=
I17
b A71
cA81
=
I18
Define, ctt=(c –e b/a), bt = b – d (b/a), btt = d – d (b/a), It=I12-I11 (b/c) and Itt = I13 – I11
(b/a) – drop the first row and column
1.
ct = c – d (b/c)
2.
bt = b – d (b/a)
3.
dt = d – e (b/c)
4.
ctt = c – e (b/a)
eqn #
2
3
4
5
6
7
col2
ct A21
bt A21
a A21
0
0
0
col3
dt A31
ctt A31
b A31
a A21
0
0
Col4
eA41
dA41
c A41
b A41
a A41
0
C5
0
eA51
dA51
cA51
b A51
a A51
C6
C7
C8
Rhs1
0
0
0
=
It
0
0
0
=
Itt
eA61 0
0
=
I14
dA61 eA71
0
=
I15
cA61 dA71
eA81 =
I16
b
cA71
dA81 =
I17
A61
0
0
0
0
a A61 b A71
cA81 =
I18
8
Again make the subtractions, watch out for the ctt. Eventually these reduce to 3 equations
in 3 unknowns. While one can continue, this is Gauss Jordan.
Band Diagonal Systems3
Band diagonal systems have m1 elements below the diagonal and m2 above the
diagonal
3
1
0
0
0
0
0
4
1
5
0
0
0
0
9
2
6
5
0
0
0
0
3
5
8
9
0
0
0
0
7
9
3
2
0
0
0
0
3
8
4
6
0
0
0
0
2
4
4
3 1 0 0 
4 1 5 0 



 has N (number of rows 7, m1 = 2, and m2 = 1. It is stored as
9
2
6
5


0 3 5 8 
X
X
3
1
X
4
1
5
9
3
6
5
3
5
8
9
7
9
3
2
3
8
4
6
2
4
4
X
The routine bandec calculates the upper triangle in the space of A above. This routine is
used with banbks to solve band-diagonal sets ofequations.
The routines bandec and banbks are based on the Handbook routines bandet1 and
bansol1 in Wilkinson and Reinsh4
Press – section 2.6
A.L. Gasrcia, Numerical Methods for Physics, Prentice Hall (1994), pp 253-255
3
Press, Numerical Recipes in C, Cambridge University Press 1988,1992 section 2.4
4
Wilkinson, J. H., and Reinsch, C., 1971, Linear Algebra, vol II of Handbook for Automatic
Computation (New York: Springer-Verlag, Chapter 1/6.
1
2
Download