function ShowSVD2()
% Shows the SVD connection to the 2x2 matrix-vector product y = Ax where
% A is 2x2 and x is a unit vector in the 2-norm
for eg=1:10
% Generate a nice 2x2 and compute its SVD...
A = randn(2,2);
A = A/norm(A);
[U,S,V] = svd(A);
% Display the unit circle and the right singular vectors V(:,1) and
% V(:,2)...
subplot(1,2,1)
theta = linspace(0,2*pi,200);
c = cos(theta);
s = sin(theta);
fill(c,s,'y','linewidth',2)
hold on
plot([-1.2 1.2],[0 0],':k',[0 0],[-1.2,1.2],':k')
plot([0;V(1,1)],[0;V(2,1)],'r','linewidth',3)
plot(V(1,1),V(2,1),'.r','Markersize',25)
plot([0;V(1,2)],[0;V(2,2)],'k','linewidth',3)
plot(V(1,2),V(2,2),'.k','Markersize',25)
text(-1.3,-1.2,'V(:,1) ------','Color','r','fontsize',20)
text(-1.3,-1.6,'V(:,2) ------','Color','k','fontsize',20)
hold off
axis equal off
% Display the range-space ellipse and the vectors
% AV(:,1) = S(1,1)U(:,1) and AV(:,2)= S(2,2)U(:,2).
subplot(1,2,2)
theta = linspace(0,2*pi,200);
Z = A*[cos(theta);sin(theta)];
fill(Z(1,:),Z(2,:),'y','linewidth',2)
sig1 = S(1,1);
sig2 = S(2,2);
hold on
plot([-1.2 1.2],[0 0],':k',[0 0],[-1.2,1.2],':k')
plot([0;sig1*U(1,1)],[0;sig1*U(2,1)],'r','linewidth',3)
plot(sig1*U(1,1),sig1*U(2,1),'.r','Markersize',25)
plot([0;sig2*U(1,2)],[0;sig2*U(2,2)],'k','linewidth',3)
plot(sig2*U(1,2),sig2*U(2,2),'.k','Markersize',25)
text(-1.4,-1.2,'sig1*U(:,1) ------','Color','r','fontsize',20)
text(-1.4,-1.6,'sig2*U(:,2) ------','Color','k','fontsize',20)
hold off
axis equal off
shg
pause(2)
end