Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Chapter 2: Solutions of Linear

Systems of Equations
Lecture 2
Gauss-Seidel iteration Method
Gauss-Seidel Method
A set of n equations and n unknowns:
a11 x1  a12 x2  a13 x3  ...  a1n xn  b1
a21 x1  a22 x2  a23 x3  ...  a2n xn  b2
……
an1x1  an 2 x2  an3 x3  ...  ann xn  bn

The diagonal elements are non-zero

Rewrite each equation solving for the corresponding


unknown. Ex:
• First equation, solve for x1
• Second equation, solve for x2
MAFE208IU-L5 • …. 2
Gauss-Seidel Method
Transformation
Rewriting each equation
b1  a12 x2  a13 x3   a1n xn
x1 
a11 From Equation 1

b2  a21 x1  a23 x3   a2 n xn
x2  From equation 2
a22
…..
  
bn 1  an 1,1 x1  an 1,2 x2   an 1,n  2 xn  2  an 1,n xn
xn 1  From equation n-1
an 1,n 1
bn  an1 x1  an 2 x2    an,n 1 xn 1
xn  From equation n
ann
MAFE208IU-L5 3
Algorithm for Gauss-Seidel Method
Let x ( k )  ( x1( k ) , x2( k ) ,...., xn( k ) ) be a given approximate value,
k  0,1, 2,..., we compute the new approximate value x ( k 1) :

b1  a12 x2( k )  a13 x3( k )  a1n xn( k )


x1( k 1) 
a11

bi  ai1 x1( k 1)  ...  ai ,i 1 xi(k11)  ai ,i 1 xi(k1)  a1n xn( k )


xi( k 1) 
aii

bn  an1 x1( k 1)  ...  a1,n 1 xn( k11)


xn( k 1) 
ann
Repeat this process until a stopping criterion is met
MAFE208IU-L5 4
Stopping Criteria
We can use either Approximate Error or Relative
Approximate Error to stop the computation process

Ea  max{| x new
i x old
i |, i  1, 2,..., n}
new
x x old
 a  max{ i
new
i
, i  1, 2,..., n}
xi

The iterations are stopped when the absolute


relative approximate error is less than a
prespecified tolerance for all unknowns x1 , x2 ,..., xn
.
MAFE208IU-L5 5
Example
Use Gauss-Seidel method, find the root of the system with stopping
criterion |Ea | ≤ 0.01 with starting point x(0) =(0,0,0):
6 x1  x2  2 x3  1
x1  8 x2  3x3  5
2 x1  2 x2  9 x3  7
Solution
Resolve for each variable x1  (1  x2  2 x3 ) / 6
x2  (5  x1  3x3 ) / (8)
x3  (7  2 x1  2 x2 ) / (9)
Iterative Formula:
x1( k 1)  (1  x2( k )  2 x3( k ) ) / 6
x2( k 1)  ( 5  x1( k 1)  3x3( k ) ) / ( 8)
MAFE208IU-L5 x3( k 1)  ( 7  2 x1( k 1)  2 x2( k 1) ) / ( 9) 6
Example …
Starting with x(0) =(0,0,0), and using:

x1( k 1)  (1  x2( k )  2 x3( k ) ) / 6


( k 1) ( k 1)
x 2  ( 5  x 1  3x ) / ( 8)
(k )
3

x3( k 1)  ( 7  2 x1( k 1)  2 x2( k 1) ) / ( 9)


we get
(k )
x x1 | x1new  x1old | x2 | x2new  x2old | x3 | x3new  x3old | Ea
0 O 0 O
1 0.1667 0.6458 0.8843 --
2 -0.0204 0.1871 0.9540 0.3082 0.9943 0.1100 0.3082
3 -0.0058 0.0146 0.9972 0.0432 1.0006 0.0063 0.0432
4 -0.0007 0.0051 1.0002 0.0030 1.0002 0.0004 0.0051

So, approximate solution is x=(-0.0007, 1.0002, 1.0002)


MAFE208IU-L5 7
Remark
Gauss-Seidel method: not all systems of equations
will converge.
One class of system of equations always converges:
One with a diagonally dominant coefficient matrix.
Diagonally dominant: [A] in [A] [X] = [C] is diagonally
dominant if:
n n
aii   aij
for all ‘i’ aii   aij
j 1 j 1
for at least one ‘i’
j i and j i

MAFE208IU-L5 8
Comments on Gauss-Seidel
• Disadvantages:
– it may not converge
– When it converged, it did so very slowly
• Advantages:
– When matrix is very sparse (most elements are
zero), elimination methods waste large amount of
computer memory by storing zeros
– Gauss-Seidel method saves memory because only
nonzero coefficients are involved in the structure
of equations
MAFE208IU-L5 9
Exercise
Using Gauss-Seidel iteration method, solve the following system

3 x1  x2  5
2 x2  x3  1
x2  5 x3  2 x4  25
x3  6 x4  x5  16
 x4  3x5  11
Use x (0) =(0,0,0,0,1), stopping condition: | Ea | 0.02

MAFE208IU-L5 10
Quiz 2
2) Using Gauss-Seidel
mn: last two digits of your iteration method, solve the
Student ID number following system

1) Solve the following (2  3m) x1  x3  3m  5


system using Crout’s
method x1  (1  2n) x2  4n  1
x2  (4  n) x3  2 x4  3n  22
2 x1  nx2  3x3  2n  11
x2  5 x4  x5  27
nx1  (3  m) x2  3 x3  2m  n  15
mx1  x2  2 x3  m  4 2 x3  (3  m) x5  5m  9

Use x (0) =(0,0,0,0,0),


stopping condition: | Ea | 0.02
MAFE208IU-L5 11
Ex 2: Find temperature in a square sheet of metal. The temperature
at the edges of the sheet are kept at : 100, 90, 50, and 0 degrees.
T1,3  90 T  90 T3,3  90
2,3

T1, 2 T2, 2 T3,2


T0,2  100 T4,2  50

T1,1 T2,1 T3,1


T0,1  100 T4,1  50

T1,0  0 T2,0  0 T3,0  0


Temperature at grid points: Ti 1, j  Ti 1, j  Ti , j 1  Ti , j 1  4Ti , j  0
MAFE208IU-L14 Solve by Gauss-Seidel method, use |𝐸 | ≤ 0.2 12
T1,3  200 T2,3  200
Quiz
Find temperature in a
square sheet of metal.
T0,2  10m T1, 2 T2, 2 T3,2  10n
The temperature at
edges of the sheet are
kept as in Figure T0,1  5m T3,1  5n
T1,1 T2,1
Approximate T
at grid points
Temperature at grid points:
T1,0  0 T2,0  0
Ti 1, j  Ti 1, j  Ti , j 1  Ti , j 1  4Ti , j  0
mn  The last two digits
Solve by a) Gauss elimination of your student ID number
b) LU decomposition method
c) Gauss-Seidel method, use |𝐸 | ≤ 0.5
MAFE208IU-L14 13

You might also like