MAFE208IU-L5 - Linear Systems of Equations - Part 2

You might also like

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
Description
A set of n equations and n unknowns:
The diagonal elements are non-
a11x1 + a12 x2 + a13x3 + ... + a1n xn = b1 zero
a21x1 + a22 x2 + a23x3 + ... + a2n xn = b2 Rewrite each equation solving
. .
. . for the corresponding unknown
. .
ex:
an1x1 + an 2 x2 + an3 x3 + ... + ann xn = bn
First equation, solve for x1
Second equation, solve for x2

MAFE208IU-L5 2
Gauss-Seidel Method
Transformation
Rewriting each equation
b − a x − a x  − a1n xn From Equation 1
x1 = 1 12 2 13 3
a11

b2 − a21x1 − a23 x3  − a2 n xn
x2 = From equation 2
a22
  
b − a x − a x  − an −1,n− 2 xn − 2 − an −1,n xn From equation n-1
xn −1 = n −1 n −1,1 1 n −1,2 2
an −1,n−1
bn − an1 x1 − an 2 x2 −  − an,n−1 xn −1 From equation n
xn =
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{| xinew − xiold |, i = 1, 2,..., n}


xinew − xiold
 a = max{ new
, 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 = (1 + x2 − 2 x3 ) / 6
x1 − 8 x2 + 3x3 = −5 x2 = (−5 − x1 − 3x3 ) / (−8)
−2 x1 + 2 x2 − 9 x3 = −7 x3 = (−7 + 2 x1 − 2 x2 ) / (−9)

x1( k +1) = (1 + x2( k ) − 2 x3( k ) ) / 6


Iterative Formula: x2( k +1) = ( −5 − x1( k +1) − 3x3( k ) ) / ( −8)
x3( k +1) = ( −7 + 2 x1( k +1) − 2 x2( k +1) ) / ( −9)
MAFE208IU-L5 6
Solution
Starting with x(0) =(0,0,0), and using:

x1( k +1) = (1 + x2( k ) − 2 x3( k ) ) / 6


( k +1) ( k +1)
x2 = ( −5 − x 1 − 3x ) / ( −8)
(k )
3
( k +1) ( k +1) ( k +1)
we get x3 = ( −7 + 2 x 1 − 2x 2 ) / ( −9)
x(k ) x1 | x1new − x1old | x2 | x2new − x2old | x3 | x3new − x3old | Ea
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’ and aii   aij for at least one ‘i’
j =1 j =1
j i 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 1
Solve the following system

5 x1 − 2 x2 = 1
x1 + 8 x2 − 2 x3 = 11
− x2 + 7 x3 − 2 x4 = 11
−2 x3 + 5 x4 = 14
Using
a) LU decomposition method
b) Gauss-Seidel iteration method
Use x (0) =(1,1,1,1), stopping condition: | Ea | 0.02
MAFE208IU-L5 10
Exercise 4
Using Gauss-Seidel iteration method, solve the following system

8 x1 + 3 x2 = −21
x1 − 5 x2 + 2 x3 = 10
− x2 + 6 x3 + 2 x4 = 71
3 x3 − 5 x4 + 2 x5 = −2
−2 x4 + 5 x5 = 22
Use x (0) =(1,2,3,4,5), stopping condition: | Ea | 0.05
MAFE208IU-L5 11
Ex 2: Find temperature in a square sheet of metal. The temperature
at the edges of the sheet are kept at : 200, 100, 50, and 0 degrees.
T1,3 = 200 T2,3 = 200

T0,2 = 100 T1, 2 T2, 2


T3,2 = 50

T1,1 T2,1
T0,1 = 100 T3,1 = 50

T1,0 = 0 T2,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.512
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 T1,1 T2,1 T3,1 = 5n
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