Write a MATLAB program that sets up a 15 x 40 matrix with entries zero everywhere except for values 1 in the positions indicated in Figure 1. The upper-leftmost 1 is in the (2,2) position while the lower-rightmost 1 is in the (13,39) position. The picture was produced using the spy(A) command.
a) Call svd to compute the singular values of A and print the results. Plot these numbers using both plot and semilogy. What is the exact rank of A?
b) For each i from 1 to rank(A), construct the rank-i matrix B that is the best approximation to A in the 2-norm. Use the command pcolor(B) with colormap(gray) to create images of these various approximations.
10
15 0
5
10
15
20
25
30
35
40
Figure 1: Figure generated by the spy(A) command.