
%
% Sets up the hello matrix A that is
% show in Trefethen and Bau, page 68.
%
A=zeros(15,40);
for i=2:9
     A(i,2)=1;
     A(i,3)=1;
     A(i,6)=1;
     A(i,7)=1;
end;
A(5:6,4:5)=[1 1;1 1];

for i=3:10
     A(i,10)=1;
     A(i,11)=1;
end;
A(3:4,12:15)=ones(2,4);
A(6:7,12:15)=ones(2,4);
A(9:10,12:15)=ones(2,4);

for i=4:11
     A(i,18)=1;
     A(i,19)=1;
end;
A(10:11,20:23)=ones(2,4);

for i=5:12
     A(i,26)=1;
     A(i,27)=1;
end;
A(11:12,28:31)=ones(2,4);
%
for i=6:13
     A(i,34)=1;
     A(i,35)=1;
     A(i,38)=1;
     A(i,39)=1;
end;
 A(6:7,36:37)=ones(2,2);
 A(12:13,36:37)=ones(2,2);
%
%

% Show the nonzero structure of A:
figure(1)
spy(A)

B = 0.2 + 0.6*A;  % shift values away from 0, 1
                  
[U,S,V] = svd(B);

figure(2)
showimage(B)

junk = input('Hit return for rank k approximations')

for k=1:11
    Bk = U(:,1:k) * S(1:k,1:k) * V(:,1:k)';
    showimage(Bk)
    disp(sprintf('k = %i', k))
    junk = input('Hit return to continue...');
end

