TExcelTAD
Home › Calculus Essentials › Power Series

Power Series

A power series is a polynomial that never ends. Inside its interval of convergence it behaves like an ordinary function: you can evaluate it, differentiate it and integrate it term by term. That makes power series the way to turn functions like ln⁡\ln, arctan⁡\arctan and exe^x into plain arithmetic a computer can do.

Definition

∑n=0∞cn(x−a)n=c0+c1(x−a)+c2(x−a)2+…(n=0,1,2,…)\sum_{n=0}^{\infty} c_n (x - a)^n = c_0 + c_1(x - a) + c_2(x - a)^2 + \ldots \qquad (n = 0, 1, 2, \ldots)

aa is the centre and the cnc_n are the coefficients. For each value of xx this is an ordinary series that either converges or diverges.

Radius and interval of convergence

Every power series has a radius of convergence RR (possibly 0 or ∞\infty):

  • it converges (absolutely) when ∣x−a∣<R\lvert x - a \rvert < R,
  • it diverges when ∣x−a∣>R\lvert x - a \rvert > R,
  • at the two endpoints x=a±Rx = a \pm R anything can happen; check them separately.

The ratio test usually finds RR. For ∑xn/n\sum x^n/n: ∣an+1/an∣=∣x∣⋅n/(n+1)→∣x∣\lvert a_{n+1}/a_n \rvert = \lvert x \rvert \cdot n/(n + 1) \to \lvert x \rvert, so R=1R = 1. At x=1x = 1 it is the harmonic series (diverges), at x=−1x = -1 the alternating harmonic series (converges): the interval is [−1,1)[-1, 1).

Series Function Radius
∑xn\sum x^n 1/(1−x)1/(1 - x) 1
∑(−1)nx2n\sum (-1)^n x^{2n} 1/(1+x2)1/(1 + x^2) 1
∑(−1)n+1xn/n\sum (-1)^{n+1} x^n/n (n≥1n \ge 1) ln⁡(1+x)\ln(1 + x) 1
∑(−1)nx2n+1/(2n+1)\sum (-1)^n x^{2n+1}/(2n + 1) arctan⁡x\arctan x 1
∑xn/n!\sum x^n/n! exe^x ∞\infty

The first row is the geometric series with ratio xx. Watch what happens inside and outside the radius:

python · try it yourself
def partial(x, terms):
    return sum(x**n for n in range(terms))

for x in [0.5, 0.9, 1.5]:
    sums = [round(partial(x, t), 4) for t in (5, 20, 80)]
    target = 1 / (1 - x)
    print(f"x={x}: partial sums {sums}   1/(1-x) = {target:.4f}")
x=0.5: partial sums [1.9375, 2.0, 2.0]   1/(1-x) = 2.0000
x=0.9: partial sums [4.0951, 8.7842, 9.9978]   1/(1-x) = 10.0000
x=1.5: partial sums [13.1875, 6648.5135, 244529196111407.28]   1/(1-x) = -2.0000

At x=0.5x = 0.5 it converges quickly, at x=0.9x = 0.9 slowly (close to the edge), and at x=1.5x = 1.5 it explodes even though 1/(1−x)=−21/(1 - x) = -2 is a perfectly good number there. The function exists outside the radius; the series just stops representing it.

Calculus term by term

Inside the radius you can differentiate or integrate each term, and the radius stays the same. Starting from the geometric series:

11+t=1−t+t2−t3+…→integrate 0..xln⁡(1+x)=x−x22+x33−…11+t2=1−t2+t4−t6+…→integrate 0..xarctan⁡x=x−x33+x55−…11−x=∑xn→differentiate1(1−x)2=∑nxn−1\begin{aligned} \frac{1}{1 + t} &= 1 - t + t^2 - t^3 + \ldots && \xrightarrow{\text{integrate } 0..x} \ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \ldots \\ \frac{1}{1 + t^2} &= 1 - t^2 + t^4 - t^6 + \ldots && \xrightarrow{\text{integrate } 0..x} \arctan x = x - \frac{x^3}{3} + \frac{x^5}{5} - \ldots \\ \frac{1}{1 - x} &= \sum x^n && \xrightarrow{\text{differentiate}} \frac{1}{(1 - x)^2} = \sum n x^{n-1} \end{aligned}

Putting x=1x = 1 into the arctan series gives the Leibniz series π/4=1−1/3+1/5−…\pi/4 = 1 - 1/3 + 1/5 - \ldots. It converges painfully slowly because x=1x = 1 sits on the edge of the interval. Machin's formula π/4=4arctan⁡(1/5)−arctan⁡(1/239)\pi/4 = 4\arctan(1/5) - \arctan(1/239) evaluates the same series at small xx, where it converges fast. Formulas like it were used to compute π\pi to millions of digits.

python · try it yourself
import math

def arctan_series(x, terms):
    return sum((-1) ** n * x ** (2 * n + 1) / (2 * n + 1) for n in range(terms))

for terms in [10, 1000]:
    leibniz = 4 * arctan_series(1, terms)
    print(f"Leibniz, {terms:4d} terms: {leibniz:.12f}  error {abs(leibniz - math.pi):.1e}")

for terms in [5, 10]:
    machin = 4 * (4 * arctan_series(1 / 5, terms) - arctan_series(1 / 239, terms))
    print(f"Machin,  {terms:4d} terms: {machin:.12f}  error {abs(machin - math.pi):.1e}")
Leibniz,   10 terms: 3.041839618929  error 1.0e-01
Leibniz, 1000 terms: 3.140592653840  error 1.0e-03
Machin,     5 terms: 3.141592682404  error 2.9e-08
Machin,    10 terms: 3.141592653590  error 1.3e-15

In software: evaluating polynomials with Horner's method

A truncated power series is a polynomial, and the standard way to evaluate one is Horner's method: rewrite c0+c1x+c2x2+c3x3c_0 + c_1x + c_2x^2 + c_3x^3 as c0+x(c1+x(c2+x⋅c3))c_0 + x(c_1 + x(c_2 + x \cdot c_3)). It needs only nn multiplications and nn additions, no powers, and is more accurate in floating point. Math libraries, shader code and fixed-point DSP code all evaluate their approximations this way.

python · try it yourself
import math

def horner(coeffs, x):             # coeffs lowest power first
    result = 0.0
    for c in reversed(coeffs):
        result = result * x + c
    return result

# first 12 terms of the series for e^x: c_n = 1/n!
coeffs = [1 / math.factorial(n) for n in range(12)]
for x in [0.5, 1.0, 2.0]:
    print(f"x={x}: Horner {horner(coeffs, x):.10f}   math.exp {math.exp(x):.10f}")
x=0.5: Horner 1.6487212707   math.exp 1.6487212707
x=1.0: Horner 2.7182818262   math.exp 2.7182818285
x=2.0: Horner 7.3890460157   math.exp 7.3890560989

Twelve terms agree with math.exp to all ten digits at x=0.5x = 0.5, but the error grows with xx (about 10−510^{-5} at x=2x = 2). Real libraries therefore first shrink xx into a small range, as the next lesson shows.

Generating functions in combinatorics are another use: an algorithm's counting problem becomes the coefficients of a power series, and algebra on the series (like the geometric-series trick) solves it.

Exercises

Exercise 1: Find the radius

Find the radius of convergence of ∑xn/3n\sum x^n / 3^n and its sum inside that radius.

Answer

R=3R = 3; the sum is 3/(3−x)3/(3 - x).

Solution
it is geometric with ratio x/3: converges for ∣x/3∣<1, i.e. ∣x∣<3sum=1/(1−x/3)=3/(3−x)\begin{aligned} &\text{it is geometric with ratio } x/3\text{: converges for } \lvert x/3 \rvert < 1, \text{ i.e. } \lvert x \rvert < 3 \\ &\text{sum} = 1/(1 - x/3) = 3/(3 - x) \end{aligned}

Exercise 2: Infinite radius

Use the ratio test to show that ∑xn/n!\sum x^n/n! converges for every xx.

Answer

R=∞R = \infty.

Solution
∣an+1an∣=∣x∣n+1(n+1)!⋅n!∣x∣n=∣x∣n+1→0<1for every x\left\lvert \frac{a_{n+1}}{a_n} \right\rvert = \frac{\lvert x \rvert^{n+1}}{(n + 1)!} \cdot \frac{n!}{\lvert x \rvert^n} = \frac{\lvert x \rvert}{n + 1} \to 0 < 1 \quad \text{for every } x

Exercise 3: Build a new series

Starting from 1/(1−x)=∑xn1/(1 - x) = \sum x^n, find a power series for 1/(1−x)21/(1 - x)^2 and use it to compute ∑n/2n\sum n/2^n.

Answer

1/(1−x)2=∑n=1∞nxn−11/(1 - x)^2 = \sum_{n=1}^{\infty} n x^{n-1}; ∑n/2n=2\sum n/2^n = 2.

Solution
differentiate:1/(1−x)2=1+2x+3x2+…=∑nxn−1multiply by x:x/(1−x)2=∑nxnx=1/2:(1/2)/(1/4)=2\begin{aligned} \text{differentiate:}\quad & 1/(1 - x)^2 = 1 + 2x + 3x^2 + \ldots = \textstyle\sum n x^{n-1} \\ \text{multiply by } x\text{:}\quad & x/(1 - x)^2 = \textstyle\sum n x^n \\ x = 1/2\text{:}\quad & (1/2)/(1/4) = 2 \end{aligned}

Exercise 4: ln⁡2\ln 2 two ways

The series for ln⁡(1+x)\ln(1 + x) at x=1x = 1 converges slowly. Since ln⁡2=−ln⁡(1−1/2)\ln 2 = -\ln(1 - 1/2) and −ln⁡(1−x)=x+x2/2+x3/3+…-\ln(1 - x) = x + x^2/2 + x^3/3 + \ldots, compare 20 terms of each.

Answer

ln⁡(1+x)\ln(1 + x) at x=1x = 1: error about 0.0240.024; −ln⁡(1−x)-\ln(1 - x) at x=1/2x = 1/2: error about 4.4×10−84.4 \times 10^{-8}.

Solution
python · try it yourself
import math

slow = sum((-1) ** (n + 1) / n for n in range(1, 21))
fast = sum(0.5**n / n for n in range(1, 21))
print(f"slow: {slow:.10f} error {abs(slow - math.log(2)):.1e}")
print(f"fast: {fast:.10f} error {abs(fast - math.log(2)):.1e}")
slow: 0.6687714032 error 2.4e-02
fast: 0.6931471371 error 4.4e-08

Evaluating a series well inside its radius is far more efficient than at the edge.

Test yourself

What is the radius of convergence of ∑(2x)n\sum (2x)^n?

  1. 2
  2. 1
  3. 1/21/2
  4. ∞\infty

Integrating the series for 1/(1+x2)1/(1 + x^2) term by term gives the series of which function?

  1. ln⁡(1+x2)\ln(1 + x^2)
  2. arctan⁡x\arctan x
  3. exe^x
  4. 1/(1+x)1/(1 + x)

Why is Horner's method preferred for evaluating polynomials?

  1. It uses fewer multiplications and avoids computing powers
  2. It is exact in floating point
  3. It works only for even polynomials
  4. It finds the roots