Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
x1 =[0.5000;0.5000]
x2 =[2.0050;-0.9950]
S = svds(A);
C=cond(A);
S =[4.4721;0.0447]
C =100.0000
As the smallest singular value is very small hence the condition number is large and matrix A is ill
conditioned. Hence matrix A yields very different results with slight perturbations.
load 'C:\Users\Eysha\Desktop\pcadata.mat';
M=(1/8)*(data(:,1)+data(:,2)+data(:,3)+data(:,4)+data(:,5)+data(:,6)+data(:,7
)+data(:,8)); %Mean
a=data(:,1)-M; %Subtracting mean from each channel
b=data(:,2)-M;
c=data(:,3)-M;
d=data(:,4)-M;
e=data(:,5)-M;
f=data(:,6)-M;
g=data(:,7)-M;
h=data(:,8)-M;
K=[a b c d e f g h]; %Zero mean channels
plot(K)
title('Zero mean channels')
2. Estimate the covariance matrix of the data and plot the first two principle components of the data.
RGB = imread('peppers.png');
I = rgb2gray(RGB); %Grayscale image
imshow(I)
title('Grayscale image')
[U,S,V] = svd(double(I)); %Singular value decomposition
2. Find low rank approximations of your image for k = 1, 2,4,8,20,32. In each case, find the mean square
error of the approximation.
S1=zeros(384,512);
k=input('Enter value for low Rank approximation K=');
for r=1:k
S1(:,r)=S(:,r); % I1=U(:,1:k)*S(1:k,1:k)*V(:,1:k)'
end
colormap(gray)
I1=U*S1*V'; %Approximated image
imagesc(I1)
title(['Rank ',num2str(k),' approximation'])
error=norm(single(I)-I1) %error
error in k rank approximation:
error1 =1.0696e+04
error2 =6.2841e+03
error4 =4.3060e+03
error8 =2.3156e+03
error20 =985.4435
error 32= 587.6897
3. Plot k against mean square error in approximation.
k1=[1 2 4 8 20 32];
error1=[1.0696e+04 6.2841e+03 4.3060e+03 2.3156e+03 985.4435 587.6897];
figure,plot(k1,error1)
xlabel('K');
ylabel('Mean Square error');
title('K vs mean square error in approximation')