% Skript zur Musterlösung
%
% Numerische Mathematik, SS 2013
%
% Test QR-Zerlegung
%
% Ingolf Busch, Juni 2013

[U,~]=qr(randn(80));
[V,~]=qr(randn(80));
N=1:80;
S=diag(2.^-N);

A=U*S*V';


[Q1,R1] = my_gs(A);
[Q2,R2] = my_mgs(A);

[Q3,R3] = my_hqr(A);
[Q4,R4] = my_gqr(A);

figure;
semilogy(N,abs(diag(R1)),'o',N,abs(diag(R2)),'*',N,eps*ones(size(N)),'r--');
legend('gs','mgs','eps','Location','NorthEast');

figure;
semilogy(N,abs(diag(R3)),'o',N,abs(diag(R4)),'*',N,eps*ones(size(N)),'r--');
legend('hqr','gqr','eps','Location','NorthEast');