-
Notifications
You must be signed in to change notification settings - Fork 0
/
variance_covariance_test.m
60 lines (50 loc) · 978 Bytes
/
variance_covariance_test.m
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
% Variance, covariance and standartion didviation calculate
% X - vec of x meas
% Y - vec of Y meas
% Z - vec of Z meas
%% way 1
% measurment
clear all;
clc;
N=5;
% X=randi([1,4],1,N);
% Y=randi([4,8],1,N);
% Z=randi([3,9],1,N);
X= [90 90 60 30 30];
Y =[80 60 50 40 20];
Z= [40 80 70 70 90];
% averege of measurment
X_av=sum(X)/N;
Y_av=sum(Y)/N;
Z_av=sum(Z)/N;
% deviation
X_dev=-X+X_av;
Y_dev=-Y+Y_av;
Z_dev=-Z+Z_av;
% squared deviation
Xsq_dev=X_dev.^2;
Ysq_dev=Y_dev.^2;
Zsq_dev=Z_dev.^2;
% variance
X_vari=sum(Xsq_dev)/N;
Y_vari=sum(Ysq_dev)/N;
Z_vari=sum(Zsq_dev)/N;
% covariance
XY_cov=sum(X_dev.*Y_dev)/N;
XZ_cov=sum(X_dev.*Z_dev)/N;
YZ_cov=sum(Y_dev.*Z_dev)/N;
% standart deviation
X_sd=sqrt(X_vari);
Y_sd=sqrt(Y_vari);
Z_sd=sqrt(Z_vari);
M_cov=[X_vari XY_cov XZ_cov;
XY_cov Y_vari YZ_cov;
XZ_cov YZ_cov Z_vari];
display(M_cov);
% way 2;
% avr = M-1*M/N
% COV = avt'*avr/N;
M= [X' Y' Z'];
avr=M-ones(N)*M./N;
M2_cov=avr'*avr./N;
display(M2_cov);