Numerical approximation of sums (the Float attribute of Sum )

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.


numeric::sum(f(x), x = a .. b)
numeric::sum(f(x), x in {x1, x2, …})
numeric::sum(f(x), x = {x1, x2, …})
numeric::sum(f(x), x in RootOf(p(X), X))
numeric::sum(f(x), x = RootOf(p(X), X))
float(hold(sum)(f(x), x = a .. b))
float(hold(sum)(f(x), x in {x1, x2, …}))
float(hold(sum)(f(x), x = {x1, x2, …}))
float(hold(sum)(f(x), x in RootOf(p(X), X)))
float(hold(sum)(f(x), x = RootOf(p(X), X)))
float(freeze(sum)(f(x), x = a .. b))
float(freeze(sum)(f(x), x in {x1, x2, …}))
float(freeze(sum)(f(x), x = {x1, x2, …}))
float(freeze(sum)(f(x), x in RootOf(p(X), X)))
float(freeze(sum)(f(x), x = RootOf(p(X), X)))


numeric::sum(f(i), i=a..b) computes a numerical approximation of .

numeric::sum(f(x), x ∈ {x1, x2, …}) computes a numerical approximation of .

numeric::sum(f(x), x in RootOf(p(X), X)) computes a numerical approximation of .

The call numeric::sum(…) is equivalent to calling the float attribute of sum via float ( hold( sum )(…)) or float ( freeze( sum )(…)).

If there are other symbolic parameters in f(x), apart from the summation variable x, a symbolic sum is returned. Numerical expressions such as , etc. are accepted and converted to floating-point numbers.

    Note:   For infinite sums, the expression f(i) with integer i must have an extension f(x) to all real x in the interval . Internally, the integral is computed numerically and used in the approximation process.

    Note:   For finite sums, numeric::sum just returns _plus ( float(f(i)$i=a..b)). Note that numerical cancellation may occur! If f(i) does not contain floating-point numbers, cancellation can be avoided summing the symbolic terms by _plus(f(i)$i=a..b) instead. Cf. Example 3.

Convergence is fast, if f(x) decays rapidly for x -> infinity or | x | -> infinity, respectively

    Note:   Convergence may be slow for alternating sums containing expressions such as (- 1)i. Such sums are also often subject to cancellation problems!

The call numeric::sum(f(x), x = {x1, x2, …}) computes numerical approximations of x1, x2 etc., substitutes these values into f(x) and adds up the results. This process may be subject to cancellation problems!

The calls numeric::sum(f(x), x ∈ {x1, x2, …}) and numeric::sum(f(x), x = {x1, x2, …}) are equivalent.

The call numeric::sum(f(x), x in RootOf(p(X), X)) computes numerical approximations of all roots of p, substitutes these values into f(x) and adds up the results. Cf. Example 4. This process may be subject to cancellation problems!

The calls numeric::sum(f(x), x in RootOf(p(X), X)) and numeric::sum(f(x), x = RootOf(p(X), X)) are equivalent.

Environment Interactions

The function is sensitive to the environment variable DIGITS, which determines the numerical working precision.


Example 1

We demonstrate some equivalent calls for numerical summation:

numeric::sum(1/i!, i = 0..infinity),
float(hold(sum)(1/i!, i = 0..infinity)),
float(freeze(sum)(1/i!, i = 0..infinity))

The MuPAD® symbolic summation sum does not find a simple representation of the following sum:

sum(1/i!/(i^2+1)!, i = 0..infinity)

The following float evaluation calls numeric::sum:


The exact value of the following sum is π coth(π):

numeric::sum(1/(1+i^2), i = -infinity..infinity) =

Example 2

The following sum cannot be evaluated numerically because of the symbolic parameter x:

numeric::sum(1/(x+i^2), i = -infinity..infinity)

Example 3

We demonstrate numerical cancellation when summing the Taylor series for :

exp(-20.0) <> numeric::sum((-20)^i/i!, i = 0..100)

Also the infinite sum suffers from cancellation:

exp(-20.0) <> numeric::sum((-20)^i/i!, i = 0..infinity)

Cancellation can be avoided using a finite sum with exact terms:

exp(-20.0) = float(_plus((-20)^i/i! $ i = 0..100))

Example 4

The following call computes the numerical roots of the polynomial in the RootOf expression and sums over all the roots:

numeric::sum(exp(x)/x, x in RootOf(X^10 - X - PI, X))

Related Examples



An arithmetical expression in x

i, x

Summation variables: identifiers or indexed identifiers

a, b

Integers or ±infinity satisfying ab

x1, x2, …

Numerical expressions


A univariate polynomial expression in X


The indeterminate of p: an identifier or an indexed identifier

Return Values

Floating point number or a symbolic expression of type numeric::sum.


Depending on whether the series is alternating or monotone, numeric::sum tries a number of strategies to calculate its limit: Levin's u transformation, the Euler-MacLaurin formula or van Wijngaarden's trick.

The Euler-MacLaurin formula is

involving the Bernoulli numbers B2 m.

See Also

MuPAD Functions

Was this topic helpful?