% Jerry Zhu
% generate random points on unit sphere
X=randn(2,20);for i=1:20; X(:,i)=X(:,i)/norm(X(:,i));end

% plot X
Z=X; figure; hold on; plot(Z(1,:), Z(2,:),'.'); plot(Z(1,1), Z(2,1),'r*'); plot(Z(1,2), Z(2,2),'g*'); axis square; axis([-1 1 -1 1]); grid

% generate a random matrix
A=rand(2,2)

% plot AX
Z=A*X; figure; hold on; plot(Z(1,:), Z(2,:),'.'); plot(Z(1,1), Z(2,1),'r*'); plot(Z(1,2), Z(2,2),'g*'); axis square; axis([-1 1 -1 1]); grid

% now let's separate out the three steps of SVD
[U, S, V]=svd(A)
Z=V'*X; figure; hold on; plot(Z(1,:), Z(2,:),'.'); plot(Z(1,1), Z(2,1),'r*'); plot(Z(1,2), Z(2,2),'g*'); axis square; axis([-1 1 -1 1]); grid 
Z=S*V'*X; figure; hold on; plot(Z(1,:), Z(2,:),'.'); plot(Z(1,1), Z(2,1),'r*'); plot(Z(1,2), Z(2,2),'g*'); axis square; axis([-1 1 -1 1]); grid
Z=U*S*V'*X; figure; hold on; plot(Z(1,:), Z(2,:),'.'); plot(Z(1,1), Z(2,1),'r*'); plot(Z(1,2), Z(2,2),'g*'); axis square; axis([-1 1 -1 1]); grid


