MATLAB: Managing two variables in sum function

loopMATLABsum

Hi, I want to manage two variables in a sum function in a way that sum(i*cos(ik)); which i=1:N , k=1:M but I want only want the SUM with respect to i and create a vector which has M values in other way i should be sumed but k only takes a value each time. what can I do? If I should use loops how can I do that? Thanks in advance

Best Answer

N=10;
M=20;
ii=1:N
for k=1:M
som(k)=sum(ii.*cos(ii*k));
end