Class Session File
Class Session File
Numerical Analysis
Lesson #: 4
Title: Iterative numerical method
[ ][ ] [ ]
Condition check:
𝑎 𝑏 𝑐 𝑥 𝐵1
ALL
𝑑 𝑒 𝑓 𝑦 = 𝐵2
𝑔 h 𝑖 𝑧 𝐵3
And for at least 1 row:
At least 1 of
them
Example 1 – check if it diagonally
dominant
[ ][ ] [ ]
9 1 2 𝑥 𝐵1
1 7 4 𝑦 = 𝐵2
2 3 7 𝑧 𝐵3
• OK This means that all row diagonals are
• OK dominant > this matrix is diagonally
• OK dominant.
When solving using iterative
method, convergence is
guaranteed.
Example 2 – check if it diagonally
dominant
Example 2 - solution
• OK
• FAIL
• Therefore, this matrix is not diagonally dominant, use
direct method.
[ ][ ] [ ]
𝑎 𝑏 𝑐 𝑥 𝐵1
Jacobi iteration 𝑑 𝑒 𝑓 𝑦 = 𝐵2
Process of Jacobi iteration: 𝑔 h 𝑖 𝑧 𝐵3
1) Guess a value for x, y, z
• Normally start at x=0, y=0, z=0
2) Rewrite our system of equation so what we find for x, y, z.
X 0
Y 0
z 0
[ ][ ] [ ]
9 2 3 𝑥 7
1 12 9 𝑦 = 2
4 6 14 𝑧 1
Example Jacobi iteration - solution
Check if it is diagonally dominant
[ ][ ] [ ]
• 9 > 2 + 3 OK 9 2 3 𝑥 7
• 12 > 1 + 9 OK 1 12 9 𝑦 = 2
• 14 > 4 + 6 OK 4 6 14 𝑧 1
Make separated equations for x, y, and z
X 0 0.778
Y 0 0.167
z 0 0.071
Example Jacobi iteration - solution
From iteration
1:
X = 0.778
Solution for
Y = 0.167
Z = 0.071 Iteration 2
Y 0 0.167 0.049
z 0 0.071 -0.222
Example Jacobi iteration - solution
From iteration
2:
X = 0.717
Solution for
Y = 0.049
Z = -0.222 Iteration 3
iteration - X
Y
0
0
0.778
0.167
0.717
0.049
0.841
0.273
0.768
0.212
0.826
0.317
Validate Iteration
5 in original
equations
Iteration Error in equation 1 Since error
1 9(0.778)+2(0.137)+3(0.071)-
is
9 7=0.489
2 1.117 decreasing
3 -0.655 , it is
4 0.519 converging
5 0.352 . It should
6 0.265
eventually
Gauss-seidel method
• It is very similar to Jacobi method
• However, use the most updated values immediately.
• In the first step, guess that y=0 and z=0. whatever
answer you get for x, use that in the second equation,
then whatever answer you get for y, use that in the
third equation and so on.
Example – use Gauss seidel method
• Solve for x, y, and z
[ ][ ] [ ]
9 2 3 𝑥 7
1 12 9 𝑦 = 2
4 6 14 𝑧 1
Example gauss seidel- solution
Check if it is diagonally dominant
[ ][ ] [ ]
• 9 > 2 + 3 OK 9 2 3 𝑥 7
• 12 > 1 + 9 OK 1 12 9 𝑦 = 2
• 14 > 4 + 6 OK 4 6 14 𝑧 1
Make separated equations for x, y, and z
z 0 -0.195
Example gauss seidel- solution
z 0 -0.195 -0.267
Example gauss seidel- solution
gauss seidel-
on on on
e guess on 1 on 2
3 4 5
X 0 0.778 0.820 0.813 0.808 0.805
solution Y
z
0
0
0.102
-0.195
0.244
-0.267
0.299
-0.289
0.316
-0.295
0.322
-0.297
Validate Iteration
5 in original
equations
Iteration Error in equation 1
Since error
1 9(0.778)+2(0.102)+3(-0.195)- is
9 7=-0.38
decreasing,
2 0.07 it is
3 0.05 converging.
4 0.02 It should
5 0.002
eventually
Note:
reach zero.
this method reached near zero quicker than
the Jacobi
Classwork: gauss seidel method
• Find x. y and z, up to 3 iterations
[ ][ ] [ ]
3 1 2 𝑥 1
3 6 2 𝑦 = 2
2 4 8 𝑧 3
End of Class