% the script VisualizeSVD_LE shows the effects of a 3X2 random % matrix acting on the unit circle and visualizes the SVD clf % unit vectors on the unit circle (in 2D) theta=linspace(0,2*pi,100);x=cos(theta); y=sin(theta); % random matrix A A=rand(3,2) % columns of B contains the coordinate (in 3D) of the vectors % obtained after the transformation operated by A B=A*[x;y]; [U,S,V]=svd(A); % scaling of the columns of U by means of singular values (be careful, s3=0) UU=U*S; % visualize vectors on the unit circle figure; plot(x,y,'.b'); ylim([-1.1,1.1]);axis equal; hold on; % visualize column vectors of V % (are an orthogonal basis in R2) disp('visualize vectors on the unit circle') disp('column vectors of V are an orthogonal basis in R2') title('column vectors of V, basis in R2',FontSize=9) quiver(zeros(1,2),zeros(1,2), V(1,:),V(2,:)); set(gcf, 'Position', [100, 100, 400, 300]); % modify the size of the figure axis equal; hold off % visualize vectors after the transformation by A. They form an ellipse in % R3. figure; plot3(B(1,:),B(2,:),B(3,:),'.r'); axis equal; hold on % The ellipse lies on the plane generated by the first two columns of U % (that are an orthogonal basis on such plane representing the range of A. % The length of the largest semiaxis is s1; the length of the minor % semiaxis is s2. quiver3(0,0,0,UU(1,1),UU(2,1),UU(3,1)) quiver3(0,0,0,UU(1,2),UU(2,2),UU(3,2)) quiver3(0,0,0,U(1,3),U(2,3),U(3,3),'g') axis equal; hold off disp('the ellipse is the transformation of the unit circle performed by A') disp('the ellipse lies on the plane spanned by the first two columns of U') disp('column of U = orthogonal basis on the (plane) range of A') disp('the length of major semiaxis is sigma(1), the length of minor semiaxis is sigma(2)') disp('the third column of U is the basis of the orthogonal complement of the range of A')