Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1 for all eq.s k greater than j a) multiply eq. j by a kj /a jj b) subtract the result from eq. K This leads to upper triangular
2) now backsubstitute a) determine x n from b) put x n into n-1 eq. c) solve for x n-1 d) repeat from b), moving back to n-2, n-3, etc. until all equations are solved
Matlab code
Operation counting Important as matrix gets large For Gauss elimination elimination routine uses on the order of operations backsubstitution uses
Problems with Gauss elimination (as done last time) 1) division by zero 2) round off errors 3) ill conditioned systems
Division by zero Using first eq. to eliminate x1 in second eq. means dividing by 0
Pivoting developed to avoid this find row with largest absolute value under pivot element switch rows More later
Round off errors With more than n 3 /3 operations, get a lot of chopping. More important - error is propagted More than 100 equations - round can be very important - system dependent
Ill conditioned systems - small changes in coefficients lead to large changes in solution Round-off errors especially important in ill- conditioned systems
Recall ill conditioned system from graphical methods
Can write as Since slopes are almost equal
becomes
Determinant close to zero indicates ill- conditioned set of equations. How close? No clear answer Problem of scale
Multiply our set of equations by 100
However, graphically No change
Scaling Make maximum element in any row =1
Another problem - singular systems Two equations in the set are the same Determinant is 0.
Calculating determinant using Gauss elimination Given then
How to avoid pitfalls higher precision pivoting scaling
Partial Pivoting Determine the largest coefficient in the column below pivot element Then switch rows (Compete pivot switches columns also, but is rarely used.)
Example: Exchange rows 2 and 3 And now eliminate
Algorithm for Gauss elimination using improvements 1) first eliminate for each eq. j, j=1 to n-1 first scale each equation k greater than j then pivot now a) multiply eq. j by a kj /a jj b) subtract the result from eq. k
The Gauss Jordan method Major difference - eliminate unknowns from all rows, not just subsequent ones Normalize matrix so all entries are 1 Leads to identity matrix instead of upper triangular Backsubstitution is easy