How to calculate array by expression with sum, not using loops

I want to calc array (k=1..N) from expression arr(k)=1/N*(\sum_{i=1}^{N}{arr2(i)*cos((2*k-1)*pi*i/N)})
arr2 -- already calculated array
N -- positive integer( it can be very big, so I need solution with good performance)
It is very easy to do with loops, but how to do it without loops?

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 5월 7일
N = numel(arr);
k = 1:N;
arr = cos((2*k(:)-1)*k(:).'*pi/N)*arr2(:)/N;

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2014년 5월 7일

답변:

2014년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by