Definite and indefinite summation
sum function in MATLAB®, see
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.
i = a .. b) sum(
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
integers of type
DOM_INT, the call
_plus(f $ i
= a..b) gives the desired result, while
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
i. This is an expression
= g(i + 1) - g(i).
It is implicitly assumed that
i runs through
sum(f, i = a..b) computes the definite sum
i running from
b are numbers,
then they must be integers.
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
i extending over all roots of the polynomial
f is a rational function of
a closed form of the sum will be found.
See Example 2.
The system returns a symbolic call of
it cannot compute a closed form representation of the sum.
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)
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))
sum can compute finite sums if indefinite
sum(1/(i^2 + i), i = 1..100)
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
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
necessary to expand the binomials:
Finite sums with more than 1000 terms are not expanded:
sum(binomial(n, i), i = 0..1000)
However, if one of the boundaries is symbolic, then
_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)
The following infinite sum cannot be computed symbolically:
sum(ln(i)/i^5, i = 1..infinity)
We obtain a floating-point approximation via
numeric::sum(ln(i)/i^5, i = 1..infinity)
expression depending on
The boundaries: arithmetical expressions
An indeterminate of
sum implements Abramov's algorithm
for rational expressions, Gosper's algorithm for hypergeometric expressions,
and Zeilberger's algorithm for the definite summation of holonomic