find the variance of autocorrelation function

4 visualizaciones (últimos 30 días)
Chithralekha
Chithralekha el 17 de Ag. de 2013
Respondida: Jaynik el 25 de Jul. de 2024
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

Respuestas (1)

Jaynik
Jaynik el 25 de Jul. de 2024
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!

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by