% Forward elimination part of Scaled Partial pivoting "update of 'b'" 
% and the backward substitution

function [x] = NaiveSolve(A,b)
%Given input:
%   coefficient matrix 'A' and RHS 'b' 
% will get output the solution of "Ax=b"
%    'x'
[A] = NaiveGauss(A);
% This call for the function Gauss gives 'A=LU' and the index vector 'l'
[n,n] = size(A); 
p = length(b);

if abs(p-n)>0
   error('The RHS b has the wrong dimension')
end

for i=1:n
    l(i)=i;
end
% Forward Elimination update of 'b'  
    for k=1:n-1
    for i=k+1:n
        b(l(i))=b(l(i)) - A(l(i),k)*b(l(k));
    end
    end
% Backward Substitution
x(n) = b(l(n))/A(l(n),n);
for i=n-1:-1:1
    sum=b(l(i));
    for j=i+1:n
        sum=sum - A(l(i),j) * x(j);
    end
    x(i)=sum/A(l(i),i);
end    
