This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Definite and indefinite summation

For the sum function in MATLAB®, see sum.

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


sum(f, i)
sum(f, i = a .. b)
sum(f, i = RootOf(p, x))


sum(f, i) computes a symbolic antidifference of f(i) with respect to i.

sum(f, i = a..b) tries to find a closed form representation of the sum .

sum serves for simplifying symbolic sums (the discrete analog of integration). It should not be used for simply adding a finite number of terms: if a and b are integers of type DOM_INT, the call _plus(f $ i = a..b) gives the desired result, while sum(f, i = a..b) may return unevaluated. expand may be used to sum such an unevaluated finite sum. See Example 3.

sum(f, i) computes the indefinite sum of f with respect to i. This is an expression g such that f(i) = g(i + 1) - g(i).

It is implicitly assumed that i runs through integers only.

sum(f, i = a..b) computes the definite sum with i running from a to b.

If a and b are numbers, then they must be integers.

If b - a is a nonnegative integer, then the explicit sum f(a) + f(a + 1) + … + f(b) is returned, provided that this sum has no more than 1000 terms.

sum(f, i = RootOf(p, x)) computes the sum with i extending over all roots of the polynomial p with respect to x.

If f is a rational function of i, a closed form of the sum will be found.

See Example 2.

The system returns a symbolic call of sum if it cannot compute a closed form representation of the sum.

Infinite symbolic sums without symbolic parameters can be evaluated numerically via float or numeric::sum. Cf. Example 4.


Example 1

We compute some indefinite sums:

sum(1/(i^2 - 1), i)

sum(1/i/(i + 2)^2, i)

sum(binomial(n + i, i), i)

We compute some definite sums. Note that are valid boundaries:

sum(1/(i^2 + 21*i), i = 1..infinity)

sum(1/i, i = a .. a + 3)


Example 2

We compute some sums over all roots of a polynomial:

sum(i^2, i = RootOf(x^3 + a*x^2 + b*x + c, x))

sum(1/(z + i), i = RootOf(x^4 - y*x + 1, x))

Example 3

sum can compute finite sums if indefinite summation succeeds:

sum(1/(i^2 + i), i = 1..100)

_plus yields the same result more quickly if the number of summands is small:

_plus(1/(i^2 + i) $ i = 1..100)

In such cases, sum is much more efficient than _plus if the number of summands is large:

sum(1/(i^2 + i), i = 1..10^30)

Finite sums for which no indefinite summation is possible are expanded if they have no more than 1000 terms:

sum(binomial(n, i), i = 0..4)

An application of expand is necessary to expand the binomials:


Finite sums with more than 1000 terms are not expanded:

sum(binomial(n, i), i = 0..1000)

You might use expand here to expand the sum and obtain a huge expression. If you really want to do that, we recommend using _plus directly.

However, if one of the boundaries is symbolic, then _plus cannot be used:

_plus(1/(i^2 + i) $ i = 1..n)

_plus(binomial(n, i) $ i = 0..n)

sum(1/(i^2 + i), i = 1..n), sum(binomial(n, i), i = 0..n)

Example 4

The following infinite sum cannot be computed symbolically:

sum(ln(i)/i^5, i = 1..infinity)

We obtain a floating-point approximation via float:


Alternatively, the function numeric::sum can be used directly. This is usually much faster than applying float, since it avoids the overhead of sum attempting to compute a symbolic representation:

numeric::sum(ln(i)/i^5, i = 1..infinity)

Related Examples



An arithmetical expression depending on i


The summation index: an identifier or indexed identifier

a, b

The boundaries: arithmetical expressions


A polynomial of type DOM_POLY or a polynomial expression


An indeterminate of p


The function sum implements Abramov's algorithm for rational expressions, Gosper's algorithm for hypergeometric expressions, and Zeilberger's algorithm for the definite summation of holonomic expressions.

See Also

MuPAD Functions

Was this topic helpful?