---
title: Power series solutions
heading: When no formula exists, let the equation write the solution's Taylor series
eyebrow: A8 · Lesson 49 · Power series solutions
xp: 40
---

::: hook
Most linear equations with variable coefficients have no solution in familiar functions. Airy's equation, $y'' = xy$, describes an electron's wave near a tunneling barrier and light near the bright edge of a rainbow; Bessel's equation describes drumheads, waveguides and the current inside a thick wire. Their solutions are smooth, though, so each has a Taylor series. Put an unknown series into the equation, and matching powers of $x$ gives a rule that produces the coefficients one after another. The series is then the solution, to as many digits as you care to add terms for.
:::

::: play
- The curves are the partial sums of the series solution of $y'' = xy$ with $y(0) = 1$, $y'(0) = 0$, using the terms up to $x^{3N}$, against the exact solution computed numerically.
- Each extra term extends the range where the sum is right: the series converges for every $x$, but far out it needs many terms.
:::

```sim plot
view: graph
x: x = -4..4
y: y = -2..6
slider: N = 1..6 step 1 = 2
plot: 1 + x^3/6 + step(N - 2)*x^6/180 + step(N - 3)*x^9/12960 + step(N - 4)*x^12/1710720 + step(N - 5)*x^15/359251200 + step(N - 6)*x^18/1.099308672e11 | label: partial sum
readout: terms used = N + 1
```

::: predict
## Put $y = a_0 + a_1x + a_2x^2 + \cdots$ into $y' = y$ with $y(0) = 1$. What rule do the coefficients follow?

- [x] $a_{n+1} = a_n/(n + 1)$, so $a_n = 1/n!$
- [ ] $a_{n+1} = a_n$, so every $a_n = 1$
- [ ] $a_{n+1} = (n + 1)a_n$
- [ ] They can't be found without solving first

::: reveal
$a_{n+1} = a_n/(n + 1)$. Differentiating the series gives $y' = a_1 + 2a_2x + 3a_3x^2 + \cdots$, and matching the coefficient of $x^n$ on both sides gives $(n + 1)a_{n+1} = a_n$. Starting from $a_0 = 1$, $a_n = 1/n!$: the series for $e^x$, which the equation built without being told.
:::
:::

::: nameit
## The method

1. Write $y = \sum a_nx^n$, $y' = \sum na_nx^{n-1}$, $y'' = \sum n(n - 1)a_nx^{n-2}$.
2. Substitute, and **shift the indices** so every sum is written in powers $x^n$.
3. Set the total coefficient of each power to zero. That gives a **recurrence**: each $a$ in terms of earlier ones.
4. The initial conditions fix the first ones: $a_0 = y(0)$ and $a_1 = y'(0)$.

For Airy's equation $y'' = xy$: the left side is $\sum (n + 2)(n + 1)a_{n+2}x^n$ and the right is $\sum a_{n-1}x^n$, so $a_2 = 0$ and

$$a_{n+2} = \frac{a_{n-1}}{(n + 2)(n + 1)}$$

Each coefficient comes from the one three places back: $a_0$ feeds $a_3, a_6, \ldots$ and $a_1$ feeds $a_4, a_7, \ldots$, giving two independent solutions.

## Where it works, and how far

At an **ordinary point**, where the equation $y'' + p(x)y' + q(x)y = 0$ has $p$ and $q$ with Taylor series, the method gives two independent series solutions. Each converges at least out to the distance from the center to the nearest point where $p$ or $q$ blows up, **including complex points**. For $(1 + x^2)y'' + y = 0$, nothing goes wrong on the real line, yet the series about 0 only converges for $|x| < 1$, because $1 + x^2 = 0$ at $x = \pm j$.

At a **singular point**, like $x = 0$ for Bessel's equation, plain power series can fail; a modified series, $x^r\sum a_nx^n$, takes over (course A12).
:::

::: example
## Solve $y'' + y = 0$ by series, with $y(0) = a_0$ and $y'(0) = a_1$.

::: solution
1. **Substitute the series.**
   $$\sum[(n + 2)(n + 1)a_{n+2} + a_n]x^n = 0$$
2. **Recurrence.**
   $$a_{n+2} = -\frac{a_n}{(n + 2)(n + 1)}$$
3. **First coefficients.**
   $$\begin{aligned} a_2 &= -\frac{a_0}{2}, & a_4 &= \frac{a_0}{24} \\ a_3 &= -\frac{a_1}{6}, & a_5 &= \frac{a_1}{120} \end{aligned}$$
4. **Recognize the series.** The even terms are $a_0(1 - x^2/2! + x^4/4! - \cdots) = a_0\cos x$ and the odd ones $a_1\sin x$.
5. **Why it matters.** The series method recovers the familiar solution, which is the test that the method and the algebra are right before using them where no familiar solution exists.

**Answer:** $y = a_0\cos x + a_1\sin x$.
:::
:::

::: example
## Find $y(1)$ for Airy's equation $y'' = xy$ with $y(0) = 1$ and $y'(0) = 0$.

::: solution
1. **The surviving chain.** With $a_1 = 0$ only the chain from $a_0$ survives:
   $$\begin{aligned} a_3 &= \frac{1}{3 \cdot 2} \\ &= \frac16 \\ a_6 &= \frac{a_3}{6 \cdot 5} \\ &= \frac{1}{180} \\ a_9 &= \frac{a_6}{9 \cdot 8} \\ &= \frac{1}{12\,960} \\ a_{12} &= \frac{1}{1\,710\,720} \end{aligned}$$
2. **Sum at $x = 1$.**
   $$\begin{aligned} y(1) &= 1 + 0.166\,667 \\ &\quad + 0.005\,556 + 0.000\,077 \\ &\quad + 0.000\,001 \\ &= 1.172\,300 \end{aligned}$$
3. **Check.** An RK4 integration of the equation from 0 to 1 gives 1.172 300 too.
4. **Why it converges fast.** The terms shrink so fast because each is divided by roughly $n^2$; at $x = 2$ it takes nine terms to reach ten digits.

**Answer:** $y(1) = 1.172\,300$.
:::
:::

::: example
## How far from 0 can you trust the series solution of $(4 + x^2)y'' + xy' + y = 0$?

::: solution
1. **Standard form.** Divide by $4 + x^2$:
   $$p = \frac{x}{4 + x^2}, \qquad q = \frac{1}{4 + x^2}$$
2. **Singular points.** These blow up where $x^2 = -4$, at $x = \pm 2j$.
3. **Radius of convergence.** Those are 2 away from the origin, so the series about 0 converges for $|x| < 2$ at least.
4. **Why the limit is there.** On the real line the equation is perfectly calm at $x = 2$; the limit comes from points you'd never plot.
5. **Going farther.** For values farther out, expand about another center, or integrate numerically.

**Answer:** you can trust it for $|x| < 2$ at least.
:::
:::

::: check
given: a0 = 1 | 2; a1 = 1 | -1 | 3; k = 4 | 5
answer: a0*(1/24)*step(5 - k - 0.5) + a1*(1/120)*step(k - 4.5)
tolerance: 0.5%

## For $y'' + y = 0$ with $y(0) = \given{a0}$ and $y'(0) = \given{a1}$, what is the coefficient $a_{\given{k}}$ of $x^{\given{k}}$ in the series solution?

::: right
Right. The recurrence $a_{n+2} = -a_n/((n + 2)(n + 1))$ steps twice from $a_{\given{k} - 4}$, and two minus signs cancel: {answer}.
:::

::: misses
- [-(a0/24)*step(5 - k - 0.5) - (a1/120)*step(k - 4.5)] Two steps of the recurrence give two minus signs, which cancel.
- [a0/12*step(5 - k - 0.5) + a1/20*step(k - 4.5)] Each step divides by $(n + 2)(n + 1)$; two steps divide by $4!$ for $a_4$ or $5!$ for $a_5$.
- [any] Not yet. Apply $a_{n+2} = -a_n/((n + 2)(n + 1))$ twice, starting from $a_0$ (for $a_4$) or $a_1$ (for $a_5$).
:::
:::

::: check
given: x = 1 | 1.5 | 2
answer: 1 + x^3/6 + x^6/180 + x^9/12960 + x^12/1710720
tolerance: 0.01%

## Using the series through $x^{12}$, what is the solution of $y'' = xy$ with $y(0) = 1$, $y'(0) = 0$ at $x$ = {x}?

::: right
Right. $1 + x^3/6 + x^6/180 + x^9/12\,960 + x^{12}/1\,710\,720$ = {answer}, accurate to many more digits than shown at this $x$.
:::

::: misses
- [1 + x^3/6] That stops after one correction. Keep the terms through $x^{12}$.
- [1 + x^2/2 + x^4/24] That's $\cosh x$, the series for $y'' = y$. Airy's equation steps three places at a time.
- [any] Not yet. Use $a_{n+2} = a_{n-1}/((n + 2)(n + 1))$ from $a_0 = 1$: $a_3 = 1/6$, $a_6 = 1/180$, and on.
:::
:::

::: check
given: c = 0.5 | 2 | 3 | 5
answer: c
tolerance: 0.5%

## About $x = 0$, what is the guaranteed radius of convergence of the series solutions of $(x^2 + \given{c}^2)y'' + y = 0$?

::: right
Right. $q = 1/(x^2 + \given{c}^2)$ blows up at $x = \pm \given{c}j$, a distance {c} from the origin.
:::

::: misses
- [c^2] The singular points are at $\pm\given{c}j$; their distance from 0 is {c}, not its square.
- [any] Not yet. Find where $x^2 + \given{c}^2 = 0$ in the complex plane and measure its distance from 0.
:::
:::

::: check
kind: derivation
vars: n = 1..8, x = 0.1..1

## Find the recurrence for $y' = 2xy$ with $y = \sum a_nx^n$.

::: step
answer: (n + 1)*x^n

### Writing $y'$ in powers $x^n$, the coefficient $a_{n+1}$ multiplies what?
:::

::: step
answer: 2*x^n

### Writing $2xy$ in powers $x^n$, the coefficient $a_{n-1}$ multiplies what?
:::

::: step
answer: 2/(n + 1)

### So $a_{n+1} = \;?\; \times a_{n-1}$.
:::

::: right
Right. With $a_0 = 1$ and $a_1 = 0$: $a_2 = 1$, $a_4 = 1/2$, $a_6 = 1/6$, the series for $e^{x^2}$, which solves $y' = 2xy$ as separation of variables confirms.
:::
:::

::: check
kind: parts
given: a0 = 1 | 2 | 3

## Solve $y'' + xy' + y = 0$ by series with $y(0) = \given{a0}$ and $y'(0) = 0$.

::: part
kind: expression
answer: -a/(n + 2)
vars: a = 0.5..3, n = 0..10

### Substituting gives $(n + 2)(n + 1)a_{n+2} + (n + 1)a_n = 0$. Write $a_{n+2}$ in terms of $a = a_n$ and $n$.

::: misses
- [-a/((n + 2)*(n + 1))] The $(n + 1)$ factors cancel: the $xy'$ and $y$ terms combine to $(n + 1)a_n$.
- [any] Divide by $(n + 2)(n + 1)$ and cancel.
:::
:::

::: part
answer: a0/8
tolerance: 0.5%

### What is $a_4$?

::: misses
- [-a0/8] $a_2 = -a_0/2$, then $a_4 = -a_2/4 = +a_0/8$.
- [any] Apply $a_{n+2} = -a_n/(n + 2)$ twice from $a_0$.
:::
:::

::: right
Right. The coefficients $1, -\frac12, \frac18, -\frac1{48}, \ldots$ times $a_0$ are those of $e^{-x^2/2}$, and a direct check confirms that it solves the equation.
:::
:::

::: check
kind: python
given: X = 1 | 2 | 3; tol = 1e-8 | 1e-12

## Write `airy_series(x, tol)` that sums the series solution of $y'' = xy$ with $y(0) = 1$, $y'(0) = 0$ from its recurrence, adding terms until the next one is smaller than `tol`. Return `(value, terms)`, the sum and the number of nonzero terms used. Set `ys, n = airy_series(X, tol)` for `X` = {X} and `tol` = {tol}, and `y_rk` to the RK4 solution at `X` with 20 000 steps.

```python starter
def airy_series(x, tol):
    return 1 + x**3 / 6, 2

ys, n = airy_series(X, tol)
y_rk = ys
print(ys, n, y_rk)
```

```python solution
def airy_series(x, tol):
    a, k, total, terms = 1.0, 0, 0.0, 0
    while True:
        term = a * x**k
        total += term
        terms += 1
        a = a / ((k + 3) * (k + 2))
        k += 3
        if abs(a * x**k) < tol:
            return total, terms

ys, n = airy_series(X, tol)
h, y, v = X / 20000, 1.0, 0.0
x = 0.0
for _ in range(20000):
    k1 = (v, x * y)
    k2 = (v + h / 2 * k1[1], (x + h / 2) * (y + h / 2 * k1[0]))
    k3 = (v + h / 2 * k2[1], (x + h / 2) * (y + h / 2 * k2[0]))
    k4 = (v + h * k3[1], (x + h) * (y + h * k3[0]))
    y += h / 6 * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0])
    v += h / 6 * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1])
    x += h
y_rk = y
print(ys, n, y_rk)
```

```python tests
def ref(x, N=60):
    a, s = [0.0] * N, 0.0
    a[0] = 1.0
    for m in range(1, N - 2):
        a[m + 2] = a[m - 1] / ((m + 2) * (m + 1))
    return sum(a[k] * x**k for k in range(N))
r = ref(X)
assert abs(ys - r) < 10 * tol * max(1, abs(r)), f"The series sum should be {r:.12f}. Each coefficient is the one three places back over (k + 3)(k + 2)."
assert abs(y_rk - r) < 1e-8 * max(1, abs(r)), "RK4 with 20 000 steps should agree with the series to about 8 digits."
assert 2 <= n <= 20, "The terms fall so fast that a few dozen at most are needed."
```

::: right
Right. The series and the integration agree, which checks both. Tightening the tolerance by four digits costs only a couple of extra terms, because each term is divided by roughly $k^2$.
:::
:::

::: check
kind: choice

## The equation $(1 + x^2)y'' + y = 0$ is smooth for every real $x$. Why does its series solution about 0 stop converging at $|x| = 1$?

- [x] Because its coefficient $1/(1 + x^2)$ blows up at $x = \pm j$, a distance 1 from 0 in the complex plane
- [ ] Because the solution itself blows up at $x = 1$
- [ ] Because power series never converge past 1
- [ ] Because of rounding error

::: right
Right. A power series converges in a disc in the complex plane, and the disc can't reach past the nearest trouble, even trouble that's off the real axis. The solution is fine at $x = 1$; it's the series centered at 0 that can't represent it there.
:::

::: misses
- [2] The solution is smooth for all real $x$. It's the series about 0 that runs out.
- [3] Many power series converge everywhere, like those for $e^x$ and Airy's equation.
- [4] It's a property of the exact series, not of computing it.
:::
:::

::: explain
## A series solution and an RK4 integration both give $y(1)$ for Airy's equation. What does each offer that the other doesn't?

::: model
The series gives the solution as a formula: its coefficients can be found exactly, its error at any $x$ can be bounded from the first neglected term, and it shows the solution's behavior near the center, such as which powers of $x$ start it off. But it only converges within its radius, and far out it needs many terms. RK4 works for any equation, linear or not, out to any distance, but it gives numbers at chosen points rather than a formula, and its accuracy depends on the step size. Getting the same number both ways is strong evidence that both are right.
:::
:::

::: practice

::: check
given: a0 = 1 | 3; x = 0.5 | 1
answer: a0*(1 - x^2/2 + x^4/24)
tolerance: 0.5%

## Sum the series solution of $y'' + y = 0$ with $y(0) = \given{a0}$, $y'(0) = 0$ through $x^4$, at $x$ = {x}.

::: misses
- [a0*(1 + x^2/2 + x^4/24)] The recurrence $a_{n+2} = -a_n/((n+2)(n+1))$ alternates the signs.
- [any] The terms are $a_0(1 - x^2/2 + x^4/24)$.
:::
:::

::: check
given: k = 3 | 6 | 9
answer: (1/6)*step(4 - k) + (1/180)*step(k - 4)*step(7 - k) + (1/12960)*step(k - 7)
tolerance: 0.5%

## For Airy's equation with $y(0) = 1$, $y'(0) = 0$, what is $a_{\given{k}}$?

::: misses
- [any] Use $a_3 = 1/6$, $a_6 = 1/180$, $a_9 = 1/12\,960$, each the one before divided by $(k)(k - 1)$.
:::
:::
:::
