function [l,A] = Gauss_Elim(n, A)
% Gauss - forward elimination
% Where A is a square matrix of size n by n.

% index and scale vectors
for i = 1:n
    l(i) = i;
    smax = 0.0;
    for j = 1:n
        smax = max(smax, abs(A(i,j) ) );
    end
    s(i) = smax;
end

% determine the pivot row

for k = 1:n-1
    rmax = 0;
    for i = k:n
        r = abs( A(l(i),k) / s(l(i)) );
        if r > rmax
            rmax = r;
            j = i;
        end
    end
    lk = l(k);
    l(k) = l(j);
    l(j) = lk;

% Update the matrix for step k

    for i = k+1:n
        xmult = A(l(i),k)/A(l(k),k);
        A(l(i),k) = xmult; % multiplier goes here
        for j = k+1:n
            A(l(i),j) = A(l(i),j) - xmult * A(l(k),j);
        end
    end
end
for i=1:2*n
    fprintf('A(%i)=%i\n',i, A(i));
end
% end Gauss_Elim