function x = simplegauss(A, b)
%SIMPLEGAUSS - solve the system of linear equations A*x = b
%                     using 'naive' gaussian elimination

% This version of the code uses vectorization 

    [n, ~] = size(A);

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

    % preallocate the solution vector
    x = zeros(n, 1);

    % Back substitution
    for k = n:-1:1
        x(k) = b(k)/A(k,k);
        i = 1:k-1;
        b(i) = b(i) - A(i,k)*x(k);
    end

end
