MATLAB: Function handle of a sum

function handlesum

How can I define a function that involves a summation?
for example, a function f = @(x) e^(-n*x), where the function is a sum of terms over some range of n?
Thanks

Best Answer

Assuming g(n) has vectored input/output, just do
f=@(x) sum( exp( -g(1:n) .* x )); %sum over 1...n
with obvious modifications for different ranges of n.