Effacer les filtres
Effacer les filtres

find the variance of autocorrelation function

3 vues (au cours des 30 derniers jours)
Chithralekha
Chithralekha le 17 Août 2013
Réponse apportée : Jaynik le 25 Juil 2024 à 5:40
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

Réponses (1)

Jaynik
Jaynik le 25 Juil 2024 à 5:40
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!

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by