% gauss_el.m    Gauss elimination without pivoting
function [Amod,bmod]=gauss_el(A,b,display)

% On entry: A is a square matrix
%           b is a column vector of the same dimension
%           display is 1 if step-by-step display desired, 0 otherwise
% On exit: Amod and bmod are the result of applying Gauss elimination to
%          the system Ax=b. No row or column pivoting is done, so the
%          process is unstable and may break down even if A is nonsingular.
%
n = length(b);
if size(A) ~= [n,n] | size(b) ~=[n,1],
   error('mismatched dimension')
end;
for k = 1:n-1,  % the kth step eliminates the kth column below the diagonal
              % element
    for i = k+1:n,  % We need to work on rows k+1 to n of the kth column
        mult = A(i,k)/A(k,k);  % multiplier which will give desired zero
        A(i,:) = A(i,:) - mult*A(k,:); % subtract mult*(kth row) to ith row
        b(i) = b(i) -mult*b(k);       % apply same row operation to b
        if display
           A
           pause;
        end;
    end;
end;
Amod = A;
bmod = b;
