Lec 10 Gauss Elimination1
Lec 10 Gauss Elimination1
For n x n matrix, A:
• If rank(A) = n and is consistent, A has an unique
solution exists
• If rank(A) = n and is inconsistent, A has no solution
exists
• If rank(A) < n and system is consistent, A has an
infinite number of solutions
Matrix
For an n x n system, rank(A) = n automatically
guarantees
that the system is consistent.
2 1 x 6 2 1 x 6
0.5 1 y 1 2 1 y 5
Gaussian Elimination
a11 x1 a12 x2 a13 x3 a1n xn b1
a21 x1 a22 x2 a23 x3 a2 n xn b2
a31 x1 a32 x2 a33 x3 a3n xn b3
am1 x1 am 2 x2 am3 x3 amn xn bm
The second step is to divide by -2.6650 so that the coefficient of x2 is one. Thus
0 x2 2.3965 x3 1.3530 (7)
25 5 1 25 5 1
64 0 4.8 1.56
8 1
144 12 1 0 0 0.7
Forward Elimination
Linear Equations:
A set of n equations and n unknowns
. .
. .
. .
Eqn1
(a21 )
a11
Which will change the Eq. 1 as following:
a21 a21 a
a22 a12 x2 ... a2 n a1n xn b2 21 b1
a11 a11 a11
a 21
Or Where
'
a 22 a 22 a12
a11
'
a22 x2 ... a2' n xn b2'
a 21
a 2' n a 2 n a1n
a11
Forward Elimination
Repeat this procedure for the remaining equations to reduce the set of
equations as
. . .
a x a x ... ann
'.
n.2 2
.'
. n3 3
'
xn bn'
.
.
Forward Elimination
Step 2: Eliminate x2 in the 3rd equation.
Equivalent to eliminating x1 in the 2nd equation using equation 2 as the pivot
equation.
Eqn2
Eqn3 )
(a32
a22
Forward Elimination
This procedure is repeated for the remaining equations to reduce the
set of equations as
a x ... a x b
"
33 3
"
n n
"
3
n 1 n 1
ann. xn. bn
. .
. .
Forward Elimination
At the end of the Forward Elimination steps:
0 0 a33 x 3 b3
Example of a system of 3 equations
Back Substitution
Start with the last equation because it has only
one unknown
bn( n 1)
xn ( n1)
a nn
Solve the second from last equation (n-1)th using xn solved for
previously.
This solves for xn-1.
Back Substitution
Representing Back Substitution for all equations by formula
i 1
aiji 1 x j
n
bi
j i 1
xi i 1 For i=n-1, n-2,….,1
aii
bn( n 1)
and xn ( n1)
a nn
Computer Program
function x = gaussE(A,b,ptol)
% GEdemo Show steps in Gauss elimination and back substitution
% No pivoting is used.
%
% Synopsis: x = GEdemo(A,b)
% x = GEdemo(A,b,ptol)
%
% Input: A,b = coefficient matrix and right hand side vector
% ptol = (optional) tolerance for detection of zero pivot
% Default: ptol = 50 * eps
%
% Output: x = solution vector, if solution exists
A=[25 5 1; 64 8 1; 144 12 1]
b=[106.8; 177.2; 279.2]
if nargin<3, ptol = 50*eps; end
[m,n] = size(A);
if m~=n, error('A matrix needs to be square'); end
nb = n+1; Ab = [A b]; % Augmented system
fprintf('\n Begin forward elimination with Augmented system;\n'); disp(Ab);
% --- Elimination
Computer Program (continued)
% program continued
for i =1:n-1
pivot = Ab(i,i);
if abs(pivot)<ptol, error('zero pivot encountered'); end
for k=i+1:n
factor = - Ab(k,i)/pivot;
Ab(k,i:nb) = Ab(k,i:nb) - (Ab(k,i)/pivot)*Ab(i,i:nb);
fprintf('Multiplication factor is %g\n',factor);
disp(Ab);
pause;
end
fprintf('\n After elimination in column %d with pivot = %f
\n\n',i,pivot);
disp(Ab);
pause;
end
% --- Back substitution
x = zeros(n,1); % Initializing the x vector to zero
x(n) = Ab(n,nb) /Ab(n,n);
for i= n-1:-1:1
x(i) = (Ab(i,nb) - Ab(i,i+1:n)*x(i+1:n))/Ab(i,i);
end