function [x] = gauss(A,b)
%
% x = Gauss(A,b)
% Naiv Gauss Elimination
%

n = length(b);
x = zeros(n,1);

% Forward elimination
for k=1:n-1
    for i=k+1:n
        m = A(i,k)/A(k,k);
        for j=k+1:n
            A(i,j) = A(i,j)-m*A(k,j);
        end
        b(i) = b(i)-m*b(k);
    end
end

% backward solution
x(n) = b(n)/A(n,n);
for k=n-1:-1:1
    res = b(k);
    for s=k+1:n
        res = res-A(k,s)*x(s);
    end
    x(k) = res/A(k,k); 
end


