math - Calculating varied summation formula? -
i'm trying pragmatically emulate calculator's summation function without use of loops, reason why become expensive once function gets bloated. far, know of formula n(n+1)/2, works if function looks like:
from x = 1 100, Σ (x), result = 5050.
without loop, there way implement function where:
from x = 1 100, Σ (x^2+x)?
edit: note formula must account possible function bodies.
thanks answers
the formula Σ (x^2+x) equal Σ (x) + Σ (x^2). know how calculate Σ (x).
as Σ (x^2), known square pyramidal number. can see longer explanation here, formula is:
n3/3 + n2/2 + n/6
together, that's
n3/3 + n2/2 + n/6 + n(n+1)/2
or
(n3+2n)/3 + n2
Comments
Post a Comment