Numerical summation using variable precision
Numerically sum the symbolic expression from 1 to 1,000.
syms x; s = vpasum(1/1.2^x,1,1000)
Find the summation of the symbolic function from to . Since the limits of summation must be real values, assume that the bounds and are real.
syms y(x) syms a b real y(x) = x^2; s = vpasum(y,a,b)
Compare the computation time to evaluate symbolic and numerical summations.
Find the symbolic summation of the series using
vpa to numerically evaluate the symbolic summation using 32 significant digits. Measure the time required to declare the symbolic summation and evaluate its numerical value.
syms k tic y = symsum((-1)^k*log(k)/k^3,k,1,Inf)
yVpa = vpa(y)
Elapsed time is 1.612575 seconds.
To increase computation performance (shorten computation time), use
vpasum to evaluate the same numerical summation without evaluating the symbolic summation.
tic y = vpasum((-1)^k*log(k)/k^3,k,1,Inf)
Elapsed time is 0.164563 seconds.
f— Expression or function to sum
Expression or function to sum, specified as a symbolic number, variable, function, expression, vector, matrix, or multidimensional array.
a,b— Limits of summation
Limits of summation, specified as two comma-separated numbers, symbolic numbers,
symbolic variables, symbolic functions, or symbolic expressions. Specifying the
summation range from
b can also be done using
a vector with two elements. The limits of summation must be real.
x— Summation variable
Summation variable, specified as a symbolic variable. If
not specified, the integration variable is determined by
Depending on whether the series is alternating or monotone,
tries a number of strategies to calculate its limit: Levin's u-transformation, the
Euler–Maclaurin formula, or van Wijngaarden's trick.
For example, the Euler–Maclaurin formula is
where B2m represents the 2mth Bernoulli number and Rp is an error term which depends on a, b, p, and f.
 Olver, F. W. J., A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain, eds., Chapter 2.10 Sums and Sequences, NIST Digital Library of Mathematical Functions, Release 1.0.26 of 2020-03-15.