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...nwith obvious modifications for different ranges of n. Related SolutionsMATLAB: How to calculate the integral of the complicated functions of function handles in a cell f{1} = @(x) x;f{2} = @(x) x.^2;g=@(x) f{1}(x)+f{2}(x)integral(@(x) g(x), -3,3) MATLAB: Help with coding (integral) Typo in line 18 - use sum_f instead of sum_ fa = 0; b = 1; n = 20; m = n/2; dx = (b-a)/n; x = a; sum_f = ((1/5*a)+1).*sqrt(1+exp(-2*a));eqn = @(x) ((1/5*x)+1).*sqrt(1+exp(-2*x));for i = 1:m-1 x = x + dx; sum_f = sum_f + 4*((1/5*x)+1).*sqrt(1+exp(-2*x)); x = x + dx; sum_f = sum_f + 2*((1/5*x)+1).*sqrt(1+exp(-2*x)); endx = x + dx; sum_f = sum_f + 4*((1/5*x)+1).*sqrt(1+exp(-2*x));sum_f = sum_f + b/((1/5*b)+1).*sqrt(1+exp(-2*b)); Related QuestionFunctions with different conditionsAnonymous function representation using integralL’hopital rule doesn’t work
Best Answer