clear all
A=[1 2 3 4;
3 4 8 9;
8 20 4 3;
5 6 7 8];
C=[3;4;8;10];
newA=GaussElimination(A,C);
[n,n]=size(A);
Aprime=newA(1:n,1:n)
Cprime=newA(:,n+1)
x1=A\C
x2=Aprime\Cprime
function newA=GaussElimination(A,C)
%Augment A and C
[n,n]=size(A);
newA=[A C];
for k=1:n-1
for i=k+1:n
factor=newA(i,k)/newA(k,k);
for j=k:n+1
newA(i,j)=newA(i,j)-factor*newA(k,j);
end
end
newA
end
end