필터 지우기
필터 지우기

Sigma notation - two variables. 'for' loop or symsum?

조회 수: 2 (최근 30일)
Nate
Nate 2014년 10월 20일
댓글: Roger Stafford 2014년 10월 22일
Hello
I am trying to compute a sigma summation of a simple single column vector x, where:
N = length(x)
k = 0:N/4
i = 1:N-k
I need to solve for Axx(k):
I have tried to solve this using 'for' loops and symsum function, without success. Help is hugely appreciated, thanks.

채택된 답변

Star Strider
Star Strider 2014년 10월 20일
This runs:
N = length(x);
for k = 0:N/4
Axx(k+1) = 0;
for i = 1:N-k
Axx(k+1) = Axx(k+1) + x(i)*x(i+k);
end
end
I’ll let you determine if it gives the answers you expect.
  댓글 수: 2
Nate
Nate 2014년 10월 22일
편집: Nate 2014년 10월 22일
Yes - it works perfectly, thanks.
Also - this seems to work as well:
N = length(x);
for k = 0:(N/4);
Axx(k+1) = sum((x(1:N-k,2)).*(x(1+k:N,2)));
end
Star Strider
Star Strider 2014년 10월 22일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Roger Stafford
Roger Stafford 2014년 10월 21일
Axx = x.'*hankel(x,zeros(1,N/4+1));
  댓글 수: 2
Nate
Nate 2014년 10월 22일
Thanks for this. I get an error when used with my 'x' vector.
Error using zeros Size inputs must be integers.
I found something that seems to work (see my comment below).
Thanks
Roger Stafford
Roger Stafford 2014년 10월 22일
That's probably because your value N is not a multiple of 4. Do this:
round(N/4)+1
instead.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by