function [Q,R] = clgs(A)
[m,n]=size(A);
Q=zeros(m,n); R=zeros(n,n);
V=A;
for jj = 1:n
for ii = 1:jj-1
    R(ii,jj)=Q(:,ii)'*A(:,jj);
    V(:,jj)=V(:,jj) - R(ii,jj)*Q(:,ii);
end
R(jj,jj) = norm(V(:,jj));
Q(:,jj) = V(:,jj)/R(jj,jj); 
end
end
