find the variance of autocorrelation function
3 次查看(过去 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
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!