For loop for summation

2 ビュー (過去 30 日間)
Emma
Emma 2019 年 10 月 17 日
編集済み: Matt J 2019 年 10 月 18 日
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.

採用された回答

Matt J
Matt J 2019 年 10 月 18 日
編集済み: Matt J 2019 年 10 月 18 日
R= zeros(size(y));
N= -500:500;
for j=1:numel(N)
n=N(j);
R = R + f(n).*y.^(-n);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by