function [Q,R] = clgs(A)
% CLGS classical Gram-Schmidt (unstable)
%
% See also MGS, QR
%
% tire de: LN Trefethen & D Bau III, Numerical Linear Algebra, 1997 SIAM Philadelphia 


[m,n] = size(A);
v = zeros(m,n);
R = zeros(n,n);
Q = zeros(m,n);

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