function [q,r] = clgs(A)
%compute the classical gram-schmidt of a matrix
%columns are assumed to be independent

[m,n] = size(A);

v(:,1) = A(:,1);
r(1,1) = norm(v(:,1));
q(:,1) = v(:,1)/r(1,1);

for j = 2:n,
   v(:,j) = A(:,j);
   for i = 1:j-1,
      r(i,j) = q(:,i)'*A(:,j);
      v(:,j) = v(:,j) - r(i,j)*q(:,i);
   end
   r(j,j) = norm(v(:,j));
   q(:,j) = v(:,j)/r(j,j);
end

