Professional Documents
Culture Documents
&
STATISTICS
MTH 2212 -2011/2012 SEM 1
LECTURER
DR ZAHARAH WAHID
EXT 4514, ROOM E1-4-813
1
Gauss-Siedel Method
Gauss-Seidel Method
Gauss-Seidel Method
An iterative method.
Basic Procedure:
Algebraically solve each linear equation for xi
Gauss-Seidel Method
Why?
The Gauss-Seidel Method allows the user to control round-off error.
Gauss-Seidel Method
Algorithm
A set of n equations and n unknowns:
.
.
.
ex:
First equation, solve for x1
Second equation, solve for x2
Gauss-Seidel Method
Algorithm
Rewriting each equation
c2 a21 x1 a23 x3 a2 n xn
a22
xn 1
xn
From Equation 1
From equation 2
an 1,n 1
cn an1 x1 an 2 x2 an ,n 1 xn 1
ann
From equation n
Gauss-Seidel Method
Algorithm
General Form of each equation
n
c1 a1 j x j
x1
j 1
j 1
a11
cn 1
xn 1
a 22
j 1
j n 1
n 1, j
xj
an 1,n 1
c n a nj x j
c2 a2 j x j
x2
a
n
j 1
j2
xn
j 1
j n
a nn
a21 x1 a 22 x2 a23 x3 b2
a x a x a x b
31 1
32 2
33 3
3
If the diagonal elements are all non-zero then:
b1 a12 x2 a13 x3
x1
a11
x2
b2 a21 x1 a23 x3
a22
x3
b3 a31 x1 a32 x2
a33
i 1
1
i 1
2
i 1
3
10
x1
x
2
x3
b1 a12 x a13 x
a11
i
2
i
3
i 1
1
i
3
i 1
1
i 1
2
b2 a21 x
a23 x
a22
b3 a31 x
a32 x
a33
0
0
0
Gauss-Seidel Method
Algorithm
General Form for any row i
n
ci aij x j
xi
j 1
j i
aii
, i 1,2, , n.
Gauss-Seidel Method
Solve for the unknowns
Assume an initial guess for [X]
x1
x
2
xn -1
xn
12
Gauss-Seidel Method
Calculate the Absolute Relative Approximate Error
x inew x iold
100
new
xi
13
x1 247
x 248
2
x 3 239
The right hand side values are the light intensities from the
middle of the images, while the coefficient matrix is
dependent on the light source directions with respect to the
camera. The unknowns are the incident intensities that will
determine the shape of the object.
Find the values of x1, x2, and x3 use the Gauss-Seidel
method.
14
0
0.9701 x1 247
0.2425
0
0.2425 0.9701 x 2 248
x3
15
10
0.9701
0.9701
0
0.2425
247 0 x 2 (0.9701) x3
x1
0.2425
x1 247
x 248
2
x 3 239
248 0 x1 (0.9701) x3
x2
0.2425
10
2
into the equations
247 0 10 0.9701 10
x1
1058.6
0.2425
x3
10
a i
100
1
new
xi
x 1062.7
2
1058.6 10
x3 783.81
a 1
100 99.055%
1058.6
1062.7 10
100 99.059%
1062.7
a 3
18
The maximum
absolute relative
approximate error
is 101.28%
x1 1058.6
x 1062.7
2
x 3 783.81
19
x2
x3
a 1
a 2
a 3
x3 803.98
803.98 783.81
20
ERROR
Perfect accuracy in most computational
processes is impossible
Error = true value- approximate value
Absolute error = |true value- approximate value|
The relative error is a measure of the
error in relation to the size of
true being sought
21
ERROR
22
a 3 %
1058.6
99.055
1062.7
99.059
783.81
101.28
2117.0
150.00
2112.9
150.30
803.98
197.49
4234.8
149.99
4238.9
149.85
2371.9
133.90
8470.1
150.00
8466.0
150.07
3980.5
159.59
16942
149.99
16946
149.96
8725.7
145.62
33888
150.00
33884
150.01
16689
152.28
Gauss-Seidel Method:
Pitfall
What went wrong?
Even though done correctly, the answer is not converging to the
correct answer
This example illustrates a pitfall of the Gauss-Siedel method: not all
systems of equations will converge.
Is there a fix?
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
aii aij
j 1
j i
24
for all i
and
aii aij
j 1
j i
0
0
.
2425
0
.
9701
2. LU
Gauss-Seidel Method
The Gauss-Seidel Method can still be used
The coefficient matrix is not
diagonally dominant
But this is the same set of
equations used in example #2,
which did converge.
3 7 13
A 1 5 3
12 3 5
12 3 5
A 1 5 3
3 7 13
27
Gauss-Seidel Method
Not every system of equations can be rearranged to have a
diagonally dominant coefficient matrix.
Observe the set of equations
x1 x 2 x3 3
2 x1 3 x 2 4 x3 9
x1 7 x 2 x3 9
Which equation(s) prevents this set of equation from having a
diagonally dominant coefficient matrix?
28
Gauss-Seidel Method:
Example 2
Given the system of equations
12x 1 3x 2 - 5x 3 1
x 1 5x 2 3x 3 28
3x1 7x2 13x3 76
12 3 5
A 1 5 3
3 7 13
x1
x
2
x3
29
1
0
1
Gauss-Seidel Method:
Example 2
Checking if the coefficient matrix is diagonally dominant
12 3 5
A 1 5 3
3 7 13
a 22 5 5 a 21 a 23 1 3 4
a33 13 13 a31 a32 3 7 10
The inequalities are all true and at least one row is strictly greater than:
Therefore: The solution should converge using the Gauss-Siedel Method
30
Gauss-Seidel Method:
Example 2
Rewriting each equation
12 3 5
1 5 3
3 7 13
a1 1
a 28
2
a3 76
1 3 x 2 5 x3
x1
12
28 x1 3 x3
x2
5
76 3 x1 7 x 2
x3
13
31
x
2
x3
x1
x2
1
0
1
1 3 0 51
0.50000
12
28 0.5 31
4.9000
5
76 3 0.50000 7 4.9000
x3
3.0923
13
Gauss-Seidel Method:
Example 2
The absolute relative approximate error
0.50000 1.0000
a 1
100 100.0%
0.50000
a
a
4.9000 0
100 100.00%
4.9000
3.0923 1.0000
100 67.662%
3.0923
The maximum absolute relative error after the first iteration is 100%
32
Gauss-Seidel Method:
Example 2
After Iteration #1
x1 0.5000
x 4.9000
2
x3 3.0923
Substituting the x values into the
equations
1 3 4.9000 5 3.0923
x1
0.14679
12
x2
28 0.14679 3 3.0923
3.7153
5
x3
33
76 3 0.14679 7 4.900
3.8118
13
After Iteration #2
x1 0.14679
x 3.7153
2
x3 3.8118
Gauss-Seidel Method:
Example 2
Iteration #2 absolute relative approximate error
a 1
a 3
0.14679 0.50000
100 240.62%
0.14679
3.7153 4.9000
100 31.887%
3.7153
3.8118 3.0923
100 18.876%
3.8118
The maximum absolute relative error after the first iteration is 240.62%
This is much larger than the maximum absolute relative error obtained in
iteration #1. Is this a problem?
34
Gauss-Seidel Method:
Example 2
Repeating more iterations, the following values are obtained
Iteration
1
2
3
4
5
6
a1
0.50000
0.14679
0.74275
0.94675
0.99177
0.99919
a 1
67.662
240.62
80.23
21.547
4.5394
0.74260
a2
4.900
3.7153
3.1644
3.0281
3.0034
3.0001
x1 0.99919
The solution obtained
3
.
0001
2
x3 4.0001
x1
is close to the exact solution of x 2
x3
35
1
3
4
a3
2
100.00
31.887
17.409
4.5012
0.82240
0.11000
3.0923
3.8118
3.9708
3.9971
4.0001
4.0001
67.662
18.876
4.0042
0.65798
0.07499
0.00000
Gauss-Seidel Method:
Example 3
Given the system of equations
3x1 7 x2 13 x3 76
x1 5 x2 3 x3 28
12 x1 3 x2 5 x3 1
With an initial guess of
x1
x
2
x3
36
1
0
1
28 x1 3 x3
x2
5
1 12 x1 3 x 2
x3
5
Gauss-Seidel Method:
Example 3
Conducting six iterations, the following values are obtained
Iteration
a1
1
2
3
4
5
6
21.000
196.15
1995.0
20149
2.0364105
2.0579105
a 1 %
A2
95.238
0.80000
110.71
14.421
109.83
116.02
109.90
1204.6
109.89
12140
109.89 1.2272105
a 2 %
a3
a 3 %
100.00
94.453
112.43
109.63
109.92
109.89
50.680
462.30
4718.1
47636
4.8144105
4.8653106
98.027
110.96
109.80
109.90
109.89
109.89
37
38
Gauss-Seidel Method:
Example 3
Given the system of equations
3x1 7 x2 13 x3 76
x1 5 x2 3 x3 28
12 x1 3 x2 5 x3 1
With an initial guess of
x1
x
2
x3
39
1
0
1
12 x1 3 x2 5 x3 1
x1 5 x2 3x3 28
3 x1 7 x2 13x3 76
Method:example2
Iteration #1
1 3 x 2 5 x3
x1
12
40
x1
x
2
1 3 0 51
x3
12
0.50000
28 x1 3 x3
x2
5
28 0.5 31
x2
4.9000
5
76 3x1 7 x 2
x3
13
76 3 0.50000 7 4.9000
x3
3.0923
13
1
0
1
Gauss-Seidel Method:
Example 4
Rewriting the equations
76 7 x2 13 x3
x1
3
1 3 0 51
x1
0.50000
12
Relaxation
28 x1 3 x3
x2
5
1 12 x1 3 x 2
x3
5
41
Gauss-Seidel Method:
Example 4
Rewriting the equations
76 7 x2 13 x3
x1
3
28 x1 3 x3
x2
5
1 12 x1 3 x 2
x3
5
42
1 3 x 2 5 x3
x1
12
28 x1 3 x3
x2
5
76 3x1 7 x 2
x3
13
43
76 3 0.6 7 3.093
x3
4.088
13