How to vectorize this type of function?
古いコメントを表示
I have a function of the form:
f(a) = sum((-1)^n/factorial(a-n))
where the summation limits are n = 0 to a. If a is a scalar then I can just substitute 0:a for n in the expression. But if a is a vector, then the limits on the sum are different for every element of a. One way to compute it would be:
for i = 1:numel(a)
n = 0:a(i);
f(i) = sum((-1).^n./factorial(a(i)-n));
end
However, I would like to avoid using a for loop. I am wondering if anyone has any ideas for how to vectorize this?
Matt J provided a great solution to a simpler problem HERE. Is there any way to do something similar?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!