Sei sulla pagina 1di 6

Advance Engineering Mathematics assignment

Stability analysis of linear systems

1. If b=[1 3]’ and b=[1.1 3]’ is observed, find estimates for x.

A = [1.03 0.97; 2.99 3.01];


b1=[1 3]';
b2=[1.1 3]';
x1=A\b1; % x1=inv(A)*b1;
x2=A\b2;

x1 =[0.5000;0.5000]
x2 =[2.0050;-0.9950]

2. Discuss the results obtained above in view of the singular values of A.

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.

Principle Component Analysis


1. Find and subtract the mean from each channel (8 channel data). Plot the resulting zero mean
channels.

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.

S=(1/7)*(K*K'); %Covariance matrix


[V,D] = eig(S); %Eigen values and eigen vectors of Covariance matrix
u1=V(:,9994); %First principle component
u2=V(:,9993); %Second principle component
y1=u1'*K;
y2=u2'*K;
plot(u1)
title('First principle component')
plot(u2)
title('Second principle component')
Image Compression using SVD
1. Select an image for this purpose and find the singular value decomposition of the selected image.

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')

Potrebbero piacerti anche