Uploaded by nazz WeeHaa

Chapter 3 Solution of Linear Systems (Part 1)

advertisement
BEKG 2452 Numerical Methods
Chapter 3: Solution of Linear
Systems
- Gauss Elimination
- LU Decomposition
- Gauss-Seidel Method
BEKG 2452 Numerical Methods
Solution of Linear Systems, 𝐴𝐱 = 𝐛
LU
Decomposition
Gauss
Seidel
Gauss
Elimination
- A=LU
- Apply forward
and backward
substitution
- Strictly diagonal
dominant matrix
- Run iteration
-Row Reduction
- GE
with/without
partial pivoting
May be Exact or Approximated solution
1
BEKG 2452 Numerical Methods
3.1 Gauss Elimination
3.1.1 Elementary Row Operation
Aim to reduce a matrix into an upper triangular
matrix.
I.e.
𝑿 𝑋 𝑋
0 𝑿 𝑋
0 0 𝑿
X can be any different
values
Pivot
BEKG 2452 Numerical Methods
3.1.1 Elementary Row Operation
1) Interchange any two rows
- Interchange two rows 𝑖 and 𝑗: π‘Ÿ+ ↔ π‘ŸE.g.
0 1 12 ↔13 2 3
2 3
0 1
2
BEKG 2452 Numerical Methods
3.1.1 Elementary Row Operation
2) Row replacement operation:
- Replace row 𝑗 by π‘šπ‘Ÿ+ + π‘Ÿ- :
π‘šπ‘Ÿ+ + π‘Ÿ- → π‘Ÿ3
= −3
1
−2
π‘š=−
=2
1
π‘š=−
𝟏 0 3
3 5 −2
−2 1 −3
A
: 13 <1>
B
π‘š=−
1
5
𝟏
0
0
0
πŸ“
0
:;12 <13
=12 <1>
𝟏
0
0
0
πŸ“
1
3
−11
3
3
−11
26/5
BEKG 2452 Numerical Methods
Example:
Reduce the matrix to an upper triangular matrix.
−1 2 −5
𝐴 = 2 −1 6
1
1
3
3
BEKG 2452 Numerical Methods
Solution:
−1 2 −5
2 −1 6
1
1
3
:13 <1>
=12 <13
12 <1>
−1 2 −5
0 3 −4
0 3 −2
−1 2 −5
0 3 −4
0 0 2
BEKG 2452 Numerical Methods
Example 3.1:
Reduce the following matrix to an upper triangular
matrix.
2 2 3
𝐴 = −2 1 5
1 3 4
4
BEKG 2452 Numerical Methods
3.1.2 Gauss Elimination Algorithm
Basic idea:
Solve the equivalent system which is in a simpler form
compared to the original linear system.
Flow:
π‘ŽAA
π‘Ž=A
π‘Ž;A
π‘ŽAA π‘₯A + π‘ŽA= π‘₯= + π‘ŽA; π‘₯; = 𝑏A
π‘Ž=A π‘₯A + π‘Ž== π‘₯= + π‘Ž=; π‘₯; = 𝑏=
π‘Ž;A π‘₯A + π‘Ž;= π‘₯= + π‘Ž;; π‘₯; = 𝑏;
π‘ŽA;
π‘Ž=;
π‘Ž;;
π‘₯A
𝑏A
π‘₯= = 𝑏=
π‘₯;
𝑏;
Matrix form
Linear System
Backward
Substitution
π‘ŽA=
π‘Ž==
π‘Ž;=
Row
Reduction
π‘ŽAA
π‘Ž=A
π‘Ž;A
π‘ŽA=
π‘Ž==
π‘Ž;=
π‘ŽA;
π‘Ž=;
π‘Ž;;
𝑏A
𝑏=
𝑏;
Augmented Matrix
BEKG 2452 Numerical Methods
Example:
Solve the following linear system by using
Gauss Elimination.
2π‘₯A + 3π‘₯= − π‘₯; = 2
4π‘₯A + 4π‘₯= − π‘₯; = −1
−2π‘₯A − 3π‘₯= + 4π‘₯; = 1
Solution:
Transform the linear system into matrix form:
2
3 −1 π‘₯A
2
4
4 −1 π‘₯= = −1
−2 −3 4 π‘₯;
1
5
BEKG 2452 Numerical Methods
Solution:
Augmented Matrix:
2
3 −1 2
4
4 −1 −1
−2 −3 4
1
Row reduction:
2
3 −1 2
4
4 −1 −1
−2 −3 4
1
:=12 <13
12 <1>
2 3 −1 2
0 −2 1 −5
0 0
3
3
Backward substitution:
π‘₯A
−3
∴ π‘₯= = 3
π‘₯;
1
BEKG 2452 Numerical Methods
Example 3.2:
Solve the following linear system by using Gauss
Elimination.
π‘₯A + 2π‘₯= + 3π‘₯; = 9
2π‘₯A − π‘₯= + π‘₯; = 8
3π‘₯A
− π‘₯; = 3
6
BEKG 2452 Numerical Methods
3.1.3 Gauss Elimination with Partial Pivoting
Basic idea:
Avoid to have pivot element which is near to zero (it may
cause to division by zero after normalization)
Flow:
π‘ŽAA π‘₯A + π‘ŽA= π‘₯= + π‘ŽA; π‘₯; = 𝑏A
π‘Ž=A π‘₯A + π‘Ž== π‘₯= + π‘Ž=; π‘₯; = 𝑏=
π‘Ž;A π‘₯A + π‘Ž;= π‘₯= + π‘Ž;; π‘₯; = 𝑏;
Linear System
π‘ŽAA
π‘Ž=A
π‘Ž;A
π‘ŽA=
π‘Ž==
π‘Ž;=
π‘ŽA;
π‘Ž=;
π‘Ž;;
𝑏A
𝑏=
𝑏;
Augmented Matrix
Row Reduction
- Pivot element is the largest absolute
value among entries underneath it
- Use only π‘Ÿ+ ↔ π‘Ÿ- and π‘šπ‘Ÿ+ + π‘Ÿ- → π‘Ÿ-
Backward
Substitution
BEKG 2452 Numerical Methods
Example:
Solve the following linear system by using Gauss
Elimination with partial pivoting.
0.3π‘₯A − 0.2π‘₯= + 10π‘₯; = 71.4
3π‘₯A − 0.1π‘₯= − 0.2π‘₯; = 7.85
0.1π‘₯A + 7π‘₯= − 0.3π‘₯; = −19.3
Solution:
Augmented matrix:
0.3 −0.2 10
71.4
3 −0.1 −0.2 7.85
0.1
7
−0.3 −19.3
7
BEKG 2452 Numerical Methods
Solution (cont.):
Row reduction:
Max 0.3 , 3 , 0.1 = 3
12 ↔13
:O.A12 <13
:O.O;;;12 <1>
0.3 −0.2 10
71.4
3 −0.1 −0.2 7.85
0.1
7
−0.3 −19.3
πŸ‘ −0.1 −0.2 7.85
0.3 −0.2 10
71.4
0.1
7
−0.3 −19.3
3 −0.1
−0.2
7.85
0 −0.19
10.02
70.615
0 7.0033 −0.2933 −19.5617
Max −0.19 , 7.0033
= 7.0033
BEKG 2452 Numerical Methods
Solution (cont.):
13 ↔1>
3
−0.1
0 πŸ•. πŸŽπŸŽπŸ‘πŸ‘
0 −0.19
O.O=SA13 <1>
−0.2
7.85
−0.2933 −19.5617
10.02
70.615
3 −0.1
−0.2
7.85
0 7.0033 −0.2933 −19.5617
0
0
10.1921 71.1451
Backward substitution:
π‘₯A
2.9987
∴ π‘₯= = −2.5007
π‘₯;
6.9804
8
BEKG 2452 Numerical Methods
Example 3.3:
Solve the following linear system by using
Gauss Elimination with partial pivoting.
2π‘₯A + 3π‘₯= − π‘₯; = 2
4π‘₯A + 4π‘₯= − π‘₯; = −1
−2π‘₯A − 3π‘₯= + 4π‘₯; = 1
Solution:
Augmented matrix:
2
3 −1 2
4
4 −1 −1
−2 −3 4
1
BEKG 2452 Numerical Methods
3.2 LU Decomposition
Given a linear system,
𝐴𝐱 = 𝐛
Decompose 𝐴 = πΏπ‘ˆ
πΏπ‘ˆ 𝐱 = 𝐛
𝐿 π‘ˆπ± = 𝐛
Let π‘ˆπ± = 𝐲, ∴ 𝐿𝐲 = 𝐛
solve 𝐿𝐲 = 𝐛 for 𝐲
(forward substitution)
solve π‘ˆπ± = 𝐲 for 𝐱
(backward substitution)
9
BEKG 2452 Numerical Methods
3.2 LU Decomposition
An 𝑛×𝑛 nonsingular matrix can be decomposed into
a lower triangular matrix (L) and an upper triangular
matrix (U) as follows:
π‘ŽAA
π‘Ž=A
π‘Ž;A
π‘ŽA=
π‘Ž==
π‘Ž;=
π‘ŽA;
1
π‘Ž=; = 𝑙=A
π‘Ž;;
𝑙;A
𝑙;=
𝑨
=
𝑳
0
1
0 𝑒AA
0 0
1 0
𝑒A=
𝑒==
0
𝑒A;
𝑒=;
𝑒;;
𝑼
BEKG 2452 Numerical Methods
3.2.1 Steps of LU Decomposition
Step 1: Construct L and U
1
𝑙=A
𝑙;A
0
1
𝑙;=
0 𝑒AA
0 0
1 0
Multiply L and U:
𝑒AA
𝑒A=
𝑙=A 𝑒AA
𝑙=A 𝑒A= + 𝑒==
𝑙;A 𝑒AA 𝑙;A 𝑒A= + 𝑙;= 𝑒==
LU
𝑒A=
𝑒==
0
= A
𝑒A;
π‘ŽAA
𝑒=; = π‘Ž=A
π‘Ž;A
𝑒;;
π‘ŽA=
π‘Ž==
π‘Ž;=
π‘ŽA;
π‘Ž=;
π‘Ž;;
𝑒A;
π‘ŽAA
𝑙=A 𝑒A; + 𝑒=;
= π‘Ž=A
π‘Ž;A
𝑙;A 𝑒A; + 𝑙;= 𝑒=; + 𝑒;;
π‘ŽA=
π‘Ž==
π‘Ž;=
π‘ŽA;
π‘Ž=;
π‘Ž;;
Compare each of the entries to obtain the values for u and l.
i.e. 𝑒AA = π‘ŽAA
10
BEKG 2452 Numerical Methods
3.2.1 Steps of LU Decomposition
Step 2: Solve 𝐿𝐲 = 𝐛 for 𝐲 by using forward substitution
𝐴𝐱 = 𝐛
When 𝐴 = πΏπ‘ˆ,
𝐿(π‘ˆπ±) = 𝐛
Let π‘ˆπ± = 𝐲,
𝐿𝐲 = 𝐛
1
𝑙=A
𝑙;A
0
1
𝑙;=
𝑏A
0 𝑦A
0 𝑦= = 𝑏=
1 𝑦;
𝑏;
𝑦A = 𝑏A
𝑙=A 𝑦A + 𝑦= = 𝑏=
𝑙;A 𝑦A + 𝑙;= 𝑦= + 𝑦; = 𝑏;
Forward
substitution
BEKG 2452 Numerical Methods
3.2.1 Steps of LU Decomposition
Step 3: Solve π‘ˆπ± = 𝐲 for 𝐱 by using backward substitution
π‘ˆπ± = 𝐲
𝑒AA
0
0
𝑒A=
𝑒==
0
𝑒A;
𝑒=;
𝑒;;
𝑦A
π‘₯A
π‘₯= = 𝑦=
𝑦;
π‘₯;
𝑒;; π‘₯; = 𝑦;
𝑒== π‘₯= + 𝑒=; π‘₯; = 𝑦=
𝑒AA π‘₯A + 𝑒A= π‘₯= + 𝑒A; π‘₯; = 𝑦A
Backward
substitution
11
BEKG 2452 Numerical Methods
Example:
Solve the following linear system by using
LU decomposition.
2π‘₯A + 3π‘₯= − π‘₯; = 2
4π‘₯A + 4π‘₯= − π‘₯; = −1
−2π‘₯A − 3π‘₯= + 4π‘₯; = 1
Solution:
Transform the linear system into matrix form:
2
3 −1 π‘₯A
2
4
4 −1 π‘₯= = −1
−2 −3 4 π‘₯;
1
BEKG 2452 Numerical Methods
Solution (cont.):
Step 1: Construct L and U
1
𝑙=A
𝑙;A
0
1
𝑙;=
Multiply L and U:
𝑒AA
𝑙=A 𝑒AA
𝑙;A 𝑒AA
0 𝑒AA
0 0
1 0
𝑒A=
𝑙=A 𝑒A= + 𝑒==
𝑙;A 𝑒A= + 𝑙;= 𝑒==
LU = A
𝑒A=
𝑒==
0
𝑒A;
2
𝑒=; = 4
𝑒;;
−2
3
4
−3
−1
−1
4
𝑒A;
2
𝑙=A 𝑒A; + 𝑒=;
= 4
𝑙;A 𝑒A; + 𝑙;= 𝑒=; + 𝑒;;
−2
3
4
−3
−1
−1
4
Compare each of the entries to obtain the values for u and l.
∴
𝐿=
1 0 0
2 1 0
−1 0 1
2 3 −1
π‘ˆ = 0 −2 1
0 0
3
12
BEKG 2452 Numerical Methods
Solution (cont.):
Step 2: Solve 𝐿𝐲 = 𝐛 for 𝐲 by using forward substitution
𝐴𝐱 = 𝐛,
πΏπ‘ˆ 𝐱 = 𝐛 ⇒
when 𝐴 = πΏπ‘ˆ,
Let π‘ˆπ± = 𝐲, we have
1
2
−1
By forward substitution:
𝑦A = 2,
𝐿 π‘ˆπ± = 𝐛.
𝐿𝐲 = 𝐛
2
0 0 𝑦A
𝑦
1 0 = = −1
1
0 1 𝑦;
2𝑦A + 𝑦= = −1,
2(2) + 𝑦= = −1,
𝑦= = −5
−𝑦A + 𝑦; = 1,
−(2) + 𝑦; = 1,
𝑦; = 3
𝑦A
2
∴ 𝑦= = −5
𝑦;
3
BEKG 2452 Numerical Methods
Solution (cont.):
Step 3: Solve π‘ˆπ± = 𝐲 for 𝐱 by using backward substitution
π‘ˆπ± = 𝐲
2 3 −1 π‘₯A
2
0 −2 1 π‘₯= = −5
0 0
3 π‘₯;
3
By Backward substitution:
3π‘₯; = 3, −2π‘₯= + π‘₯; = −5,
π‘₯; = 1 −2π‘₯= + (1) = −5,
π‘₯= = 3
2π‘₯A + 3π‘₯= − π‘₯; = 2
2π‘₯A + 3(3) − (1) = 2
π‘₯A = −3
π‘₯A
−3
π‘₯
∴ = = 3
π‘₯;
1
13
BEKG 2452 Numerical Methods
Alternate way to decompose A into LU
Row reduction:
Example 1:
𝟏
𝐴= 2
3
2
−1
0
3
1
−1
:=12 <13
:;12 <1>
1
0
0
÷1
2
−πŸ“
−6
3
−5
−10
e
: 13 <1>
B
1
0
0
2
−5
0
÷ −4
÷ −5
1
∴𝐿= 2
3
3
−5 = π‘ˆ
−πŸ’
0
1
6/5
0
0
1
BEKG 2452 Numerical Methods
Alternate way to decompose A into LU
Row reduction:
Example 2:
1
3
𝐴=
−1
−3
:h13 <1i
1
0
0
0
−2
−9
2
−6
−2
−3
0
0
−2
0
4
26
−2
6
2
−4
−3
−9
7
2
−3
0
4
−7
1
3
∴𝐿=
−1
−3
:;12 <13
12 <1>
;12 <1i
=1> <1i
0
1
0
4
1
0
0
0
−2
−3
0
−12
1
0
0
0
−2
−3
0
0
0
0
1
−2
0
0
0
1
−2
6
2
0
−2
6
2
20
−3
0
4
−7
−3
0
=π‘ˆ
4
1
14
BEKG 2452 Numerical Methods
Example 3.4:
Solve the following linear system by using LU
decomposition.
π‘₯A + 2π‘₯= + 3π‘₯; = 9
2π‘₯A − π‘₯= + π‘₯; = 8
3π‘₯A
− π‘₯; = 3
BEKG 2452 Numerical Methods
Example 3.5:
Solve the following linear system by using LU
decomposition.
1.012π‘₯A − 2.132π‘₯= + 3.104π‘₯; = 1.984
−2.132π‘₯A + 4.096π‘₯= − 7.013π‘₯; = −5.049
3.104π‘₯A − 7.013π‘₯= + 0.014π‘₯; = −3.895
15
BEKG 2452 Numerical Methods
3.3 Gauss Seidel
Strictly Diagonal Dominant Matrix
- The magnitude of diagonal entry in a row is
larger than the sum of the magnitudes of all the
other entries in that row:
π‘Žjj > ∑m
-nj π‘Žj- for π‘˜ = 1,2, … , 𝑁)
6 > 2 + 3
e.g.
6
−1
3
2
−9
0
3
4
−7
−9 > −1 + 4
−7 > 3 + 0
BEKG 2452 Numerical Methods
3.3 Gauss Seidel
Basic Idea:
Solve unknown variable of a linear system iteratively by using
previously computed results as soon as they are available.
Flow:
π‘ŽAA π‘₯A + π‘ŽA= π‘₯= + π‘ŽA; π‘₯; = 𝑏A
π‘Ž=A π‘₯A + π‘Ž== π‘₯= + π‘Ž=; π‘₯; = 𝑏=
π‘Ž;A π‘₯A + π‘Ž;= π‘₯= + π‘Ž;; π‘₯; = 𝑏;
Strictly diagonal dominant
matrix arrangement
Linear System
Stop iteration when
Form the iterative sequence
𝐱 (j) − 𝐱 (j:A)
=
(j)
max π‘₯+
Av+vw
−
r
(j:A)
π‘₯+
(j<A)
<πœ€
(known as infinity norm)
π‘₯A
(j<A)
, π‘₯=
(j<A)
, π‘₯;
(O)
(O)
(O)
Initial guess: (π‘₯A , π‘₯= , π‘₯; )
16
BEKG 2452 Numerical Methods
3.3.1 Gauss Seidel Iterative Sequence
From 𝐴𝐱 = 𝐛 (A is a strictly diagonal dominant matrix),
π‘ŽAA π‘₯A + π‘ŽA= π‘₯= + π‘ŽA; π‘₯; = 𝑏A
π‘Ž=A π‘₯A + π‘Ž== π‘₯= + π‘Ž=; π‘₯; = 𝑏=
π‘Ž;A π‘₯A + π‘Ž;= π‘₯= + π‘Ž;; π‘₯; = 𝑏;
1
(j)
j
𝑏 − π‘ŽA= π‘₯= − π‘ŽA; π‘₯;
π‘ŽAA A
1
(j)
j<A
=
𝑏= − π‘Ž=A π‘₯A
− π‘Ž=; π‘₯;
π‘Ž==
(j<A)
π‘₯A
(j<A)
π‘₯=
(j<A)
π‘₯;
=
=
1
(j<A)
j<A
𝑏; − π‘Ž;A π‘₯A
− π‘Ž;= π‘₯=
π‘Ž;;
BEKG 2452 Numerical Methods
Example:
Solve the following linear system by using
Gauss Seidel.
12π‘₯A + 3π‘₯= − π‘₯; = 15
2π‘₯A − π‘₯= + 10π‘₯; = 30
π‘₯A + 8π‘₯= + π‘₯; = 20
Start the initial guess with 𝐱 (O) = 𝟎 and stop the
iteration when 𝐱 (j) − 𝐱 (j:A)
< 0.001
r
17
BEKG 2452 Numerical Methods
Solution:
Check for strictly diagonal dominant:
12π‘₯A + 3π‘₯= − π‘₯; = 15
2π‘₯A − π‘₯= + 10π‘₯; = 30
π‘₯A + 8π‘₯= + π‘₯; = 20
12π‘₯A + 3π‘₯= − π‘₯; = 15
π‘₯A + 8π‘₯= + π‘₯; = 20
2π‘₯A − π‘₯= + 10π‘₯; = 30
π‘Ÿ= ↔ π‘Ÿ;
Iterative Sequence:
1
(j)
(j)
15 − 3π‘₯= + π‘₯;
12
1
(j<A)
(j)
j<A
π‘₯=
= 20 − π‘₯A
− π‘₯;
8
1
(j<A)
(j<A)
(j<A)
π‘₯;
=
30 − 2π‘₯A
+ π‘₯=
10
(j<A)
π‘₯A
=
BEKG 2452 Numerical Methods
Solution:
(j)
max π‘₯+
Av+vw
(j)
(j)
(j)
𝐱 (j) − 𝐱 (j:A)
π‘˜
π‘₯A
π‘₯𝟐
π‘₯πŸ‘
0
0
0
0
1
1.2500
2.3438
2.9844
2.9844
2
0.9128
2.0129
3.0187
0.0343
3
0.9983
1.9979
3.0001
0.0855
4
1.0005
1.9999
2.9999
0.0022
5
1.0000
2.0000
3.0000
0.0005
(j:A)
− π‘₯+
r
π‘₯A
1
∴ π‘₯= = 2
π‘₯;
3
18
BEKG 2452 Numerical Methods
Example 3.6:
Solve the following linear system by using Gauss Seidel.
1)
0.3π‘₯A − 0.2π‘₯= + 10π‘₯; = 71.4
3π‘₯A − 0.1π‘₯= − 0.2π‘₯; = 7.85
0.1π‘₯A + 7π‘₯= − 0.3π‘₯; = −19.3
2)
−π‘₯A + π‘₯= + 7π‘₯; = −6
4π‘₯A − π‘₯= − π‘₯; = 3
−2π‘₯A + 6π‘₯= + π‘₯; = 9
Start the initial guess with 𝐱 (O) = 𝟎 and stop the iteration when
𝐱 (j) − 𝐱 (j:A) r < 0.0005
19
Download