% This is the script from the lecture notes 22.  It can
% be used as a framework for programming assignment 04.

m=10;
n=10000;
b=rand(n,1);
Gamma(:,1)=b;
for j=2:m
    Gamma(:,j)=multA(Gamma(:,j-1));
end
[Q,R]=qr(Gamma,0);
clear Gamma;
for j=1:m
	AQ(:,j)=multA(Q(:,j));
end
z=AQ\b;
x=Q*z;
r=b-multA(x);
norm(r)

Gamma(:,1)=r;
for j=2:m
    Gamma(:,j)=multA(Gamma(:,j-1));
end
[Q,R]=qr(Gamma,0);
clear Gamma;
for j=1:m
    AQ(:,j)=multA(Q(:,j));
end
z=AQ\r;
y=Q*z;
x=x+y;
r=b-multA(x);
norm(r)
