Effacer les filtres
Effacer les filtres

Sum function?

2 vues (au cours des 30 derniers jours)
Steve
Steve le 15 Oct 2011
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.

Réponse acceptée

Naz
Naz le 15 Oct 2011
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);
  2 commentaires
Steve
Steve le 15 Oct 2011
Function f is transferred as anonymous one to my function.
What should I change?
Walter Roberson
Walter Roberson le 15 Oct 2011
n=given;
fsum = 0;
for i=1:2^(n-1)
fsum = fsum + f(i);
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by