1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
//Caption: To compute the covariance of the given 2D data
//Problem 5
//page439
close;
clear;
clc;
X1 = [2,1]';
X2 = [3,2]';
X3 = [2,3]';
X4 = [1,2]';
X = [X1,X2,X3,X4];
disp(X,'X=');
[M,N] = size(X); //M=rows, N = columns
for i =1:N
m(i) = mean(X(:,i));
A(:,i) = X(:,i)-m(i);
end
m = m';
disp(m,'mean =');
K = A'*A;
K = K/(M-1);
disp(K,'The Covaraince matix is K =')
//Result
//X=
// 2. 3. 2. 1.
// 1. 2. 3. 2.
//mean =
// 1.5 2.5 2.5 1.5
//
//The Covaraince matix is K =
// 0.5 0.5 - 0.5 - 0.5
// 0.5 0.5 - 0.5 - 0.5
// - 0.5 - 0.5 0.5 0.5
// - 0.5 - 0.5 0.5 0.5
|