function [P,L,U]=gauss_plu(A)
% function [P,L,U]=gauss_plu(A)
% performs an LU factorization of the matrix A using
% Gaussian reduction.
% A is the matrix to be factored.
% P is a permutation matrix
% L is a lower triangular factor with 1's on the diagonal
% U is an upper triangular factor.
% A = P * L * U

% your name and the date

n=numel(A(:,1));
L=eye(n);     % square n by n identity matrix
P=eye(n);     % square n by n identity matrix
U=A;
for Jcol=1:n
  % First, choose a pivot row
  [ colMax, pivotShifted ] = max ( abs ( U(Jcol:n, Jcol ) ) );

  < code to do pivoting >

  for Irow=Jcol+1:n
    % compute Irow multiplier and save in L(Irow,Jcol)
    L(Irow,Jcol)=U(Irow,Jcol)/U(Jcol,Jcol);
  
    % multiply row "Jcol" by L(Irow,Jcol) and subtract from row "Irow"
    U(Irow,Jcol:n)=U(Irow,Jcol:n)-L(Irow,Jcol)*U(Jcol,Jcol:n);
  end
end

