numeric::sum -- numerical
approximation of sums (the float attribute of sum)
Introductionnumeric::sum(f[i], i=a..b) computes a
numerical approximation of sum(f[i],i=a..b).
numeric::sum(f(x), x = RootOf(p(X), X))
computes a numerical approximation of sum(f(x), x=RootOf(p(X),
X)).
Call(s)numeric::sum(f[i], i = a..b))
float(hold(sum)(f[i], i = a..b))
float(freeze(sum)(f[i], i = a..b))
numeric::sum(f(x), x = RootOf(p(X), X)))
float(hold(sum)(f(x), x = RootOf(p(X), X)))
float(freeze(sum)(f(x), x = RootOf(p(X), X)))
Parametersf[i] |
- | an arithmetical expression in i |
i |
- | the summation index: an identifier or an indexed identifier |
a, b |
- | integers or +/-infinity satisfying
a<=b |
f(x) |
- | an arithmetical expression in x |
x |
- | the summation variable: an identifier or an indexed identifier |
p(X) |
- | a univariate polynomial in X |
X |
- | the indeterminate of p: an identifier or an indexed identifier |
Returnsa floating point number.
Related
Functions_plus, int, numeric::quadrature, sum
Detailsnumeric::sum(..) is equivalent to calling the
float attribute of sum via
float(hold(sum)(..)) or float(freeze(sum)(..)).exp(PI), sqrt(2) etc. are accepted and
converted to floating point numbers.For infinite sums, the expression f[i] with integer i must have an extension f(x) to all real x in the interval [a,b], i.e., f(i)=f[i]. Internally, the integral int(f(x),x=a..b) is computed numerically and used in the approximation process.
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, then cancellation can be avoided
summing the symbolic terms by _plus(f[i]$i=a..b). Cf.
example 3.
Convergence may be slow for alternating sums containing expressions such as (-1)^i. Such sums are also often subject to cancellation problems!
numeric::sum(f(x), x = 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!
Example
1We 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))
2.718281829, 2.718281829, 2.718281829
MuPAD's symbolic summation does not find a simple representation of the following sum:
>> sum(1/i!/(i+1)!, i = 0..infinity)
/ 1 \
sum| -------------------, i = 0..infinity |
\ fact(i) fact(i + 1) /
The following float evaluation calls
numeric::sum:
>> float(%)
1.590636855
The exact value of the following sum is PI*coth(PI):
>> numeric::sum(1/(1+i^2), i = -infinity..infinity) = float(PI*coth(PI))
3.153348095 = 3.153348095
Example
2The following sum cannot be evaluated numerically
because of the symbolic parameter x:
>> numeric::sum(1/(x+i^2), i = -infinity..infinity)
Error: first argument may only contain i as symbolic parameter\
[numeric::sum]
Example
3We demonstrate numerical cancellation when summing the Taylor series for exp(-20):
>> exp(-20.0) <> numeric::sum((-20)^i/i!, i = 0..100)
0.000000002061153622 <> 0.000000002068277833
Also the infinite sum suffers from cancellation:
>> exp(-20.0) <> numeric::sum((-20)^i/i!, i = 0..infinity)
0.000000002061153622 <> 0.000000002068334676
Cancellation can be avoided using a finite sum with exact terms:
>> exp(-20.0) = float(_plus((-20)^i/i! $ i = 0..100))
0.000000002061153622 = 0.000000002061153622
Example
4The 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 = RootOf(X^10 - X - PI, X))
9.681693381
Backgroundnumeric::sum makes use of the Euler-MacLaurin formula
sum(f(k), k=a..b) = (f(a)+f(b))/2 + int(f(k),k=a..b)
+ sum(B[2*m]/(2*m)!* ((f^(2*m-1))(b)-(f^(2*m-1))(a)], m=1..M)
+ ...
involving the Bernoulli numbers bernoulli(2*m).funcattr(sum, "float")-infinity are now
accepted.RootOf expressions was
introduced.