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