Lecture 8
●
MEEN 357 Homework Solution
1
Lecture-08-Homework-Solution-2009.doc
RMB
1.
Modify the script on page 11 above so that it will implement the Gauss-Jordan
method for the same problem, i.e., for the same
A
and
b
.
Solution
:
The script on page 11 is
%Primitive Gaussian Elimination for n=3.
clc
clear
all
%Enter the Matrix A a 3X3
A=[1,3,1;2,1,1;-2,2,-1]
%Enter the Matrix b a 3X1
b=[1;5;-8]
%Form the Augmented Matrix <A|b>
M=[A,b]
%Step 1: Build zeros below M(1,1)
%The next line checks if M(1,1) is zero.
If so, the %calculation
stops.
if
M(1,1)==0,error(
'You tried to divide by zero'
),
end
for
n=[2 3]
M(n,:)=M(n,:)-(M(n,1)/M(1,1))*M(1,:);
end
%Step 2: Build zeros below the new M(2,2)
if
M(2,2)==0,error(
'You tried to divide by zero'
),
end
for
n=3
M(n,:)=M(n,:)-(M(n,2)/M(2,2))*M(2,:);
end
if
M(3,3)==0,error(
'You tried to divide by zero'
),
end
x3=M(3,4)/M(3,3)
x2=(M(2,4)-M(2,3)*x3)/M(2,2)
x1=(M(1,4)-M(1,3)*x3-M(1,2)*x2)/M(1,1)
The last three lines represent the back substitution phase of Gaussian Elimination.
When
one adopts Gauss-Jordan elimination, this step is replaced by row operations that built
zeros above the (3,3) element and, next, above the (2,2) element.