%Script file for data homework on the SVD x=linspace(2,4); y=3*x+2; X=[x' y']; %Form the 100 x 2 data matrix [U,S,V]=svd(X); diag(S) %Display the singular values V %Display the basis vectors %Now mean subtract m1=mean(X,1); %The mean in R^2 m2=mean(X,2); %The mean in R^100 X1=X-repmat(m1,100,1); [U1,S1,V1]=svd(X1); diag(S1) V1 X2=X-repmat(m2,1,2); [U2,S2,V2]=svd(X2); diag(S2) V2 X3=X-repmat(m1,100,1)-repmat(m2,1,2)+mean(X(:)); [U3,S3,V3]=svd(X3); diag(S3) V3 plot(X(:,1),X(:,2),'k-',X1(:,1),X1(:,2),'r.'); hold on plot(X2(:,1),X2(:,2),'m.',X3(:,1),X3(:,2),'g.'); hold off