find the variance of autocorrelation function

4 次查看(过去 30 天)
i want to find the sum of the below.but i am getting an error.please help me. i write the program in two ways.both are same.but both getting different answer
for i=1:20 s(i)=(2*(acf(i+1)^2)); s1=sum(s(i)); end
AND for k=1:20 s=0; for j=1:k s=s+2*acf(j+1)^2; end end
gives different answer.what is the error in this programs? both are same

回答(1 个)

Jaynik
Jaynik 2024-7-25
Hi Chithralekha,
The two pieces of code are not equivalent, and that is why they are producing different results. In first piece of code, the value of s(i) is being calculated for each i from 1 to 20, and then summed up the current value of s(i) in each iteration. This means s1 will only hold the value of the last element s(20) because it is being overwritten in each iteration.
In the second piece of code, s is initialized to 0 at each iteration of k, then sum is calculated for the value of 2 * acf(j+1)^2 from j=1 to j=k. The final value of s will be the sum of all these values up to k=20.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by