---
title: Alternating series
heading: Overshooting your way to the answer
eyebrow: A6 · Lesson 28 · Alternating series
xp: 40
---

::: hook
Evaluate a square wave's Fourier series at the middle of a pulse and you get $1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \cdots$, which adds up to $\frac{\pi}{4}$. The signs alternate, so each partial sum overshoots, then undershoots, closing in from both sides. That back-and-forth gives you something rare: an exact, easy bound on the error after any number of terms. Calculators and microcontrollers that compute sines and cosines rely on exactly this bound to know when to stop.
:::

::: play
- The staircase is the partial sums of $1 - r + r^2 - r^3 + \cdots$. The flat line is the true sum, $\frac{1}{1 + r}$.
- The partial sums land alternately above and below the line. Each one is closer than the last.
- The readout compares the actual error after $N$ terms with the bound, the size of the next term. Is the bound ever wrong?
:::
:::

```sim plot
view: graph
x: n = 0..15
y: S = 0..1.1
slider: r = 0.3..0.95 step 0.05 = 0.8
slider: N = 1..15 step 1 = 5
plot: (1 - (-r)^(floor(n) + 1))/(1 + r) | label: partial sums | samples: 800
plot: 1/(1 + r) | label: sum | color: ch3
readout: error after N terms = abs((-r)^N/(1 + r)) | digits: 4
readout: next term, the bound = r^N | digits: 4
```

::: predict
## You add the first 3 terms of $1 - \frac{1}{2!} + \frac{1}{4!} - \frac{1}{6!} + \cdots$ (the series for $\cos 1$). What's the most your answer can be off by?

- [ ] $\frac{1}{4!}$
- [x] $\frac{1}{6!}$, about 0.0014
- [ ] It can't be known without the true value
- [ ] $\frac{1}{3}$ of the last term

::: reveal
$\frac{1}{6!} = 0.00139$, the size of the first term you left out. Three terms give $1 - 0.5 + 0.041667 = 0.541667$; the true $\cos 1 = 0.540302$, off by 0.00136, inside the bound. For an alternating series with shrinking terms, the error is always smaller than the next term.
:::
:::

::: nameit
## The alternating series test

A series $b_1 - b_2 + b_3 - b_4 + \cdots$ with $b_n > 0$ converges if

1. the terms shrink: $b_{n+1} \le b_n$, and
2. they approach zero: $b_n \to 0$.

The partial sums step back and forth across the limit with ever-shorter steps, so they must close in on it.

## The error bound

If you stop after $N$ terms, the error is at most the next term:

$$|S - S_N| \le b_{N+1}$$

and the true sum lies between $S_N$ and $S_{N+1}$. This is one of the few places in mathematics where the error of an infinite process is this easy to bound.

## Absolute and conditional convergence

A series **converges absolutely** if $\sum|a_n|$ converges; then it converges whatever the signs. A series that converges only because of its alternating signs **converges conditionally**. The alternating harmonic series $1 - \frac{1}{2} + \frac{1}{3} - \cdots = \ln 2$ is the standard example: $\sum\frac{1}{n}$ diverges.

Conditionally convergent series are fragile. Reorder their terms and you can make them add up to any number you like, so never rearrange one. Absolutely convergent series can be rearranged freely.
:::

::: example
## How many terms of $1 - \frac{1}{3} + \frac{1}{5} - \cdots = \frac{\pi}{4}$ guarantee an error below 0.001?

::: solution
1. **Find the first term left out.** The $(N + 1)$th term is $\frac{1}{2N + 1}$.
2. **Make it small enough.**
   $$\frac{1}{2N + 1} < 0.001 \quad\text{so}\quad 2N + 1 > 1000$$
   giving $N = 500$ terms.
3. **Interpret.** That's slow: the terms shrink like $\frac{1}{n}$. Series whose terms shrink like factorials, as in the cosine example, need only a handful.

**Answer:** 500 terms.
:::
:::

::: example
## Estimate $\ln 1.5$ from $\ln(1 + x) = x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots$ with four terms, and bound the error.

::: solution
1. **Add four terms.** With $x = 0.5$:
   $$\begin{aligned} &0.5 - 0.125 \\ &\quad + 0.041667 - 0.015625 \\ &= 0.401042 \end{aligned}$$
2. **Bound the error.** The next term is
   $$\frac{0.5^5}{5} = 0.00625$$
   so $\ln 1.5$ lies between 0.401042 and 0.407292.
3. **Check.** The true value is 0.405465, inside that range.

**Answer:** $\ln 1.5 \approx 0.401042$, and the true value lies between 0.401042 and 0.407292.
:::
:::

::: example
## Estimate $\sum_{n=1}^\infty\frac{(-1)^{n+1}}{n^2}$ (exactly $\pi^2/12 = 0.8225$) with five terms, and bound the error.

::: solution
1. **Add five terms.**
   $$1 - \tfrac14 + \tfrac19 - \tfrac1{16} + \tfrac1{25} = 0.8386$$
2. **Bound the error.** The alternating series bound says the error is less than the next term:
   $$\frac{1}{36} = 0.0278$$
3. **Compare with the true error.** The true error is 0.0161. The partial sum overshoots because the last term added was positive.

**Answer:** five terms give 0.8386, with an error bound of 0.0278; the true error is 0.0161.
:::
:::

::: check
given: p = 1 | 2; N = 10 | 100
answer: 1/(N + 1)^p
tolerance: 0.5%

## You add the first {N} terms of $\sum_{n=1}^\infty\dfrac{(-1)^{n+1}}{n^{\given{p}}}$. What is the alternating series bound on the error?

::: right
Right. The next term, $\frac{1}{(N + 1)^p}$ = {answer}.
:::

::: misses
- [1/N^p] That's the last term you added. The bound is the first one you left out.
- [any] Not yet. The error is at most the size of the next term.
:::
:::

::: check
given: eps = 0.05 | 0.02 | 0.01 | 0.005 | 0.002 | 0.001
answer: 1/(2*eps)

## How many terms of $1 - \frac{1}{3} + \frac{1}{5} - \cdots$ guarantee an error below {eps}?

::: right
Right. You need $\frac{1}{2N + 1} \le \varepsilon$, so {answer} terms.
:::

::: misses
- [1/eps] The terms are $\frac{1}{2n - 1}$, the odd numbers, which shrink twice as fast as $\frac{1}{n}$.
- [any] Not yet. Solve $\frac{1}{2N + 1} \le \varepsilon$.
:::
:::

::: check
given: r = 0.5 | 0.2 | 0.8
answer: 1/(1 + r)
tolerance: 0.5%

## What is $1 - \given{r} + \given{r}^2 - \given{r}^3 + \cdots$?

::: right
Right. A geometric series with ratio $-r$: $\frac{1}{1 + r}$ = {answer}.
:::

::: misses
- [1/(1 - r)] The ratio is $-\given{r}$, so the denominator is $1 - (-r)$.
- [any] Not yet. Geometric series, ratio $-r$.
:::
:::

::: check
given: x = 0.5 | 1 | 1.5
answer: x^6/720
tolerance: 0.5%

## You estimate $\cos\given{x}$ with $1 - \frac{x^2}{2} + \frac{x^4}{24}$. What is the alternating series bound on the error?

::: right
Right. The next term is $\frac{x^6}{6!}$ = {answer}.
:::

::: misses
- [x^4/24] That's the last term you used.
- [x^5/120] The cosine series has only even powers; the next one is $x^6$.
- [any] Not yet. The next term of the series.
:::
:::

::: check
kind: choice

## How does $\sum\dfrac{(-1)^n}{n}$ converge?

- [ ] Absolutely
- [x] Conditionally: it converges, but $\sum\frac{1}{n}$ doesn't
- [ ] It diverges
- [ ] Only if you group the terms in pairs

::: right
Right. The alternating signs are what make it converge, so the convergence is conditional.
:::

::: misses
- [1] Absolutely would need $\sum\frac{1}{n}$ to converge, and it doesn't.
- [3] The alternating series test applies: the terms shrink to zero.
- [any] Check $\sum|a_n|$.
:::
:::

::: check
kind: choice

## How does $\sum\dfrac{(-1)^n}{n^2}$ converge?

- [x] Absolutely
- [ ] Conditionally
- [ ] It diverges
- [ ] It can't be decided

::: right
Right. $\sum\frac{1}{n^2}$ converges, so the series converges absolutely.
:::

::: misses
- [2] Conditional means only the signs save it. Here $\sum|a_n|$ converges too.
- [any] Check $\sum|a_n|$.
:::
:::

::: check
kind: parts
given: p = 1 | 2; N = 5 | 10

## Bound the error of $\sum\frac{(-1)^{n+1}}{n^{\given{p}}}$ after {N} terms.

::: part
answer: 1/(N + 1)^p
tolerance: 0.5%

### What is the alternating-series bound?

::: misses
- [1/N^p] It's the first term left out, number $N + 1$.
- [any] The size of the next term.
:::
:::

::: part
answer: 10^(4/p)
tolerance: 0

### How many terms guarantee an error below 0.0001?

::: misses
- [any] Need $\frac{1}{(N + 1)^p} < 0.0001$.
:::
:::
:::

::: check
kind: derivation
vars: x = -0.5..0.5

## Use the alternating series for $\ln(1 + x)$ to bound an error.

::: step
answer: x - x^2/2 + x^3/3

### Write the first three terms of $\ln(1 + x)$.
:::

::: step
answer: x^4/4

### For $0 < x < 1$ the series alternates with shrinking terms. What bounds the error of those three terms?
:::

::: right
Right. The error is less than $x^4/4$, the first term left out.
:::
:::

::: explain
## Why is the error of an alternating series smaller than the first term you leave out?

::: model
After you stop, the rest of the series is $\pm(b_{N+1} - b_{N+2} + b_{N+3} - \cdots)$. Group it in pairs: $(b_{N+1} - b_{N+2}) + (b_{N+3} - b_{N+4}) + \cdots$. Each pair is positive because the terms shrink, so the rest is positive. Group it the other way, $b_{N+1} - (b_{N+2} - b_{N+3}) - \cdots$, and each bracket is positive, so the rest is less than $b_{N+1}$. The leftover is between 0 and $b_{N+1}$.
:::
:::

::: practice

::: check
given: x = 0.1 | 0.2 | 0.25 | 0.3 | 0.4 | 0.5
answer: x^4/4
tolerance: 0.5%

## You estimate $\ln(1 + \given{x})$ with $x - \frac{x^2}{2} + \frac{x^3}{3}$. What is the error bound?

::: misses
- [x^3/3] That's the last term used.
- [any] The next term, $\frac{x^4}{4}$.
:::
:::

::: check
given: x = 0.2 | 0.3 | 0.5 | 0.7 | 0.8 | 1
answer: x^5/120
tolerance: 0.5%

## You estimate $\sin\given{x}$ with $x - \frac{x^3}{6}$. What is the error bound?

::: misses
- [x^3/6] That's the last term used.
- [any] The next term, $\frac{x^5}{5!}$.
:::
:::

::: check
given: N = 3..20 int
answer: 1/(N + 1)
tolerance: 0.5%

## You add {N} terms of $1 - \frac{1}{2} + \frac{1}{3} - \cdots = \ln 2$. What is the error bound?

::: misses
- [1/N] The bound is the first term left out.
- [any] $\frac{1}{N + 1}$.
:::
:::
:::
