Solving Tridiagonal System
Solving Tridiagonal System
Course: CS 4MN3
Student: Imam Abdukerim
Professor: Dr. Sanzheng Qiao
Date:
February 27, 2009
Tridiagonal System
d1
l
1
0' s
u2
d3
u1
d2
l2
u3
ln 2
d n 1
ln 1
0' s
un 1
d n
x1
x2
x3
b1
b
2
b3
xn 1
xn
bn 1
bn
LU decomposition of
Tridiagonal Matrix
1
l1
1
0' s
1
l12
l1n 2
l2
u3
ln 2
0' s
d n 1
ln 1
1
0' s
un 1
d n
u11
d12
0' s
u12
d13 u13
u2
d3
l1n 1
u1
d2
0' s
d1
l
1
d11
0' s
d1n 1 u1n 1
d1n
Thomas Algorithm :
l1n 1 ln 1 / d1n 1
d1n d n (ln 1 / d1n 1 ) * un 1
LU decomposition of
Tridiagonal Matrix (Matlab Code)
function [u1,d1,l1] = decomt(u,d,l)
n = length(d); % get the length of the diagonal
% initialize the output vectors
u1=u;
d1=d;
l1=l;
%Perform LU decomposition
d1(1)=d(1);
for i=2:n
l1(i-1) = l(i-1)/d1(i-1); % Update the lover triangle vector
d1(i) = d(i) - (l(i-1)/d1(i-1))*u(i-1); %Update the diaginal
end
Complexity: O(n)
LU decomposition of
Tridiagonal Matrix (Testing)
u = [23 43 22 3 77];
d = [3 34 55 18 13 56];
l = [1,2,3,4,5];
>>[u,d,l] = decomt(u,d,l)
u = 23 43 22 3 77
d = 3.0000 26.3333 51.7342 16.7242 12.2825 24.6545
l = 0.3333 0.0759 0.0580 0.2392 0.4071
(Construct L and U using decomposed vectors)
L = diag(l,-1)+eye(6);
U = diag(d)+diag(u,+1);
L=
1.0000
0
0
0
0
0
0.3333 1.0000
0
0
0
0
0 0.0759 1.0000
0
0
0
0
0 0.0580 1.0000
0
0
0
0
0 0.2392 1.0000
0
0
0
0
0 0.4071 1.0000
U=
3.0000 23.0000
0
0
0
0
0 26.3333 43.0000
0
0
0
0
0 51.7342 22.0000
0
0
0
0
0 16.7242 3.0000
0
0
0
0
0 12.2825 77.0000
0
0
0
0
0 24.6545
(Construct triangular matrix by multiplying L
and U)
>>L*U
ans =
3.0000 23.0000
0
0
0
0
1.0000 34.0000 43.0000
0
0
0
0 2.0000 55.0000 22.0000
0
0
0
0 3.0000 18.0000 3.0000
0
0
0
0 4.0000 13.0000 77.0000
0
0
0
0 5.0000 56.0000
0' s
Step 2 : Ux y
0' s
1
l12
l1n 2
1
l1n 1
y1 b1
y b
2 2
y b
3 3
yn1 bn1
yn bn
d11
0' s
u11
d12
0' s
u12
d13
u13
d1n 1 u1n 1
d1n
x1 y1
x y
2 2
x y
3 3
xn 1 yn1
xn yn
u = 23
M=
3.0000 23.0000
0
0
0
0
1.0000 34.0000 43.0000
0
0
0
0 2.0000 55.0000 22.0000
0
0
0
0 3.0000 18.0000 3.0000
0
0
0
0 4.0000 13.0000 77.0000
0
0
0
0 5.0000 56.0000
43
22
77
43
0.0759
33
67
0.0580
89
0.2392
0.4071
76
>> solvet(u,d,l,b)
b = 45
>> M\b1
x = -11.9303
ans =
-11.9303
3.5127
-1.5000
4.9307
-5.7506
1.8706
3.5127 -1.5000
ans = -11.9303
1.8706
4.9307 -5.7506
3.5127 -1.5000
1.8706
4.9307 -5.7506
43
33
67
89
76
Question(s)?