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