Findings the parameters from the time series

2 views (last 30 days)
In the attached data file, there are two sheets, Sheet 1 and Sheet 2. Sheet 1 contains 4846 values of E or we can 4846 time series values. Sheet 2 contains the variables E, p(E), X, R1,R2, and R3.
Firstly I need to divide this 4846 values into different number of time series. As can be seen in Sheet 2, first time series has one row (or only the first value of E), second time series has 2 rows ( first and second value of E), third time series has 3 rows ( first, second and third value of E) and so on....i.e. each time a new E value is added. So at the end there will be 4846 different time series.
Basically I have to calculate R1, R2, and R3. Before that, p(E) and X is to be calculated. By clicking on each cell, the formula for calculating the variables will be visible. So basically, for each value of E, I will get R1,R2,and R3.Also, the first value of R1, R2 and R3 will be zero. You can start from the second time series.
I want to write the MATLAB code for the same by first dividing it into different time series and finally calculating R1,R2, and R3. This might be confusing. Ask any doubts for clarification.

Accepted Answer

Mathieu NOE
Mathieu NOE on 2 May 2024
hello
here you are
there is still a doubt in my mind for the third (last ) iteration for R3
according to your excel file the equation is
R3 = D7*C9*LN(D7) + D8*C8*LN(D8) + D9*C7*LN(D9) - ((D7*C9 + D8*C8 +D9*C7)*LN(D8*C9+D9*C8+D7*C7))
but I wonder why this logic in the last term LN(D8*C9+D9*C8+D7*C7)
shoudn't it be this ? : LN(D7*C9 + D8*C8 +D9*C7)
so R3 equation would be
R3 = D7*C9*LN(D7) + D8*C8*LN(D8) + D9*C7*LN(D9) - ((D7*C9 + D8*C8 +D9*C7)*LN(D7*C9 + D8*C8 +D9*C7))
in that case , this is what I have implemented :
data = readmatrix('Data.xlsx',"Sheet",1);
samples = numel(data);
for k=1:3 % replace "3" by "samples" to run until the end of data
ind = (1:k); % col "A"
datak = data(ind)'; % col "B"
dsum = sum(datak);
pE = datak./dsum; % col "C"
X = ind./ind(end); % col "D"
% R1 = C7*D7^(2) + C8*D8^(2) +C9*D9^(2) - (C7*D7+C8*D8 +C9*D9)^2
R1 = sum(pE.*(X.^2)) - sum(pE.*X).^2; % ok
% R2 = D7*C7*LN(D7) + D8*C8*LN(D8) + D9*C9*LN(D9) - ((D7*C7 + D8*C8 +D9*C9)*LN(D8*C8+D9*C9+D7*C7))
R2 = sum((pE.*X.*log(X))) - sum(pE.*X)*log(sum(pE.*X)); % ok
% R3 =D7*C9*LN(D7) + D8*C8*LN(D8) + D9*C7*LN(D9) - ((D7*C9 + D8*C8 +D9*C7)*LN(D8*C9+D9*C8+D7*C7))
pE_flip = pE(end:-1:1);
prod3 = pE_flip.*X; % (D7*C9 + D8*C8 +D9*C7)
R3 = sum(prod3.*log(X)) - sum(prod3)*log(sum(prod3));
out = [R1 R2 R3];
fprintf('%6.2e %6.2e %6.2e\n',out);
end

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!