Professional Documents
Culture Documents
The LU decomposition rountine and a forward/backward solve rountine for a tridiagonal system is given by
the following matlab code:
In order to find the solutions of the systems, we have the Thomas algorithm:
K = At CA
Where
– A is a N × N matrix
– C is a N × N matrix
So K is a N × N Tridiagonal matrix
We need to find the solutions of the following system:
Kx = f
where
W1
.
.
.
.
f = . (3)
..
.
.
Wn
and
√
Ci = 1000 + 2N − i, i = 1, · · · , N
Wi = 1000 + 5(2N − i), i = 1, · · · , N
• In order to find the rest of the question, we development the following script:
Listing 4: Solution
1 clc
2 clear all
3 N= [ 1 0 , 1 0 0 , 1 0 0 0 ] ;
4 f p r i n t f ( 'N\ t C o n d i t i o n Matrix \ t \ t \ tError TA GE \ t \ t \ t R e s i d u a l TA\ t \ t \ t \ t \ t R e s i d u a l GE \n '
)
5 f o r k =1:3
6 W=1000+5∗(2∗N( k ) −(1:N( k ) ) ) ;
7 C=d i a g (1000+ s q r t ( ( 2 ∗N( k ) −(1:N( k ) ) ) ) , 0 ) ;
8 A=d i a g ( o n e s (N( k ) , 1 ) , 0 )+d i a g (− o n e s (N( k ) −1 ,1) , −1) ;
9
10 K=A' ∗C∗A;
11
12 a=d i a g (K) ;
13 b=d i a g ( K( 2 :N( k ) , 1 :N( k ) −1) ) ;
14 c=d i a g ( K( 1 :N( k ) −1 ,2:N( k ) ) ) ;
15 b2=W' ;
16
17 %t i c
18 [ l , d , u ] = LUtriag ( a , b , c ) ;
19 solLU = thomas ( l , d , u , b2 ) ;
20 %t o c
21
22 %t i c
23 s o l G a u s s=Gauss (K, b2 ) ;
24 %t o c
25
26 Error LU GE=norm ( solLU−s o l G a u s s ) ;
27 ResiLU=norm (K∗ solLU '−b2 ) ;
28 ResiGauss=norm (K∗ s o l G a u s s '−b2 ) ;
29
30 f p r i n t f ( '%d\ t \ t%f \ t \ t \ t %.10 f \ t \ t %.4 e \ t \ t %.4 e \n ' ,N( k ) , cond (K) , Error LU GE , ResiLU ,
ResiGauss )
31 end
The Thomas algorithm is a special version of Gaussian elimination. Thats why they ended up with
the same residual for this linear system
• The condition number is
N Condition Matrix
10 175.039649
100 16365.835989
1000 1627118.802177
We note that when N grow the Thomas Algorithm for tridiagonal system is more efficient