Professional Documents
Culture Documents
1. Gauss-Seidel Method
2. Jacobi Method
Gauss-Seidel Method
An iterative method.
Basic Procedure:
-Algebraically solve each linear equation for xi
-Assume an initial guess solution array
-Solve for each xi and repeat
-Use absolute relative approximate error after each iteration
to check if error is within a pre-specified tolerance.
Gauss-Seidel Method
Why?
The Gauss-Seidel Method allows the user to control round-off error.
Algorithm
A set of n equations and n unknowns:
If: the diagonal elements are
a11x1 + a12 x2 + a13 x3 + ... + a1n xn = b1 non-zero
a21x1 + a22 x2 + a23 x3 + ... + 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
Gauss-Seidel Method
Algorithm
Rewriting each equation
c1 − a12 x2 − a13 x3 − a1n xn
x1 = From Equation 1
a11
c2 − a21 x1 − a23 x3 − a2 n xn
x2 = From equation 2
a22
c − 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
cn − an1 x1 − an 2 x2 − − an,n −1 xn −1
xn = From equation n
ann
Gauss-Seidel Method
Algorithm
General Form of each equation
n
a
n
c1 − a1 j x j cn −1 − n −1, j xj
j =1 j =1
j n −1
x1 =
j 1
xn −1 =
a11 an −1,n −1
n
n
c2 − a2 j x j c n − a nj x j
j =1 j =1
j n
x2 =
j 2
xn =
a 22 a nn
Gauss-Seidel Method
Algorithm
General Form for any row ‘i’
n
ci − aij x j
j =1
j i
xi = , i = 1,2,, n.
aii
n
aii aij
n
aii aij for all ‘i’ and for at least one ‘i’
j =1 j =1
j i j i
Convergence of Iterative Methods
The inequalities are all true and at least one row is strictly greater than:
Therefore: The solution should converge using the Gauss-Siedel Method
Gauss-Seidel Method: Example
1 − 3 x 2 + 5 x3 1 − 3(0) + 5(1)
x1 = x1 = = 0.50000
12 12
4.9000 − 0
a 2
= 100 = 100.00%
4.9000
3.0923 − 1.0000
a 3
= 100 = 67.662%
3.0923
The maximum absolute relative error after the first iteration is 100%
Gauss-Seidel Method: Example
After Iteration #1
x1 0.5000
x = 4.9000
2
x3 3.0923
This is much larger than the maximum absolute relative error obtained in
iteration #1. Is this a problem?
Gauss-Seidel Method: Example
x1 0.99919 x1 1
The solution obtained x = 3.0001 is close to the exact solution of x = 3 .
2 2
x3 4.0001 x3 4
Gauss-Seidel Method
x1 + x2 + x3 = 3
2x1 + 3x2 + 4x3 = 9
x1 + 7 x2 + x3 = 9
𝑘 𝑘−1 (𝑘−1)
(𝑘) c2 − 𝑎21 𝑥1 − 𝑎23 𝑥3 … … − 𝑎2𝑛 𝑥𝑛 From equation 2
𝑥2 =
𝑎22
⋮ ⋮ ⋮
(𝑘) (𝑘) (𝑘) (𝑘−1)
(𝑘) 𝑐𝑛−1 − 𝑎𝑛−1,1 𝑥1 − 𝑎𝑛−1,2 𝑥2 … … − 𝑎𝑛−1,𝑛−2 𝑥𝑛−2 − 𝑎𝑛−1,𝑛 𝑥𝑛 From equation n-1
𝑥𝑛−1 =
𝑎𝑛−1𝑛−1
10x1 − x2 + 2 x3 =6
− x1 + 11x2 − x3 + 3x4 = 25
2 x1 − x2 + 10x3 − x4 = −11
3x2 − x3 + 8 x4 = 15
1 ( k −1 ) 1 ( k −1 ) 3
= − x3 +
(k)
x1 x2
10 5 5
1 ( k −1 ) 1 ( k −1 ) 3 ( k −1 ) 25
= + x3 − x4 +
(k )
x2 x1
11 11 11 11
1 ( k −1 ) 1 ( k −1 ) 1 ( k −1 ) 11
= − x1 + x2 + x4 −
(k )
x3
5 10 10 10
3 ( k −1 ) 1 ( k −1 ) 15
= − x2 + x3 +
(k )
x4
8 8 8
1 ( k −1) 1 ( k −1) 3
= − x3 +
(k)
x1 x2
10 5 5
1 (k) 1 ( k −1) 3 ( k −1) 25
= + x3 − x4 +
(k)
x2 x1
11 11 11 11
1 (k) 1 (k) 1 ( k −1) 11
= − x1 + + −
(k)
x3 x2 x4
5 10 10 10
3 (k) 1 (k) 15
= − x2 + x3 +
(k)
x4
8 8 8
Results of Gauss-Seidel Iteration:
(Blue numbers are for Jacobi iterations.)
k 0 1 2 3
(k ) 0.0000 0.6000 1.0300 1.0065
x1
0.6000 1.0473 0.9326
(k ) 0.0000 2.3272 2.0370 2.0036
x2 2.2727 1.7159 2.0530
(k ) 0.0000 -0.9873 -1.0140 -1.0025
x3
-1.1000 -0.8052 -1.0493
(k ) 0.0000 0.8789 0.9844 0.9983
x4 1.8750 0.8852 1.1309
The solution is: x1= 1, x2 = 2, x3 = -1,
x4 = 1
It required 15 iterations for Jacobi
method and 7 iterations for Gauss-
Seidel method to arrive at the solution
with a tolerance of 0.00001.
Iterative formula for Jacobi Method
10x1 − x2 + 2 x3 =6
− x1 + 11x2 − x3 + 3x4 = 25
2 x1 − x2 + 10x3 − x4 = −11
3x2 − x3 + 8 x4 = 15
Convert the set Ax = b in the form of x = Tx + c.
1 1 3
x1 = x2 − x3 +
10 5 5
1 1 3 25
x2 = x1 + x3 − x4 +
11 11 11 11
1 1 1 11
x3 = − x1 + x2 + x4 −
5 10 10 10
3 1 15
x4 = − x2 + x3 +
8 8 8
Start with an initial approximation of:
= 0, x 2 = 0, x3 = 0 and x4 = 0.
(0) (0) (0) (0)
x1
1 (0) 1 (0) 3
= − x3 +
(1)
x1 x2
10 5 5
1 (0) 1 (0) 3 (0) 25
= + x3 − x4 +
(1)
x2 x1
11 11 11 11
1 (0) 1 (0) 1 (0) 11
= − x1 + + −
(1)
x3 x2 x4
5 10 10 10
3 (0) 1 (0) 15
= − x2 + x3 +
(1)
x4
8 8 8
1 1 3
= − (0) +
(1)
x1 (0)
10 5 5
1 1 3 25
= + (0) − (0) +
( 1)
x2 (0)
11 11 11 11
1 1 1 11
= − (0) + (0) + (0) −
( 1)
x3
5 10 10 10
3 1 15
= − (0) + (0) +
(1)
x4
8 8 8
= 0.6000, x2 = 2.2727,
(1) (1)
x1
k 0 1 2 3
(k ) 0.0000 0.6000 1.0473 0.9326
x1
(k ) 0.0000 2.2727 1.7159 2.0530
x2
(k ) 0.0000 -1.1000 -0.8052 -1.0493
x3
(k ) 0.0000 1.8750 0.8852 1.1309
x4
Use gauss-Seidel method to solve the following system. Assume the error
tolerance as 0.0001.
15𝑥1 − 2𝑥2 − 6𝑥3 = 300
1
𝑥1 = [300 + 2𝑥2 + 6𝑥3 ]
15
1
𝑥2 = [2𝑥1 + 4𝑥3 + 𝑥4 ]
12
1
𝑥3 = [6𝑥1 + 4𝑥2 + 9𝑥4 ]
19
−1
𝑥4 = [𝑥2 + 9𝑥3 ]
21
Iterative formula ( for k=1,2,3…..)
𝑋 (0) = 0, 0, 0, 0 T