clear all; 
clc; 

a = input('Provide the augmented matrix: ');

[m,n]=size(a);   % m = number of rows, n = number of columns

% Elementary operation to get row echelon form
for i=1:m-1
    for j=i+1:m
        a(j,:)=a(j,:)-a(i,:)*(a(j,i)/a(i,i));
    end
end

% now the Augmented matrix is in row echelon form
% we can now solve for unknowns

x=zeros(1,m); %initialization of solution column

for k=m:-1:1 %the last row has only one entry. we solve that first and then back-subsitute to the top
    c=0;
    for l=2:m
        c=c+a(k,l)*x(l);
    end
    x(k)=(a(k,n)-c)/a(k,k);
end

disp('Solution from basic coding:');
disp(x');

%Direct command for producing "special" row reduced echeleon form

sol = rref(a);

% the solution is the last column
disp('Solution from using rref command');
disp(sol(:,n));