# vpasum

Numerical summation using variable precision

## Syntax

``s = vpasum(f,a,b)``
``s = vpasum(f,x,a,b)``

## Description

example

````s = vpasum(f,a,b)` numerically approximates the sum of a series defined by `f` from `a` to `b`. The default summation variable `x` in `f` is determined by `symvar`. The summation bounds `a` and `b` must be real.`vpasum(f,[a,b])` is equal to `vpasum(f,a,b)`.```

example

````s = vpasum(f,x,a,b)` performs numerical summation using the summation variable `x`.```

## Examples

collapse all

Numerically sum the symbolic expression $\frac{1}{{1.2}^{x}}$ from 1 to 1,000.

```syms x; s = vpasum(1/1.2^x,1,1000)```
`s = $5.0$`

Find the summation of the symbolic function $y\left(x\right)={x}^{2}$ from $a$ to $b$. Since the limits of summation must be real values, assume that the bounds $a$ and $b$ are real.

```syms y(x) syms a b real y(x) = x^2; s = vpasum(y,a,b)```
```s =  ${\sum }_{x=a}^{b}{x}^{2}$```

Compare the computation time to evaluate symbolic and numerical summations.

Find the symbolic summation of the series $\sum _{\mathit{k}=1}^{\infty }{\left(-1\right)}^{\mathit{k}}\frac{\mathrm{log}\left(\mathit{k}\right)}{{\mathit{k}}^{3}}$ using `symsum`. Use `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)```
```y =  ${\sum }_{k=1}^{\infty }\frac{{\left(-1\right)}^{k} \mathrm{log}\left(k\right)}{{k}^{3}}$```
`yVpa = vpa(y)`
`yVpa = $0.059705906160195358363429266287926$`
`toc`
```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)```
`y = $0.059705906160195358363429266287926$`
`toc`
```Elapsed time is 0.164563 seconds. ```

## Input Arguments

collapse all

Expression or function to sum, specified as a symbolic number, variable, function, expression, vector, matrix, or multidimensional array.

Limits of summation, specified as two comma-separated numbers, symbolic numbers, symbolic variables, symbolic functions, or symbolic expressions. Specifying the summation range from `a` to `b` can also be done using a vector with two elements. The limits of summation must be real.

Summation variable, specified as a symbolic variable. If `x` is not specified, the integration variable is determined by `symvar(f)`.

## Algorithms

Depending on whether the series is alternating or monotone, `vpasum` 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

`$\sum _{i=a}^{b}f\left(i\right)=\frac{f\left(a\right)+f\left(b\right)}{2}+\underset{a}{\overset{b}{\int }}f\left(x\right)\text{\hspace{0.17em}}dx+\left(\sum _{m=1}^{⌊p/2⌋}\frac{{B}_{2m}}{\left(2m\right)!}\left(f{\left(b\right)}^{2m-1}-f{\left(a\right)}^{2m-1}\right)\right)+{R}_{p},$`

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.

## Support

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos