-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoments_E_theta.m
42 lines (30 loc) · 964 Bytes
/
moments_E_theta.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function moments_E_theta computes the mean of E and theta and the
% covariance matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% - theta: array of angle values
% - E: array of energy values
% Output
% ------
% - thetabar: mean of angle values
% - Ebar: mean of energy values
% - Theta: covariance matrix
% Author: Pablo Seleson
% ------
% Last Modified: February 1, 2022
% -------------
function [thetabar,Ebar,Theta] = moments_E_theta(theta,E)
% Compute number of data
N = length(theta);
% Compute average quantities
thetabar = sum(theta)/N;
Ebar = sum(E)/N;
% Compute covariance matrix
Theta = zeros(2,2);
Theta(1,1) = sum((theta - thetabar).^2)/N;
Theta(2,2) = sum((E - Ebar).^2)/N;
Theta(1,2) = sum((theta - thetabar).*(E - Ebar))/N;
Theta(2,1) = Theta(1,2);
end