Lecture Module 3 Presentation
Lecture Module 3 Presentation
ENGINEERING MATHEMATICS 4
➢ Iteration Method
➢ Gauss Siedel
➢ Crout
➢ Thomas
➢ Variant 1
➢ Variant 2
➢ Thomas Algorithm
➢ Cholesky
1 u 1+ 2 u 2 =1
2 u1 + 9 u 2+ 1 u3=6
1 u 2 + 9 u3+ 4 u 4 =2
4 u3 + 3 u 4 =8
Or in matrix notation, you can write [K ] {u }= { F }
[ ]{ } { }
1 2 0 0 u1 1
2 9 1 0 u2 = 6
0 1 9 4 u3 2
0 0 4 3 u4 8
[ ]{ } { }
1 2 0 0 u1 1
2 9 1 0 u2 = 6
0 1 9 4 u3 2
0 0 4 3 u4 8
K= 1 2 0 0 F= 1
2 9 1 0 6
Enter the data
0 1 9 4 2
0 0 4 3 8
U= -1.6923
1.3462 > Insert » Function » MMULT
-2.7308 > Select the first range inv(K)
6.3077 > Select the second range F
> Press ENTER
K= 1 2 0 0 F= 1
2 9 1 0 6
Enter the data
0 1 9 4 2
0 0 4 3 8
1u 1+ 2 u 2 =1
3 u1 + 4 u 2 + 5 u3 =0
6 u2 + 7 u3 + 8 u 4 =2
10 u3 + 11 u 4=3
Answer:
{}{ }
u1 1.1173
u 2 = −0.0586
u3 −0.6235
u4 0.8395
In this method, the basic idea is modify the matrix into upper triangular.
Then solve
x 2 =−0.05
x 1 =1.125
Forward
2 x 1+ 5 x 2=2
−4 x 1 + 10 x 2 =−5
Then solve
x 2 =−0.05
x 1 =1.125
from [−4
2 5
10 ]{ } { }
x1
x2
= 2
5
to [ ]{ } { }
2 5 x1
0 20 x 2
= 2
−1
[ A] { x }= { b } [U ] { x }= { f }
[ ]{ } { } [ ]{ } { }
a 11 a12 ⋯ a 1n x 1 b1 u11 u12 ⋯ u1n x1 f1
a 21 a 22 ⋯ a 2n x 2 0 u22 ⋯ u2n x 2
= b2 = f2
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
a m1 a m2 ⋯ a mn x n bn 0 0 ⋯ u mn x n fn
a ii ≠0
Upper triangular matrix
the solution is very simple, starting
from the last row then BACKWARD
Elimination step:
(k )
assume a kk ≠0
(k)
a ik
define multiplier mik = (k)
i=k + 1,⋯, n
a kk
( k + 1) (k ) (k )
a ij =−mik a kj + aij
(k + 1) (k ) (k )
bij =−mik b k + bi i , j=k + 1,⋯, n
Substitution step:
Using the last step from the elimination step [U ]=[ A](n−1) { f }= {b }(n−1)
fn
x n=
u nn
[ ]
n
1
xk= g k − ∑ u kj x j
ukk j=k + 1
x1 + 2 x 2 =1
3 x 1+ 4 x 2 + 5 x 3=0
6 x 2 + 7 x 3 + 8 x 4 =2
10 x 3 + 11 x 4 =3
[ ]{ } { }
1 2 0 0 x1 1
3 4 5 0 x2 = 0
0 6 7 8 x3 2
0 0 10 11 x 4 3
[ ∣]
1 2 0 0 1
3 4 5 0 0
0 6 7 8 2
0 0 10 11 3
[ ∣]
1 2 0 0 1 E1
3 4 5 0 0 E2
0 6 7 8 2 E3
0 0 10 11 3 E4
[ ∣ ] [ ∣]
1(−3) 2(−3) 0(−3) 0(−3) 1(−3) + 1 2 0 0 1
3 4 5 0 0 0 −2 5 0 −3
0 6 7 8 2 0 6 7 8 2
0 0 10 11 3 0 0 10 11 3
[ ∣]
1 2 0 0 1 E1
0 −2 5 0 −3 E2
0 6 7 8 2 E3
0 0 10 11 3 E4
[ ∣ ] [ ∣]
1 2 0 0 1 1 2 0 0 1
0(3) −2(3) 5(3) 0(3) −3(3) 0 −2 5 0 −3
+
0 6 7 8 2 0 0 22 8 −7
0 0 10 11 3 0 0 10 11 3
[ ∣]
1 2 0 0 1 E1
0 −2 5 0 −3 E2
0 0 22 8 −7 E3
0 0 10 11 3 E4
[ ∣ ]
1 2 0 0 1
0 −2 5 0 −3
0(−10/22) 0(−10/22) 22(−10/22) 8(−10/ 22) −7(−10/22)
+
0 0 10 11 3
[ ∣ ]
1 2 0 0 1
0 −2 5 0 −3
0 0 22 8 −7
0 0 0 7.364 6.182
BDA34003 Engineering Mathematics IV 22
Waluyo Adi Siswanto (waluyo@uthm.edu.my)
Substitution steps:
[ ]{ } { }
1 2 0 0 x1 1
0 −2 5 0 x2
= −3
0 0 22 8 x3 −7
0 0 0 7.364 x4 6.182
6.182
x 4= =0.839
7.364
1
x3=
22
[ −7−8 x 4 ] =−0.623
1
x2=
−2
[−3−(5 x 3+ 0 x 4)]=−0.059
1
x1=
1
[1−(2 x 2+ 0 x3+ 0 x 4)]=1.117
x
x 21
x3
x4
N = max(size(A));
for j=N-1:-1:1;
x(j) = (b(j)-A(j,j+1:N)*x(j+1:N))/A(j,j);
end ;
(k )
Gauss elimination requires a kk ≠0
In every step, the matrix must be checked
and rearrange if necessary to satisfy that
diagonal element is not 0.
(k )
a ik
Another operation mik = (k )
a kk
The pivot element in this operation should
Use the largest element to avoid round-off error.
The matrix should be rearranged.
Taken from: Applied Numerical Methods for Engineers and Scientists (3ed,2012, p.244) by Stephen C. Chapra
0.02 x 1 + 300 x 2+ 10 x 3 =9
500 x 1 − x 2 + 3 x 3 =6
4 x1 + 7 x 2 + x 3=2
[ ]{ } { }
0.02 300 10 x1 9
500 −1 3 x2 = 6
4 7 1 x3 2
[ ∣]
0.02 300 10 9
500 −1 3 6
4 7 1 2
[ ∣] [ ∣]
0.02 300 10 9 E1 500 −1 3 6 E1
500 −1 3 6 E2 rearrange 0.02 300 10 9 E2
4 7 1 2 E3 4 7 1 2 E3
[ ∣]
500 −1 3 6 E1
0 300 10 9 E2
4 7 1 2 E3
[ ∣ ] [ ∣ ]
500(−0.008) −1(−0.008) 3(−0.008) 6(−0.008) 500 −1 3 6
0 300 10 9 + 0 300 10 9
4 7 1 2 0 7.008 0.976 1.952
[ ∣ ]
500 −1 3 6 E1
0 300 10 9 E2
0 7.008 0.976 1.952 E3
[ ∣ ]
500 −1 3 6
0(−0.0234) 300 (−0.0234) 10(−0.0234) 9(−0.0234)
+
0 7.008 0.976 1.952
[ ∣ ]
500 −1 3 6
0 300 10 9
0 0 0.742 1.742
[ ∣ ] [ ]{ } { }
500 −1 3 6 500 −1 3 x1 6
0 300 10 9 0 300 10 x2 = 9
0 0 0.742 1.742 0 0 0.742 x3 1.742
1.742
x3= =2.348
0.742
1
x2=
300
[ 9−10 x 3 ] =−0.048
1
x1=
500
[ 6−(−1 x 2+ 3 x 3)]=−0.002
[ ] [ ]
l 11 0 ⋯ 0 u11 u12 ⋯ u1n
l l ⋯ 0 0 u 22 ⋯ u2n
[ L]= 21 22 [U ]=
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
l m1 l m2 ⋯ l mn 0 0 ⋯ u mn
[ A] { x } = {b }
1. Decomposition step [U ] [ L]
2. Solving steps
[L] {d } = {b }
[U ] { x } = {d }
[ A] { x } = {b }
[L] [U ]
[ ] [ ]
1 0 ⋯ 0 u11 u12 ⋯ u1n
l 1 ⋯ 0 0 u 22 ⋯ u 2n
[ L]= 21 [U ]=
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
l n1 l n2 ⋯ 1 0 0 ⋯ u nn
2 x 1 −1 x 2 −2 x 3=−1
−4 x 1 +6 x 2 +3 x 3=13
−4 x 1 −2 x 2 +8 x 3 =−6
[ ]{ } { }
2 −1 −2 x1 −1
[ A ] { x }= {b } −4 6 3 x 2 = 13
−4 −2 8 x3 −6
[ L ][ U ]=[ A ]
[ ] [ ][ ] [ ]
2 −1 −2 1 0 0 d e f d e f
−4 6 3 = a 1 0 0 g h = ad ae+ g af + h
−4 −2 8 b c 1 0 0 i bd be+ cg bf + h+ i
d =2 e=−1 f =−2
ad =−4 ae+ g=6 af + h=3
→ a=−2 → g=4 → h=−1
bd =−4 be+ cg=−2 bf + ch+ i=8
→ b=−2 → c=−1 → i=3
[ ]
d =2 e=−1 f =−2
a=−2 g=4 h=−1
b=−2 c=−1 i=3
[ ][ ][ ]
2 −1 −2 1 0 0 2 −1 −2
−4 6 3 = −2 1 0 0 4 −1
−4 −2 8 −2 −1 1 0 0 3
[ L] [U ]
[ ]{ } { }
1 0 0 d1 −1
−2 1 0 d 2 = 13
−2 −1 1 d 3 −6
−1
d 1= =−1
1
1
d 2=
1
[ 13−(−2 d 1 ) ]=11
1
d 3=
1
[−6−(−2 d 1−1 d 2 ) ]=3
[ ]{ } { }
2 −1 −2 x 1 −1
0 4 −1 x 2 = 11
0 0 3 x3 3
3
x 3 = =1
3
1
x2=
4
[ 11−(−1 x 3 ) ] =3
1
x 1=
2
[−1−(−1 x 2−2 x 3)]=2
[ ]{ } { }
1 2 3 4 x1 3
5 2 7 8 x2
= 0
9 0 3 2 x3 7
3 4 5 6 x4 8
b) Find the vector {d} in Doolittle step { d }=[3 −15 13.75 −1.833]T
[ A] { x } = {b }
[L] [U ]
[ ] [ ]
l 11 0 ⋯ 0 1 u12 ⋯ u1n
l l ⋯ 0 0 1 ⋯ u2n
[ L]= 21 22 [U ]=
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
l n1 l n2 ⋯ l nn 0 0 ⋯ 1
Modify your doolittle.m (example 3-6) to implement CROUT method and save as crout.m.
Try to solve example 3.7 by using crout.m. Try to solve by hand calculation according to Crout.
[ ]{ } { }
1 2 3 4 x1 3
5 2 7 8 x2
= 0
9 0 3 2 x3 7
3 4 5 6 x4 8
[ ] [ ][ ]
1 2 3 4 a 0 0 0 1 k l m
5 2 7 8 b c 0 0 0 1 n o
=
9 0 3 2 d e f 0 0 0 1 p
3 4 5 6 g h i j 0 0 0 1
[ ]
a=1 ak =2 al =3 am=4
b=5 bk + c=2 bl+ cn=7 bm+ co=8
=
d =9 dk + e=0 dl + en+ f =3 dm+ eo+ fp=2
g=3 gk + h=4 gl+ hn+ i=5 gm+ ho+ ip+ j=6
[ ][ ][ ]
1 2 3 4 a=1 0 0 0 1 k =2 l=3 m=4
5 2 7 8 b=5 c=−8 0 0 0 1 n=1 o=1.5
=
9 0 3 2 b=9 e=−18 f =−6 0 0 0 1 p=7/6
3 4 5 6 b=3 h=−2 i=−2 j=−2/3 0 0 0 1
[ L] [U ]
[ ]{ } { }
1 0 0 0 d1 3
5 −8 0 0 d2
= 0
9 −18 −6 0 d3 7
3 −2 −2 −2/ 3 d4 8
3
d 1 = =3
1
1
d 2=
−8
[ 0−(5 d 1 )]=1.875
1
d 3=
−6
[ 7−(9 d 1−18 d 2 ) ]=−2.292
1
d 4=
−2/3
[ 8−(3 d 1−2 d 2−2 d 3)]=2.751
[ ]{ } { }
1 2 3 4 x1 3
0 1 1 1.5 x 2 = 1.875
0 0 1 7/6 x 3 −2.292
0 0 0 1 x4 2.751
2.751
x 4= =2.751
1
1
x 3=
1
[−2.292−(7/6 x 4 )]=−5.502
1
x2=
1
[ 1.875−(1 x 3 + 1.5 x 4 ) ]=3.251
1
x 1=
1
[ 3−(2 x 2+ 3 x 3+ 4 x 4)]=2
Engineering problems often lead to coefficient matrices that are sparsely populated,
meaning that most elements of the matrix are zero. If all the nonzero terms are clustered
about the leading diagonal, then the matrix is said to be banded.
[ A] = [ L] [U ]
[ ][ ][ ]
b1 c1 0 ⋯ 0 α1 0 0 ⋯ 0 1 β1 0 ⋯ 0
a 2 b2 c 2 ⋯ 0 a2 α2 0 ⋯ 0 0 1 β2 ⋯ 0
0 a3 ⋱ 0 = 0 a3 ⋱ 0 + 0 0 ⋱ 0
⋮ ⋮ bn−1 c n−1 ⋮ ⋮ α n−1 0 ⋮ ⋮ 1 βn−1
0 0 ⋯ an bn 0 0 ⋯ a n αn 0 0 ⋯ 0 1
[ ]{ } { }
1 2 0 0 x1 1
3 4 5 0 x2 = 0
0 6 7 8 x3 2
0 0 10 11 x 4 3
d) Use your crout.m to check the answer, and proof that Crout on banded matrix gives
the same result of L and U as defined by Thomas.
[ ]{ } { }
1 2 0 0 x1 1
3 4 5 0 x2 = 0
0 6 7 8 x3 2
0 0 10 11 x 4 3
[ ] [ ][ ]
1 2 0 0 α1 0 0 0 1 β1 0 0
3 4 5 0 = 3 α2 0 0 0 1 β2 0
0 6 7 8 0 6 α3 0 0 0 1 β3
0 0 10 11 0 0 10 α 4 0 0 0 1
[ ]
α 1=1 α1 β1=2
3 3β1 + α 2=4 α 2 β2=5
=
6 6β2 + α3 =7 α3 β3 =8
10 β3+ α 4=11
[ ][ ][ ]
1 2 0 0 1 0 0 0 1 2 0 0
3 4 5 0 3 −2 0 0 0 1 −2.5 0
=
0 6 7 8 0 6 22 0 0 0 1 0.3636
0 0 10 11 0 0 10 7.3636 0 0 0 1
[ L] [U ]
[ ]{ } {}
1 0 0 0 d1 1
3 −2 0 0 d2
= 0
0 6 22 0 d3 2
0 0 10 7.3636 d4 3
1
d 1 = =1
1
1
d 2=
−2
[ 0−(3 d 1)]=1.5
1
d 3=
22
[ 2−(6 d 2 ) ] =−0.3182
1
d 4=
10
[ 3−(10 d 3)]=0.8395
[ ]{ } { }
1 2 0 0 x1 1
0 1 −2.5 0 x2 1.5
=
0 0 1 0.3636 x3 −0.3182
0 0 0 1 x4 0.8395
0.8395
x 4= =0.8395
1
1
x3=
1
[−0.3182−(0.3636 x 4)]=−0.6234
1
x 2=
1
[ 1.5−(−2.5 x 3 ) ]=−0.0585
1
x1=
1
[1−(2 x 2)]=1.117
[ A] = [ L] [U ]
[ ][ ][ ]
d 1 c1 0 ⋯ 0 1 0 0 ⋯ 0 α1 c 1 0 ⋯ 0
a 2 d 2 c2 ⋯ 0 β2 1 0 ⋯ 0 0 α2 c2 ⋯ 0
0 a3 ⋱ 0 = 0 β3 ⋱ 0 + 0 0 ⋱ 0
⋮ ⋮ d n−1 c n−1 ⋮ ⋮ 1 0 ⋮ ⋮ α n−1 c n−1
0 0 ⋯ an dn 0 0 ⋯ βn 1 0 0 ⋯ 0 αn
Do example 3-9a by using Thomas method variant 2. Try the thomas.m also by hand!
[ ]{ } { }
1 2 0 0 x1 1
3 4 5 0 x2 = 0
0 6 7 8 x3 2
0 0 10 11 x 4 3
[ ] [ ][ ]
1 2 0 0 1 0 0 0 α1 2 0 0
3 4 5 0 = β1 1 0 0 0 α2 5 0
0 6 7 8 0 β2 1 0 0 0 α3 8
0 0 10 11 0 0 β3 1 0 0 0 α4
[ ]
α1 =1 2
α β =3 2β1 + α2 =4 5
= 1 1
α 2 β2 =6 5β2 + α 3=7 8
α3 β3 =10 8β3 + α 4 =11
[ ][ ][ ]
1 2 0 0 1 0 0 0 1 2 0 0
3 4 5 0 3 1 0 0 0 −2 5 0
=
0 6 7 8 0 −3 1 0 0 0 22 8
0 0 10 11 0 0 0.4545 1 0 0 0 7.3636
[ L] [U ]
[ ]{ } {}
1 0 0 0 d1 1
3 1 0 0 d2
= 0
0 −3 1 0 d3 2
0 0 0.4545 1 d4 3
1
d 1 = =1
1
1
d 2=
1
[ 0−(3 d 1 )]=−3
1
d 3=
1
[ 2−(−3 d 2 ) ] =−7
1
d 4=
1
[ 3−(0.4545 d 3)]=6.1818
[ ]{ } { }
1 2 0 0 x1 1
0 −2 5 0 x2
= −3
0 0 22 8 x3 −7
0 0 0 7.3636 x4 6.1818
6.1818
x 4= =0.8395
7.3636
1
x3=
22
[−7−(8 x 4 )]=−0.6234
1
x 2=
−2
[ −3−(5 x 3 ) ]=−0.0585
1
x1=
1
[1−(2 x 2)]=1.117
The routine for Thomas (Variant 1) has been generalized for a faster calculation by using
a calculation table.
[ A] = [ L] [U ]
[ ][ ][ ]
d 1 e1 0 ⋯ 0 α1 0 0 ⋯ 0 1 β1 0 ⋯ 0
c2 d 2 e2 ⋯ 0 c2 α2 0 ⋯ 0 0 1 β2 ⋯ 0
0 c3 ⋱ 0 = 0 c3 ⋱ 0 + 0 0 ⋱ 0
⋮ ⋮ d n−1 e n−1 ⋮ ⋮ α n−1 0 ⋮ ⋮ 1 βn−1
0 0 ⋯ cn dn 0 0 ⋯ cn αn 0 0 ⋯ 0 1
i 1 2 ... n
di
ei
ci
bi
α 1=d 1 α i =d i−ci β i−1
ei
β i=α
i
b1 bi−ci yi−1
y 1= α yi= αi
1
x n= y n x i = y i − β i x i+ 1
[ ]{ } { }
1 2 0 0 x1 1
3 4 5 0 x2 = 0
0 6 7 8 x3 2
0 0 10 11 x 4 3
i 1 2 3 4
di 1 4 7 11
ei 2 5 8
ci 3 6 10
bi 1 0 2 3
α 1=d 1 α i =d i−ci β i−1 1 4-3(2) 7-6(-2.5) 11-10(0.364)
=-2 =22 =7.36
[ A] { x } = {b }
T
[L] [ U ]=[ L ]
[ ] [ ]
l 11 0 ⋯ 0 l 11 l 21 ⋯ l nl
l l ⋯ 0 0 l 22 ⋯ l n2
[ L]= 21 22 [U ]=
⋮ ⋮ ⋮ ⋮ ⋮ ⋮
l n1 l n2 ⋯ l nn 0 0 ⋯ l nn
If i= j (diagonal term)
% LU Decomposition (CHOLESKY METHOD)
√
j−1 for j = 1:n
L jj = A jj − ∑ L 2jk must be temp = A(j,j) - dot(A(j,1:j-1),A(j,1:j-1));
k =1 positive if temp < 0.0
error(’Matrix is not positive definite’)
j=2, 3,⋯, n end
A(j,j) = sqrt(temp);
For non diagonal term for i = j+1:n
A(i,j)=(A(i,j) - dot(A(i,1:j-1),A(j,1:j-1)))/A(j,j);
( )
j−1 end
A jj −∑ Lik L jk end
k =1 L = tril(A);
L jj = U=transpose(L);
L jj
% End of Decomposition (CHOLESKY METHOD)
[ ]{ } { }
8 2 3 4 x1 1
2 5 1 0 x2 = 0
3 1 7 3 x3 0
4 0 3 11 x 4 9
[ ]{ } { }
8 2 3 4 x1 1
2 5 1 0 x2 = 0
3 1 7 3 x3 0
4 0 3 11 x 4 9
[ ] [ ][ ]
8 2 3 4 a 0 0 0 a b d g
2 5 1 0 b c 0 0 0 c e h
=
3 1 7 3 d e f 0 0 0 f i
4 0 3 11 g h i j 0 0 0 j
[ ]
a 2 =8
ab=2 b2 + c 2 =5
= 2 2 2
ad =3 bd + ce=1 d + e + f =7
2 2 2 2
ag=4 bg + ch=0 dg+ eh+ if =3 g + h + i + j =11
a 2 =8
→ a=2.8284
2 2
ab=2 b + c =5
→ b=0.7071 → c=2.1213
2 2 2
ad =3 bd + ce=1 d + e + f =7
→ d =1.0607 → e=0.1179 → f =2.4210
ag=4 bg+ ch=0 dg+ eh+ if =3 g 2 + h 2+ i 2 + j 2=11
→ g=1.4142 → h=−0.4714 → i=0.6425 → j=2.8922
[ ][ ][ ]
8 2 3 4 2.8284 0 0 0 2.8284 0.7071 1.0607 1.4142
2 5 1 0 0.7071 2.1213 0 0 0 2.1213 0.1179 −0.4714
=
3 1 7 3 1.0607 0.1179 2.4210 0 0 0 2.4210 0.6425
4 0 3 11 1.4142 −0.4714 0.6425 2.8922 0 0 0 2.8922
[ L] [U ]
[ ]{ } { }
2.8284 0 0 0 d1 1
0.7071 2.1213 0 0 d2
= 0
1.0607 0.1179 2.4210 0 d3 0
1.4142 −0.4714 0.6425 2.8922 d 4 9
1
d 1= =0.3536
2.8284
1
d 2=
2.1213
[ 0−(0.7071 d 1)]=−0.1179
1
d 3=
2.4210
[ 0−(1.0607 d 1+ 0.1179 d 2 ) ]=−0.1492
1
d 4=
2.8922
[ 9−(1.4142 d 1−0.4714 d 2+ 0.6425 d 3 ) ]=2.9528
[ ]{ } { }
2.8284 0.7071 1.0607 1.4142 x1 0.3536
0 2.1213 0.1179 −0.4714 x2
= −0.1179
0 0 2.4210 0.6425 x3 −0.1492
0 0 0 2.8922 x4 2.9528
2.9528
x 4= =1.0210
2.8922
1
x 3=
2.4210
[−0.1492−(0.6425 x 4)]=−0.3326
1
x2=
2.1213
[ −0.1179−(0.1179 x 3−0.4714 x 4 ) ] =0.1898
1
x1=
2.8284
[ 0.3536−(0.7071 x 2+ 1.0607 x 3+ 1.4142 x 4)]=−0.3082
In simultaneous equations
a 11 x 1+ a12 x 2+ ⋯+ a 1n x n=b1
a 21 x 1 + a 22 x 2 + ⋯+ a 2n x n =b2
⋮ ⋮
a n1 x 1 + a n2 x 2+ ⋯+ a nn x n=bn
( k + 1) (k ) (k)
(k + 1) b2 −a 21 x 1 + a 22 x 2 − ⋯ −a 2n x n
x2 =
a 22
(k + 1) ( k+ 1) (k )
(k + 1) bn −a 2n1 x 1 + an2 x 2 − ⋯ −a nn x n
xn =
a nn
|a ii |⩾∑ |aij |
j =1
j≠i
[ ]{ } { }
See this example 1 7 4 x1 2
not diagonally dominant
1 0 9 x2 = 3
6 0 1 x3 5
[ ]{ } { }
6 0 1 x1 5 |6|⩾|0|+ |1|
Rearrange 1 7 4 x2 = 2 |7|⩾|1|+ |4|
1 0 9 x3 3 |9|⩾|1|+ |0|
diagonally dominant
k =0,1,⋯, n
i=1,2,⋯, n
1
[ ]
i −1 n
( k + 1) (k + 1)
x i = bi − ∑ aij x j − ∑ aij x(kj )
a ii j =1 j=i + 1
function x = GaussSeidel(A,b,es,maxit)
% Gauss-Siedel method for i = 1:n
if nargin<4, maxit=50; end C(i,1:n) = C(i,1:n)/A(i,i);
if nargin<3, es=0.00001; end end
[m,n] = size(A); for i = 1:n
if m~=n, error('Matrix A must be square'); end d(i) = b(i)/A(i,i);
C = A; end
for i = 1:n iter = 0;
C(i,i) = 0; while (1)
x(i) = 0; xold = x;
end for i = 1:n
x = x'; x(i) = d(i)-C(i,:)*x;
for i = 1:n if x(i) ~= 0
for j = 1:n; ea(i) = abs((x(i) - xold(i))/x(i)) * 100;
H = abs(A(i,j)); end
Check(i) = abs(A(i,i)) - sum(H); end
if Check(i) < 0 iter = iter+1;
fprintf('The matrix is not strictly diagonally dominant at row if max(ea)<=es | iter >= maxit, break, end
%2i\n\n',i)) end
end
end
end
[ ]{ } { }
0 −2 −7 −3 x1 3
4 0 1 −9 x2
= 3
3 1 1 0 x3 2 a) Check the criterion of diagonally dominant
−1 −5 2 1 5 on every row
x4
b) If not satisfied then rearrange and check
the criterion
[ ]{ } { }
3 1 1 0 x1 2 |3|⩾ |1|+ |1|+ |0| → OK
−1 −5 2 1 x2 OK
= 5
|5|⩾ |1|+ |2|+ |1| →
0 −2 −7 −3 x3 3 |7|⩾ |0|+ |2|+ |3| → OK
4 0 1 −9 x4 3 |9|⩾ |4|+ |0|+ |1| → OK
(k ) (k) (k ) (k ) (k )
(k + 1) 2−1 x 2 −1 x 3 −0 1 x 4 2− x 2 − x 3
x1 = =
3 3
(k + 1) (k ) (k ) (k + 1) (k ) (k)
(k + 1) 5−(−1) x 1 −2 x 3 −1 x 4 5+ x 1 −2 x 3 − x 4
x2 = =
−5 −5
( k + 1) (k + 1) (k ) (k + 1) (k)
( k + 1) 3−(0) x 1 −(−2) x 2 −(−3) x 4 3+ 2 x 2 + 3 x 4
x 3 = =
−7 −7
( k + 1) (k + 1) (k + 1) ( k + 1) ( k + 1)
(k + 1) 3−(4) x1 −(0) x 2 −(1) x 3 3−4 x 1 − x 3
x 4 = =
−9 −9
Based on your understanding of the methods you have learned in this lecture module,
prepare a summary table explaining the requirement of each method if any.
Dazzling Florist offers three sizes of flower arrangements containing roses, daisies
and carnations during Mother’s Day. Each small size arrangement contains one rose,
three daisies and three carnations. The medium size arrangement contains two roses,
four daisies and six carnations. Meanwhile, each large size arrangement contains four
roses, eight daisies and six carnations. The owner of the florist noted that she used a
total of 24 roses, 50 daisies and 48 carnations in filling orders for these three different
types of flower arrangement sizes.
By using Gauss Seidel Iteration method and verify the results with SMath