Vous êtes sur la page 1sur 24

# NUMERICAL METHODS

Lecture 5

Dr. P V Ramana
NM Dr P V Ramana 1
NM Dr P V Ramana 67
= Ax

NM Dr P V Ramana 68
NM Dr P V Ramana 69
Tridiagonal Matrix
f1 g 1 x1 r1
e f g x r
2 2 2 2 2
e3 f3 g3 x 3 r3

O O O M = M
ei fi gi x i ri

O O O M M
e n 1 f n1 g n1 x n1 rn1

en f n x n rn
 Special case of banded matrix with bandwidth = 3
 Save storage, 3 n instead of n n
NM Dr P V Ramana 70
Tridiagonal Systems
Tridiagonal Systems:
The non-zero elements are in
the main diagonal,
5 1 0 0 0 x1 b1
super diagonal and
3
4 1 0 0 x2 b2
subdiagonal.
0 2 6 2 0 x3 = b3
aij=0 if |i-j| > 1
0 0 1 4 1 x4 b4
0 0 0 1 6 x5 b5

NM Dr P V Ramana 71
Tridiagonal Systems
Occur in many applications
Needs less storage (4n-2 compared to n +n for the general cases)
2

## Selection of pivoting rows is unnecessary (under some conditions)

Efficiently solved by Gaussian elimination

5 1 0 0 0 x1 b1
3
4 1 0 0 x2 b2

0 2 6 2 0 x3 = b3

0 0 1 4 1 x4 b4
0 0 0 1 6 x5 b5
NM Dr P V Ramana 72
Algorithm to Solve Tridiagonal Systems
Based on Naive Gaussian elimination.
As in previous Gaussian elimination algorithms
Forward elimination step
Backward substitution step
Elements in the super diagonal are not affected.
Elements in the main diagonal, and B need updating

5 1 0 0 0 x1 b1
3 x
4 1 0 0 2 2 b

0 2 6 2 0 x3 = b3

0 0 1 4 1 x4 b4
0 0 0 1 6 x5 b5
NM Dr P V Ramana 73
Tridiagonal System

All the a elements will be zeros, need to update the d and b elements
The c elements are not updated
d1 c1 x1 b1 d1 c1 x1 b1
a d c2 x b d '
c2 x b '
1 2 2 2 2 2 2'
a2 d3 O x3 = b3 d 3' O x3 = b3
O O cn 1 M M O cn 1 M M
'
'
a n 1 d n xn bn d n xn bn

NM Dr P V Ramana 74
Solving Tridiagonal System
Forward Eliminatio n
a
d i d i i1
c i 1
d i1
a i1
b i b i b i 1 2 i n
d i1
Backward Substituti on
bn
x n =
d n
1
xi = (b i c i x i+1 ) for i = n 1 , n 2 ,..., 1
di
NM Dr P V Ramana 75
f1 g1 x1 r1
e f g x r
Tridiagonal Matrix

2 2 2

e3 f3 g3
2 2
x3 r3

O O O M = M
ei fi gi xi ri

O O O M M
en1 fn1 gn1 xn1 rn1
 Forward elimination
en

fn xn rn

## ek Use factor = ek / fk1

fk = fk f g k 1
k 1 to eliminate subdiagonal
k = 2 , 3, K , n element
r = r e k r
k k k 1 Apply the same matrix
f k 1 operations to right hand side

 Back substitution
rn
xn =
fn
rk g k x k + 1
xk = k = n 1, n 2 , K , 3, 2 ,1
fk NM Dr P V Ramana 76
Certain matrices have particular
structures that can be exploited to
develop efficient solution schemes (e.g.
banded, symmetric)

## A banded matrix is a square matrix that

has all elements equal to zero, with the
exception of a band centered on the
main diagonal.

## Standard Gauss Elimination is

inefficient in solving banded equations
because unnecessary space and time
would be expended on the storage and
manipulation of zeros.

## There is no need to store or process the

zeros (off of the band)
77 NM Dr P V Ramana
Solving Tridiagonal Systems
(Thomas Algorithm)
A tridiagonal system has a bandwidth of 3

f1 g1 x1 r1 DECOMPOSITION
e x r
2 f2 g2 2 = 2
e3 f3 g 3 x3 r3 DO k = 2, n
ek = ek / fk-1
e4 f 4 x4 r4 fk = fk - ek gk-1
1 0 0 0 f1 g1 END DO
e' 1 0 0 f 2' g2
A = L U = 2
0 e'3 1 0 f 3' g3 Time Complexity?

0 0 e'4 1 f 4' O(n)
vs. O(n3)
78 NM Dr P V Ramana
Tridiagonal Systems
{d}
1 0 0 0 f1 g1 x1 r1
e' 1 0 0 f 2' g2 x r
2 2 = 2
0 e'3 1 0 f 3' g3 x3 r3
'
0 0 e'4 1 f 4 x 4 r4

1 0 0 0 d1 r1 f1 g1 x1 d1
e ' 0 d 2 r2 x d
2 1 0
f 2' g2 2 = 2
=
0 e'3 1 0 d 3 r3 f 3' g3 x3 d 3

0 0 e' 4 1 d 4 r4 f 4' x 4 d 4

## Forward Substitution Back Substitution

d1 = r1 xn = dn /fn
DO k = 2, n DO k = n-1, 1, -1
dk = rk - ek dk-1 xk = (dk - gk . xk+1 )/fk
79 NM Dr P V Ramana
END DO END DO
Hand Calculations: Tridiagonal Matrix
1 2 0 0 x1 3 f1 g1 x1 r1
ek e f g x r
fk = fk f gk1
2 5 1 0 x 2 5 2 2 2 2 = 2
= e3 f3 g3 x3 r3

k 1
0 1 2 0.5 x 3 2 e4 f4 x4 r4

r = r ek r 0 0 0. 5 1 .25 x 4 3.5 rn
k k fk1 k1 xn =
fn
(a) Forward elimination (b) Back substitution
rk gk xk+1
e2 2 r4 4 xk =

f 2 = f 2
f1
g 1 = 5
1
( 2 ) = 1 x 4 = = =4 fk

f4 1
r = r e 2 r = 5 2 ( 3 ) = 1 r g 3 x 4 1 ( 0.5 )( 4 )
2 2
f1
1
1 x3 = 3 = =3
f3 1
e3 1
f 3 = f 3 f g 2 = 2 1 ( 1) = 1 r2 g 2 x 3 1 ( 1)( 3 )
2 x = = =2
2
f2 1
r = r e 2 r = 2 1 ( 1) = 1
3 2
f1
1
1 r g 1 x 2 3 ( 2 )( 2 )
x1 = 1 = =1
e4 0.5 f1 1
f 4 = f 4 g 3 = 1 . 25 ( 0. 5 ) = 1
f3 1

r = r e 4 r = 3.5 0.5 ( 1)NM =4 Dr P V Ramana 80
4 4
f3
3
1
MATLAB M-
M-file: Tridiag

81
NM Dr P V Ramana
Example: Tridiagonal matrix
1 2 x 1 3 function [e,f,g,r] = example
2 6 4 x 22
2
4 9 0 .5 x 3 35.5 e=[ 0 -2 4 -0.5 1.5 -3];
= f=[ 1 6 9 3.25 1.75 13];
0 . 5 3 . 25 1 . 5 x
4 = 7 . 75
1.5 1.75 3 x 5 4 g=[-2 4 -0.5 1.5 -3 0];

3 13
6
x 33 r=[-3 22 35.5 -7.75 4 -33];

[e,f,g,r] = example

e =
0 -2.0000 4.0000 -0.5000 1.5000 -3.0000
f =
1.0000 6.0000 9.0000 3.2500 1.7500 13.0000
g =
-2.0000 4.0000 -0.5000 1.5000 -3.0000 0
r =
-3.0000 22.0000 35.5000 -7.7500 4.0000 -33.0000

x = Tridiag (e, f, g, r)
x = 1 2 3 -1 -2 -3

## Note: e(1) = 0 and g(n) = 0 82

NM Dr P V Ramana
Example 2
Solve
5 2 x1 12 5 1 2 12
1 5 2 x 9 5 1 2 9
2 = D = , A = , C = , B =
1 5 2 x3 8 5 1 2 8

1 5 x4 6 5 6
Forward Eliminatio n
a i 1 a i 1
d i d i c i 1 , bi bi bi 1 2i4
d i 1 d i 1
Backward Substituti on
bn 1
xn = , xi = (bi ci xi +1 ) for i = 3, 2,1
dn di
NM Dr P V Ramana 83
Example 2
5 1 2 12
5 1 2 9
D = , A = , C = , B =
5 1 2 8

5
6
Forward Elimination
a1 1 2 a1 112
d 2 = d 2 c1 = 5 = 4.6, b2 = b2 b1 = 9 = 6.6
d1 5 d1 5
a2 1 2 a2 1 6.6
d3 = d3 c2 = 5 = 4.5652, b3 = b3 b2 = 8 = 6.5652
d2 4.6 d2 4.6
a3 1 2 a3 1 6.5652

d 4 = d 4 c3 = 5
= 4.5619, b4 = b4 b3 = 6 = 4.5619
d3 4.5652 d3 4.5652

NM Dr P V Ramana 84
Example 2
Backward Substitution
After the Forward Elimination:
Backward Substitution:

## DT = [5 4.6 4.5652 4.5619], BT = [12 6.6 6.5652 4.5619]

b4 4.5619
x4 = = = 1,
d 4 4.5619
b c x 6.5652 2 1
x3 = 3 3 4 = =1
d3 4.5652
b c x 6 .6 2 1
x2 = 2 2 3 = =1
d2 4 .6
b1 c1x2 12 2 1
x1 = = =2
d1 5NM Dr P V Ramana 85
NM Dr P V Ramana 86
Gauss-Seidel Method Algorithm
a11 a12 L a1n x1 b1
a a x b
21 22 2 = 2
M O

a
n1 a nn xn bn
Split A into an upper component, a diagonal component and a
lower component

Upper triangular, U

NM Dr P V Ramana 87
Gauss-Seidel Method Algorithm
a11 a12 L a1n x1 b1
a a x b
21 22 2 = 2
M O

a
n1 a nn xn bn
Split A into an upper component, a diagonal component and a
lower component

Diagonal, D

NM Dr P V Ramana 88
Gauss-Seidel Method Algorithm
a11 a12 L a1n x1 b1
a a x b
21 22 2 = 2
M O

a
n1 a nn xn bn
Split A into an upper component, a diagonal component and a
lower component

Lower triangular, L

NM Dr P V Ramana 89