MATLAB: Sum function

functionMATLABseriessum

Hello Experts,
Consider I have to sum from i=1 to 2^(n-1) (n is given) values of some function f(i).
How can I do it like series in math sum from i=1 to 2^(n-1) of f(i)…
Thanks a lot in advance.

Best Answer

n=given;
i=1:2^(n-1); %gives you array of integers from 1,2,...2^(n-1)
% let's say your function is f=2i;
f=2*i;
yoursum=sum(f);