%NxN is the size of the matrix we compute the QR-factorization of.
N=100
clear U X V S A q1 q2
%This code creates 2 NxN random orthogonal matrics U and V.
[U,X]=qr(randn(N));
[V,X]=qr(randn(N));
%We place 2^(-(-1:-1:-N)) along the diagonal
S=diag(2.^(-1:-1:-N));
[S(1,1), S(N,N)]
%Build the matrix A with SVD U*S*V
A=U*S*V;
sz=size(A)
%Use the two GS-algorithms to compute the QR-factorization
[qc,rc]=clgs(A);
[qm,rm]=mgs(A);
%Plot the diagonal entries of the "R" factor.
figure, semilogy(1:N,diag(rc),'r',1:N,diag(rm),'g')
title('Diagonal entries of R')
%Compute Q'*Q to check to see how orthogonal the columns are
q1=qc'*qc;
q2=qm'*qm;
figure, plot(1:N,max(eye(sz(1))-q1),'r',1:N,max(eye(sz(1))-q2),'g')
title('Column maxima of Q^tQ-Id')

