% Tony Hyun Kim

% 18.06 PS#9, Problem 5



% Part (a)

A = flipud(double(imread('strang.jpg')));

subplot(221);

pcolor(A); shading interp; colormap('gray'); axis equal;

title('Original picture');



% Part (b)

[U,S,V] = svd(A);

subplot(222);

semilogy(diag(S),'o');

xlabel('Index of singular values');

ylabel('Singular values');



% Part (c)

S2 = S*diag([ones(1,50), zeros(1,size(S,2)-50)]);

subplot(223);

pcolor(U*S2*V'); shading interp; colormap('gray'); axis equal;

title('Largest 50 singular values');



% Part (c)

M = 10;

S2 = S*diag([ones(1,M), zeros(1,size(S,2)-M)]);

subplot(224);

pcolor(U*S2*V'); shading interp; colormap('gray'); axis equal;

titlestr = sprintf('Largest %d singular values',M);

title(titlestr);