How to vectorize this type of function?
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Multidimensional Arrays en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!