# 12 Gaussian Elimination - Naive Gaussian Elimination System...

• Notes
• 15

This preview shows page 1 - 7 out of 15 pages.

“Naive” Gaussian Elimination: System of Equations: 33 6 4 2 5 2 4 9 3 2 3 2 1 3 2 1 3 2 1 = - + - = + - = + + x x x x x x x x x System in matrix form (Ax = b): >> A = [2 3 1; 4 -2 5; 1 4 -6] A = 2 3 1 4 -2 5 1 4 -6 >> b = [9; -2; 33] b = 9 -2 33
First step – form augmented matrix by combining A and b >> C = [A b] C = 2 3 1 9 4 -2 5 -2 1 4 -6 33 In general: [M1 M2 M3 ... Mn] % OK as long as all matrices have same number of rows [M1; M2; M3; ... Mn] % OK as long as all matrices have same number of columns M1 M2 M3 Mn M1 M2 M3 Mn
2 3 1 9 4 -2 5 -2 1 4 -6 33 Pivot row Pivot All elements below the pivot are converted to zero by applying row = row – (element below pivot/ pivot) * pivot row (*** see note next slide ***) In this case row 2 = row 2 – (4/2) * pivot row row 3 = row 3 – (1/2) * pivot row To be zeroed
Note: Instead of row = row – (element below pivot/ pivot) * pivot row Some students seem to prefer row = (pivot/ element below pivot) * row – pivot row Was it taught this way in a first year course? When partial pivoting is used (pivot/ element below pivot) will always be greater than or equal to 1 and the alternate formula makes for larger values. This is a bad idea (see slides at the end of this package) and you will not get full marks on tests if you use this approach.
Row 1 is the pivot row, C(1,1) is the pivot: P = C(1,1); Subtract C(2,1)/P times the pivot row from row 2: >> C(2,:) = C(2,:) - (C(2,1)/P) * C(1,:) C = 2 3 1 9 0 -8 3 -20 1 4 -6 33 Subtract C(3,1)/P times the pivot row from row 3: >> C(3,:) = C(3,:) - (C(3,1)/P) * C(1,:) C = 2.0000 3.0000 1.0000 9.0000 0 -8.0000 3.0000 -20.0000 0 2.5000 -6.5000 28.5000
Same idea applied using row 2 as the pivot row and C(2,2) as the pivot: >> P = C(2,2); >> C(3,:) = C(3,:) - (C(3,2)/P) * C(2,:) C = 2.0000 3.0000 1.0000 9.0000 0 -8.0000 3.0000 -20.0000 0 0 -5.5625 22.2500 For a larger system C(3,3) would be the next pivot and so on.