function [L,R] = LRtest(A)
%  [L,R]  = LRtest(A) if A is a square matrix
%  performs the LR decomposition of the matrix A
%  !!!!!!!!!!!! NO PIVOTING IS DONE !!!!!!!!!!!!!!!!!
%  this is for instructional purposes only

%  a test on the dimensions
[n,m] = size(A);
if (n ~= m) 
  error ('LPtest: matrix has to be square')
end%if

R = zeros(size(A));
L = eye(n);

for k = 1:n
  R(k,k:n) = A(k,k:n);
  if ( R(k,k) == 0) 
    error ('LRtest: division by 0') 
  end%if
% divide  numbers in k-th column, below the diagonal by A(k,k)
  L(k+1:n,k) = A(k+1:n,k)/R(k,k);
% apply the row operations to A
  for j = k+1:n
     A(j,k+1:n) = A(j,k+1:n) - A(k,k+1:n)*L(j,k);
  end%for
end%for
end%function
