How to vectorize this type of function?
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Multidimensional Arrays dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!