MATLAB Answers

Emma
0

For loop for summation

Asked by Emma
on 17 Oct 2019
Latest activity Edited by Matt J
on 18 Oct 2019 at 0:55
I need to create a for loop for a series summation. The sum is from n=-500 to 500. The summation is some function of n multiplied by y^-n. The problem that I am running into is that y is a matrix that needs to be indexed over. Currently, I have something along the lines of
R= zeros(size(y));
N= -500:500;
for m=1:numel(y)
R(m) = R(m) + f(N)*y(m)^(-N)
end
But am running into problems because N is not the same size as y.

  0 Comments

Sign in to comment.

1 Answer

Matt J
Answer by Matt J
on 18 Oct 2019 at 0:54
Edited by Matt J
on 18 Oct 2019 at 0:55
 Accepted Answer

R= zeros(size(y));
N= -500:500;
for j=1:numel(N)
n=N(j);
R = R + f(n).*y.^(-n);
end

  0 Comments

Sign in to comment.