Professional Documents
Culture Documents
clear();
fprintf('Enter the no of sample\n');
n=input('Number of row=');
fprintf('Enter the number of varaible\n');
m=input('Number of column=');
fprintf('enter the data matrix');
a=input('[a]=')
%calculation of mean matrix
t=0;
for j=1:1:m
t=t+1;
sum(t)=0;
for i=1:1:n
sum(t)=sum(t)+a(i,j);
end
mean(t)=sum(t)/n;
end
%calculation of modified data
for j=1:1:m
for i=1:1:n
am(i,j)=a(i,j)-mean(j);
end
end
display('modified data is')
display(am)
%calculation of covariance matrix,eigenvalues of it and corresponding eigen
%vectors
covm=cov(a);
display(covm);
[eigenvector,eigenvalues]=eig(covm);
display(eigenvector);
display(eigenvalues);
%arranging the matrix of eigenvector in decreasing value of eigen valuek=
k=0;
for i=1:1:m
for j=1:1:m
if(i==j)
k=k+1;
d(k)=eigenvalues(i,j);
end
end
end
display(d);
dsorted=sort(d,'descend');
display(fev);
%calculation of new data
newdata=transpose(fev)*transpose(am);
display('final data is =')
display(newdata);
Execution of code
1. For three variable
Enter the no of sample,=Number of row=15
Enter the number of variable= Number of column=3
Enter the data matrix[a]= [68 98 19; 67 96 15; 67 80 27 ; 66 69 41 ; 66 74 29 ; 66 56 40 ; 66 82 103 ;
66 84 198 ; 65 100 11; 64 71 64 ; 63 51 40;63 85 62; 60 83 12;60 61 29; 59 77 18]
a=
68 98 19
67 96 15
67 80 27
66 69 41
66 74 29
66 56 40
66 82 103
66 84 198
65 100 11
64 71 64
63 51 40
63 85 62
60 83 12
60 61 29
59 77 18
modified data is:
[am] = 3.6000 20.2000 -28.2000
2.6000 18.2000 -32.2000
2.6000 2.2000 -20.2000
1.6000 -8.8000 -6.2000
1.6000 -3.8000 -18.2000
1.6000 -21.8000 -7.2000
1.6000 4.2000 55.8000
1.6000 6.2000 150.8000
0.6000 22.2000 -36.2000
-0.4000 -6.8000 16.8000
-1.4000 -26.8000 -7.2000
-1.4000 7.2000 14.8000
-4.4000 5.2000 -35.2000
-4.4000 -16.8000 -18.2000
-5.4000 -0.8000 -29.2000
covm = 1.0e+003 *
0.0080 0.0133 0.0283
0.0133 0.2133 -0.0159
0.0283 -0.0159 2.3430
eigenvector =
-0.9978 0.0653 0.0121
0.0652 0.9978 -0.0074
0.0125 0.0066 0.9999
eigenvalues = 1.0e+003 *
0.0067
0
0
0
0.2141
0
0
0
2.3435
d = 1.0e+003 (0.0067 0.2141 2.3435)
position = 3 2 1
cnt = 1
Feature vector, [fv]T = [ 0.0121 -0.0074 0.9999]
Final data is = -28.302, -32.2998, -20.1829, -6.1151, -18.1508, -7.019, 55.7827, 150.7585, -36.3530,
16.8437, -7.0183 14.7285, -35.2879, -18.1272, -29.2563
a = 68
67
67
66
66
66
66
66
65
64
63
63
60
60
59
63 98 75 19
62
66
64
64
66
50
42
62
55
65
41
59
62
59
96
80
69
74
56
82
84
100
71
51
85
83
61
77
68
64
64
63
78
76
66
78
74
63
78
66
61
52
15
27
41
29
40
103
198
11
64
40
62
12
29
18
Modified data is ,
am =
3.6000
2.6000
2.6000
1.6000
1.6000
1.6000
1.6000
1.6000
0.6000
-0.4000
-1.4000
-1.4000
-4.4000
-4.4000
-5.4000
covm = 1.0e+003 *
0.0080 0.0024
0.0024 0.0668
0.0133 -0.0325
0.0106 -0.0169
0.0283 -0.2949
eigenvector =
-0.9053 0.3971
0.3728 0.9010
0.0892 0.1315
0.1742 0.0331
0.0550 0.1101
eigenvalues = 1.0e+003 *
0.0019
0
0
0.0264
0
0
0
0
0
0
0
0
0.0133
-0.0325
0.2133
0.0355
-0.0159
0.0106
-0.0169
0.0355
0.0601
0.0471
0.0283
-0.2949
-0.0159
0.0471
2.3430
0.1360
-0.0569
-0.2374
0.9597
-0.0304
-0.0635
0.1731
-0.9583
-0.2171
0.0226
0.0118
-0.1264
-0.0050
0.0210
0.9917
0
0
0
0
0
0
0.0523 0
0
0.2285
0
0
2.3820
position =[ 5 4
cnt = 2
fev =
1]
0.0118 -0.0635
-0.1264 0.1731
-0.0050
0.9583
0.0210 -0.2171
0.9917 0.0226
Final data is =[Y1,Y2]=[ -28.4320 -32.4213 -21.0316 -6.8526 -18.7985 -7.7384 56.5887 151.5888
-36.2210 17.2703 - 7.9378 17.0595 -35.0770 -18.5939 -29.4033 ; -20.9076 -17.6712
-0.5059
10.0696 5.2237 19.8114 -6.0140 -4.9942 -23.6393 5.0715 27.8773 -11.6181 -4.9215 18.1508
4.0674]