You are on page 1of 1

GAUSS ELIMINATION METHOD

function []= gauss_elim2(A,b)


[m n]=size(A);
[n p]=size(b);
if(m==n)
if(rank([A b])==rank(A))
f=1;
fprintf('The given system of linear
is consistent');
else fprintf('The given system of linear equations is
inconsistent');
fprintf('Thus no solution');
end
if(f==1)
X = zeros(n,p);
for i=1:n-1
mult=-A(i+1:n,i)/A(i,i);
A(i+1:n,:)= A(i+1:n,:)+
mult*A(i,:);
b(i+1:n,:)= b(i+1:n,:)+ mult*b(i,:);
end
X(n,:) = b(n,:)/A(n,n);
for i = n-1:-1:1
X(i,:) = (b(i,:) - A(i,i+1:n)*X(i+1:n,:))/A(i,i);
End
fprintf('the solution of the given system of equations is:\n');
disp(X);
end

itr=n*(n+1)/2;
fprintf('the number of iterations in which gauss elimination
can be performed are: %d\n',itr);
else
fprintf('Gauss Elimination cannot be done');
end

OUTPUT:

You might also like