Dr. Jie Zou PHY Chapter 3 Solution of Simultaneous Linear Algebraic Equations: Lecture (III) Note: Besides the main textbook, also see Ref: Applied Numerical Methods with MATLAB for Engineers and Scientists, by S. Chapra, Ch. 9.
Dr. Jie Zou PHY Naïve Gauss Elimination: The general algorithm Problem: Solve a general set of n equations: a 11 x 1 +a 12 x 2 + +a 1n x n =b 1 (1) a 21 x 1 +a 22 x 2 + +a 2n x n =b 2 (2) a n1 x 1 +a n2 x 2 + +a nn x n =b n (n) (I) Forward Elimination of Unknowns Step 1: Eliminate x 1 from Eq. (2) through Eq. (n). Eq. (2) - (a 21 /a 11 ) Eq. (1) Eq. (n) – (a n1 /a 11 ) Eq. (1) The modified system: a 11 x 1 +a 12 x 2 + +a 1n x n =b 1 (1’) a’ 22 x 2 + +a’ 2n x n =b’ 2 (2’) a’ n2 x 2 + +a’ nn x n =b’ n (n’) Repeated
Dr. Jie Zou PHY Step 2: Eliminate x 2 from Eq. (3’) through Eq. (n’). Eq. (3’) - (a’ 32 /a’ 22 ) Eq. (2’) Eq. (n’) – (a’ n2 /a’ 22 ) Eq. (2’) The modified system: a 11 x 1 +a 12 x 2 + a 13 x 3 + +a 1n x n =b 1 (1”) a’ 22 x 2 +a’ 23 x 3 + +a’ 2n x n =b’ 2 (2”) a” 33 x 3 + +a” 3n x n =b” 3 (3”) a” n3 x 3 + +a” nn x n =b” n (n’) Naïve Gauss Elimination: The general algorithm (cont.) Repeated Repeat the procedure … Step n-1: Eliminate x n-1 from the nth equation. Eq. (n) – (a nn-1 /a n-1n-1 ) Eq. (n-1) The modified system: a 11 x 1 +a 12 x 2 + a 13 x 3 + +a 1n x n =b 1 a’ 22 x 2 +a’ 23 x 3 + +a’ 2n x n =b’ 2 a” 33 x 3 + +a” 3n x n =b” 3 a (n-1) nn x n =b (n-1) n
Dr. Jie Zou PHY Naïve Gauss Elimination: The general algorithm (cont.) (II) Back Substitution Step 1: Solve x n from the last equation a (n-1) nn x n =b (n-1) n. x n = b n (n-1) /a nn (n-1) Note: the superscript (n-1) indicates that the elements have been modified (n-1) times. Step 2: Back-substitute the result into the (n-1)th equation to solve for x n-1 ; repeat for x n-2, …, x 1. For example: After x n and x n-1 have been solved, x n-2 is given by x n-2 =(b n-2 -a n-2 n-1 x n-1 -a n-2 n x n )/a n-2 n-2, or x n-2 =(b n-2 -[a n-2 n-1 a n-2 n ]*[x n-1 x n ]’)/a n-2 n-2 (*) Note: (*) will be useful when implementing back substitution on a computer.
Dr. Jie Zou PHY Summary Two phases of Gauss Elimination: Forward elimination Back substitution The end result: An upper triangular system. Your turn: How to implement Gauss elimination on a computer? Augmented Matrix
Dr. Jie Zou PHY Flowchart: Forward elimination Start j=1; j is the index for the unknown, x j. j n-1 Start i=j+1 i n T T Eliminate x j from Row i of Aug Initilization: Define the original [A] and b; return the size of matrix A: [m,n]=size(A) ; define the augmented matrix: Aug=[A b] ; set nb=n+1. i=i+1 Inner Loop End inner loop j=j+1 F F End outer loop Outer Loop
Dr. Jie Zou PHY An Exercise Example 9.3 (Ref. by Chapra): Use Gauss elimination to solve 3x 1 – 0.1x 2 – 0.2x 3 = x 1 + 7x 2 – 0.3x 3 = x 1 – 0.2x x 3 = 71.4 (a) By hand. Show detailed work step by step. (b) Write an M-file MyGaussElimination.m. A copy of the code will be handed out later.