LocusBlog

Taylor series

A Taylor series represents a function as an infinite polynomial in powers of $x - a$, with the coefficients chosen so that every derivative of the series matches every derivative of the function at the point $a$:

$$f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n$$

$a$ is the centre, $f^{(n)}(a)$ is the $n$th derivative evaluated there, and $f^{(0)}$ means $f$ itself. When the centre is $0$ the series is called a Maclaurin series, which is not a different object, just the case everyone writes out.

The equals sign in that formula is a claim, not a definition, and it is the part that fails. The right side is built from local information at a single point. Whether it reproduces $f$ anywhere else has to be proved separately, and sometimes it is false.

Why the coefficients are forced

Suppose $f$ can be written as some power series $\sum_{n\ge0} c_n(x-a)^n$ near $a$. The coefficients are then not a choice; they are determined.

Set $x = a$. Every term with a factor of $(x-a)$ dies and $c_0 = f(a)$. Differentiate the series term by term,

$$f'(x) = c_1 + 2c_2(x-a) + 3c_3(x-a)^2 + \cdots$$

and set $x = a$ again: $c_1 = f'(a)$. Differentiate twice and the constant term is $2c_2$, so $c_2 = f''(a)/2$. After $n$ differentiations the surviving constant is $n(n-1)\cdots 1 \cdot c_n = n!\,c_n$, which gives $c_n = f^{(n)}(a)/n!$ and nothing else.

That is the whole construction. The factorial in the denominator is not a normalisation someone chose for tidiness; it is the factorial that the repeated differentiation produced, being divided back out.

The three series worth knowing cold

For $f(x) = e^x$ every derivative is $e^x$, so every derivative at $0$ is $1$ and each coefficient is $1/n!$:

$$e^x = \sum_{n=0}^{\infty}\frac{x^n}{n!} = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \cdots$$

For $\sin x$ the derivatives at $0$ cycle through $0, 1, 0, -1$, so the even coefficients vanish:

$$\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \cdots = \sum_{n=0}^{\infty}\frac{(-1)^n x^{2n+1}}{(2n+1)!}$$

For $\cos x$ the cycle starts one step earlier, at $1, 0, -1, 0$, and the odd coefficients vanish:

$$\cos x = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots = \sum_{n=0}^{\infty}\frac{(-1)^n x^{2n}}{(2n)!}$$

Those two are consistent in the way they have to be. Differentiate the sine series term by term: $x$ gives $1$, $-x^3/6$ gives $-x^2/2$, $x^5/120$ gives $x^4/24$. That is the cosine series, exactly. A power series can be differentiated term by term inside its radius of convergence, so this is a proof and not a coincidence, and it is the cheapest way to check that you remembered which series has the odd powers.

How wrong a truncated series is

Cut the series after the $x^n$ term and you have the Taylor polynomial $P_n$. Taylor’s theorem says the leftover has the shape of the next term, with the derivative evaluated at an unknown point:

$$f(x) - P_n(x) = R_n(x) = \frac{f^{(n+1)}(c)}{(n+1)!}(x-a)^{n+1}$$

for some $c$ strictly between $a$ and $x$. You never learn $c$. What you do is bound $|f^{(n+1)}|$ over the interval between $a$ and $x$, which turns an unknown remainder into a guaranteed error bar.

Estimate $e^{0.5}$ with the cubic Maclaurin polynomial:

$$P_3(0.5) = 1 + 0.5 + \frac{0.25}{2} + \frac{0.125}{6} = 1 + 0.5 + 0.125 + 0.0208333 = 1.6458333$$

For the bound, $f^{(4)}(c) = e^c$ with $c$ somewhere in $(0, 0.5)$, so $e^c < e^{0.5}$. Quoting $e^{0.5}$ to bound the error in computing $e^{0.5}$ is circular, so use something coarse that is known in advance: $e^{0.5} < e < 3$. Then

$$|R_3(0.5)| \le \frac{3 \times 0.5^4}{4!} = \frac{3 \times 0.0625}{24} = 0.0078125$$

The true value is $e^{0.5} = 1.6487213$, so the actual error is $0.0028879$. The bound holds, with room to spare, which is what a bound built on a worst-case derivative should look like. Tightening the derivative bound to $1.65$ gives $0.0042969$, still larger than the true error and still honest.

The same machinery says how many terms you need in advance. Requiring $3 \times 0.5^{n+1}/(n+1)! < 5\times10^{-7}$ first succeeds at $n = 7$, where the bound is $2.9\times10^{-7}$. Summing eight terms gives $1.6487212$, and the true value rounds to $1.6487213$: six decimal places, as promised, with an actual error of $1.0\times10^{-7}$.

Sine gives a sharper demonstration. $P_5(0.5) = 0.47942708$ against $\sin 0.5 = 0.47942554$, an error of $1.54\times10^{-6}$. The $n=5$ bound is $0.5^6/6! = 2.17\times10^{-5}$, more than ten times too pessimistic. But the $x^6$ coefficient of the sine series is zero, so $P_5$ and $P_6$ are the same polynomial and you are entitled to use $n = 6$: the bound becomes $0.5^7/7! = 1.550\times10^{-6}$, within half a percent of the error it is bounding. Same polynomial, same error, much better bound, purely from noticing that a term was missing.

Where the series stops

Convergence is a question about $x$, and the ratio test usually answers it. For $e^x$ the ratio of consecutive terms is $|x|/(n+1)$, which goes to $0$ for every $x$, so the series converges on the whole real line. Sine and cosine have the same factorial growth and the same answer.

Most series are not so generous. The geometric series $\sum x^n$ has term ratio $|x|$ and converges only for $|x| < 1$, even though its sum $1/(1-x)$ is a perfectly well-behaved number at $x = 2$. The series is built at the centre and cannot reach past the nearest point where the function misbehaves, so the radius of convergence is the distance from the centre to that point. Endpoints have to be tested one at a time; $\ln(1+x)$ has radius $1$, converges at $x = 1$ as the alternating harmonic series, and diverges at $x = -1$.

The deeper trap is assuming that convergence settles the matter. It does not. A Taylor series can converge everywhere and still fail to equal $f$ anywhere except the centre. The standard counterexample is $f(x) = e^{-1/x^2}$ for $x \neq 0$ with $f(0) = 0$: every derivative at the origin works out to zero, so the Maclaurin series is $0 + 0x + 0x^2 + \cdots$, which converges on all of $\mathbb{R}$ to the zero function and agrees with $f$ only at $x = 0$. What is actually required is $R_n(x) \to 0$ as $n \to \infty$, and for $e^{-1/x^2}$ it does not. Showing a series converges is not the same as showing it converges to the function you started with.

Working through the remainder bound on a few functions is what makes the distinction stick, and the Taylor and Maclaurin series drill asks for the coefficients and the polynomial directly. The study guide section covers the same ground with the convergence arguments written out.

References