% program ex_a2_2.m % program to demo principal component regression of the set of equations Xa=y % written by Babu Joseph, June 2001 % Assume that x and y are defined echo on; clc; x=[1 1;2 2 ; 3 3]; y=[1 2 3]'; % first do a singular value decomposition [u,s,v]=svd(x) % the principal components are displayed % the following are the singular values s % select number of singular values to retain for regression % k= input(' Enter no of singular values to retain'); % get approximation for x % find ti, and pi ut=u(:,1:k); vt=v(:,1:k); st=s(1:k,1:k); t=ut*st; p=vt; % the approximation for x using the retained singular values are: x=t*p' % the pcr regression solution is a=p*inv(t'*t)*t'*y