Professional Documents
Culture Documents
Ch.9
1. Forward Elimination
2. Backward Substitution
1
Nave Gauss Elimination
Similar to Elimination of Unknowns
a a a a
21 a11 x1 + 21 a12 x2 + 21 a13 x3 = 21 b1
a11 a11 a11 a11
a21 x1 + a22 x2 + a23 x3 = b2
a a a
a22 21 a12 x2 + a23 21 a13 x3 = b2 21 b1
a11 a11 a11
a a a a
21 a11 x1 + 21 a12 x2 + 21 a13 x3 = 21 b1
a11 a11 a11 a11
Pivot Element
a21 x1 + a22 x2 + a23 x3 = b2
a a a
a22 21 a12 x2 + a23 21 a13 x3 = b2 21 b1
a11 a11 a11
2
Nave Gauss Elimination
1. Forward Elimination
a11 x1 + a12 x2 + a13 x3 = b1 (1)
+ a'22 x2 + a'23 x3 = b'2 (2' )
a31 x1 + a32 x2 + a33 x3 = b3 (3) Elimination Row
Eliminate x1 from (3). Multiply (1) by a31/a11, then subtract the result from (3)
a a a a
31 a11 x1 + 31 a12 x2 + 31 a13 x3 = 31 b1
11
a a11 a11 a11
a31 x1 + a32 x2 + a33 x3 = b3
a31 a31 a31
a32 a a12 x2 + a33 a a13 x3 = b3 a b1
11 11 11
b' '3
x3 =
a ' '33
3
Nave Gauss Elimination
2. Backwards substitution:
a11 x1 + a12 x2 + a13 x3 = b1 (1)
a'22 x2 + a '23 x3 = b'2 (2' )
+ a ' '33 x3 = b' '3 (3' ' )
b' '
x3 = 3
a ' '33
From (2)
b'2 a '23 x2
x2 =
a '22
b1 a12 x2 a13 x3
From (1) x3 =
a11
4
Nave Gauss Elimination Numerically
Implementing
a11 a12 a13 x1 b1 a11 a12 a13 x1 b1
a
21 a22 a23 x2 = b2 0 a'22
a '23 x2 = b'2
a31 a33 x3 b3 a' '33 x3 b' '3
0
a32 0
a21
a'22 = a22 a12
a11 aik
C. Calculate the new bs or right hand side terms b'i = bi bk
akk
a21
b'2 = b2 b1
a11
Now, work backwards row by row, right to left (n-1 row and n
column) n
bi a x
j = i +1
ij j
xi =
aii
5
Nave Gauss Elimination Pseudocode
%Forward Elimination to build an upper triangular matrix
for k=1:n-1
for i=k+1:n
factor = a(i,k)/a(k,k); %normalzing factor (Step A)
for j=k+1:n %move accross the columns loop
a(i,j) = a(i,j) - factor*a(k,j); %(Step B)
end
b(i)=b(i)-factor*b(k); %(Step C)
end
end
%Backward Substitution
x(n)=b(n)/a(n,n); %solve for the last x value
for i=n-1:-1:1
sum = 0;
for j=i+1:n
sum = sum + a(i,j)*x(j);
end
x(i)=(b(i)-sum)/a(i,i);
end
6
Problems with Nave Elimination Methods
When checking D, how small is too small? Solution:
Standardize the determinant.
7
Methods for Improving Solutions Partial Pivoting
code
p=k; %assume row with largest coefficient
big=abs(a(k,k)) %assume the diagnol term is largest
scale
x1 + .2 x2 = 3
0.0000428 x1 + 1x2 = 0.5714
Suggestion:
Employ scaling only to make a decision regarding pivoting
Comparison & row switching are not subject to RO error
Complete solution using original coefficients
8
Gauss-Jordan Elimination
Variation of Gauss Elimination
When an unknown is eliminated it is eliminated from all
equations, not just subsequent ones (Diagonal Matrix Results)
All rows are normalized by their pivot element
Identity Matrix results a a a b
[A]
11 12 13 1
Is augmented
a21 a22 a23 b2
a31 a33 b3
[I ]{x} = {b'} a32
1 0 0 x1 b'1
0 1 0 x = b'
2 2
0 0 1 x3 b'3
Almost identical to Gauss Elimination but, more operations are
required
No back substitution step