Matching more derivatives
The tangent line \(f(a) + f'(a)(x - a)\) is the unique line with the same value and the same slope as \(f\) at \(a\). A parabola can also match the second derivative, the curvature. Keep going: the polynomial of degree \(n\) that matches \(f\) and its first \(n\) derivatives at \(a\) is
Definition
The Taylor polynomial of degree \(n\) of \(f\) at \(a\) is
\[ T_n(x) = f(a) + f'(a)(x - a) + \frac{f''(a)}{2!}(x - a)^2 + \cdots + \frac{f^{(n)}(a)}{n!}(x - a)^n. \]Why the factorials? Differentiate \((x - a)^k\) \(k\) times and you get \(k!\), so dividing by \(k!\) makes the \(k\)th derivative of \(T_n\) at \(a\) come out to exactly \(f^{(k)}(a)\).
The classic expansions
All at \(a = 0\) (these are often called Maclaurin polynomials):
| Function | Taylor polynomial | Why |
|---|---|---|
| \(e^x\) | \(1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots + \frac{x^n}{n!}\) | Every derivative is \(e^x\), which is 1 at 0. |
| \(\sin x\) | \(x - \frac{x^3}{3!} + \frac{x^5}{5!} - \cdots\) | Derivatives cycle \(\sin, \cos, -\sin, -\cos\): values 0, 1, 0, −1. |
| \(\cos x\) | \(1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \cdots\) | The same cycle, shifted by one. |
| \(\ln(1 + x)\) | \(x - \frac{x^2}{2} + \frac{x^3}{3} - \cdots\) | The \(k\)th derivative at 0 is \((-1)^{k+1}(k - 1)!\). |
| \(\frac{1}{1 - x}\) | \(1 + x + x^2 + \cdots + x^n\) | The geometric series of Unit 4. |
Notice that \(\sin\) has only odd powers and \(\cos\) only even ones, matching the facts that \(\sin\) is an odd function and \(\cos\) an even one.
Taylor's theorem
An approximation is only useful if you know how wrong it might be. Taylor's theorem gives the error an exact form.
Taylor's theorem (Lagrange remainder)
If \(f\) has \(n + 1\) derivatives on an interval containing \(a\) and \(x\), then for some \(c\) between \(a\) and \(x\),
\[ f(x) = T_n(x) + \frac{f^{(n+1)}(c)}{(n + 1)!}(x - a)^{n+1}. \]Look at the remainder: it has exactly the form of the next term of the polynomial, except that the derivative is evaluated at an unknown point \(c\) instead of at \(a\). For \(n = 0\) this is precisely the mean value theorem: \(f(x) = f(a) + f'(c)(x - a)\). Taylor's theorem is the MVT carried to higher order.
Proof idea
Fix \(x\) and let \(M\) be the number with \(f(x) = T_n(x) + M(x - a)^{n+1}\). Consider \(g(t) = f(t) - T_n(t) - M(t - a)^{n+1}\). Then \(g\) and its first \(n\) derivatives vanish at \(a\), and \(g(x) = 0\) too.
By Rolle, \(g'\) vanishes at some \(c_1\) between \(a\) and \(x\). Since \(g'(a) = 0\) as well, Rolle again gives \(c_2\) between \(a\) and \(c_1\) with \(g''(c_2) = 0\). Repeat \(n + 1\) times to get \(c\) with \(g^{(n+1)}(c) = 0\). But \(g^{(n+1)}(t) = f^{(n+1)}(t) - (n + 1)!\,M\), since \(T_n\) has degree \(n\). So \(M = \frac{f^{(n+1)}(c)}{(n + 1)!}\). ∎
Computing with guarantees
Example: \(\sin(0.1)\)
Use \(\sin x \approx x - \frac{x^3}{6}\). This is \(T_3\) and also \(T_4\) (the \(x^4\) term is zero), so the remainder involves the fifth derivative, \(\cos\), which is at most 1 in size:
\[ \left|\sin(0.1) - 0.0998333\ldots\right| \le \frac{(0.1)^5}{5!} \approx 8.3\times10^{-8}. \]A cubic gives seven correct decimal places.
Example: computing \(e\)
Take \(f(x) = e^x\), \(x = 1\). Every derivative is \(e^c\) with \(0 < c < 1\), so it's less than 3. Hence
\[ 0 < e - \left(1 + 1 + \frac1{2!} + \cdots + \frac1{n!}\right) < \frac{3}{(n + 1)!}. \]With \(n = 10\) the error is below \(7.6\times10^{-8}\): the sum is \(2.71828180\ldots\), and \(e = 2.71828182\ldots\) Factorials grow so fast that this converges spectacularly.
Going deeper: \(e\) is irrational
Suppose \(e = \frac pq\). Multiply the inequality above, with \(n = q\), by \(q!\):
\[ 0 < q!\,e - q!\left(1 + 1 + \cdots + \frac1{q!}\right) < \frac{3}{q + 1}. \]The middle is an integer (since \(q!\,e = (q - 1)!\,p\), and each \(\frac{q!}{k!}\) is an integer). But for \(q \ge 2\) it lies strictly between 0 and 1, which is impossible. And \(e\) isn't an integer either, since \(2 < e < 3\). ∎ A precise error bound has turned into a proof about the nature of a number.
When does the series converge?
Let \(n \to \infty\) and you get the Taylor series \(\sum \frac{f^{(k)}(a)}{k!}(x - a)^k\). It equals \(f(x)\) exactly when the remainder tends to 0. For \(e^x\), \(\sin\) and \(\cos\) it does, for every \(x\): the remainder is at most \(C\frac{|x|^{n+1}}{(n + 1)!}\), and factorials beat powers. But that isn't automatic.
Why a wall at exactly 1? On the real line, nothing special happens to \(\ln(1 + x)\) at \(x = 1\). Stranger still, \(\frac1{1 + x^2}\) is perfectly smooth on all of \(\mathbb R\), yet its series \(1 - x^2 + x^4 - \cdots\) diverges for \(|x| > 1\). The explanation lives off the real line: \(1 + x^2 = 0\) at \(x = \pm i\), at distance 1 from 0. The companion course on complex analysis shows that the radius of convergence is always the distance to the nearest point where the function breaks down in the complex plane.
A function its series can't see
Here is the deepest surprise. A function can have derivatives of every order, a Taylor series that converges everywhere, and still not equal its series.
The reason: \(e^{-1/x^2}\) tends to 0 faster than any \(x^n\) (substitute \(t = 1/x^2\): \(t^{n/2}e^{-t} \to 0\)). From this one can show that every derivative exists and equals 0 at the origin. All the information Taylor uses is at one point, and at that point this function looks exactly like zero.
Functions that do equal their Taylor series near every point are called analytic. On the real line, being infinitely differentiable doesn't make a function analytic. In the complex plane, astonishingly, just being differentiable once does: one of the central miracles of complex analysis.
History
Brook Taylor published the series in 1715, though Gregory and Newton knew special cases decades earlier, and Indian mathematicians of the Kerala school had series for \(\sin\), \(\cos\) and \(\arctan\) around 1400. Lagrange gave the remainder formula in 1797. Cauchy found the \(e^{-1/x^2}\) example in 1823, showing that a convergent Taylor series can still converge to the wrong function.
Uses: limits and the second derivative test
Taylor expansions turn hard limits into algebra. Write "\(+\,O(x^n)\)" for "plus something at most a constant times \(|x|^n\) near 0".
Example
\[ \frac{x - \sin x}{x^3} = \frac{x - \left(x - \frac{x^3}{6} + O(x^5)\right)}{x^3} = \frac16 + O(x^2) \to \frac16. \]No need to apply L'Hôpital three times.
Taylor also explains the second derivative test. If \(f'(a) = 0\), then near \(a\), \(f(x) \approx f(a) + \frac{f''(a)}{2}(x - a)^2\). If \(f''(a) > 0\), that's an upward parabola, so \(a\) is a local minimum; if \(f''(a) < 0\), a local maximum. If \(f''(a) = 0\), the parabola is flat and you must look at higher terms: \(x^3\) has no extremum at 0, \(x^4\) has a minimum.
Practice set
Mixed questions covering the whole unit. Try each one before opening the answer.
1. Find the Taylor polynomial of degree 3 of \(e^{2x}\) at 0.
Show answer
The \(k\)th derivative is \(2^ke^{2x}\), which is \(2^k\) at 0. So \(T_3 = 1 + 2x + 2x^2 + \frac43x^3\). (Or substitute \(2x\) into the series for \(e^x\).)
2. Estimate \(\sqrt{1.1}\) with the degree 2 Taylor polynomial of \(\sqrt{1 + x}\), and bound the error.
Show answer
\(T_2 = 1 + \frac x2 - \frac{x^2}8\), giving \(1.04875\). The third derivative is \(\frac38(1 + c)^{-5/2} \le \frac38\), so the error is at most \(\frac38\cdot\frac{(0.1)^3}{6} = 6.25\times10^{-5}\). (True value: \(1.048809\ldots\))
3. How many terms of \(\sum \frac1{k!}\) guarantee \(e\) to within \(10^{-6}\)?
Show answer
Need \(\frac{3}{(n + 1)!} < 10^{-6}\), so \((n + 1)! > 3\times10^6\). Since \(10! = 3{,}628{,}800\), \(n = 9\) works: the terms up to \(\frac1{9!}\).
4. Use Taylor expansions to find \(\displaystyle\lim_{x\to0}\frac{e^x - 1 - x}{x^2}\).
Show answer
\(e^x = 1 + x + \frac{x^2}{2} + O(x^3)\), so the quotient is \(\frac12 + O(x) \to \frac12\). It agrees with the L'Hôpital calculation of Unit 7.
5. Show that \(|\cos x - (1 - \frac{x^2}{2})| \le \frac{x^4}{24}\) for all \(x\).
Show answer
\(1 - \frac{x^2}2\) is \(T_3\) for \(\cos\) (the cubic term is 0). The remainder is \(\frac{\cos^{(4)}(c)}{4!}x^4 = \frac{\cos c}{24}x^4\), and \(|\cos c| \le 1\).
6. Does \(x^4\) or \(x^3\) equal its Taylor series at 0? Is every polynomial analytic?
Show answer
Yes. A polynomial's derivatives vanish beyond its degree, so the remainder is exactly 0 once \(n\) reaches the degree: the Taylor polynomial is the polynomial itself, at any centre \(a\). Every polynomial is analytic.
Summary and glossary
- \(T_n\) is the polynomial matching \(f\) and its first \(n\) derivatives at \(a\); the coefficients are \(\frac{f^{(k)}(a)}{k!}\).
- Taylor's theorem: the error is \(\frac{f^{(n+1)}(c)}{(n + 1)!}(x - a)^{n+1}\), the MVT carried to higher order.
- For \(e^x\), \(\sin\), \(\cos\) the remainder tends to 0 for every \(x\): the series converge everywhere.
- Some series converge only on an interval, for reasons only visible in the complex plane.
- \(e^{-1/x^2}\) is infinitely differentiable but not analytic: its Taylor series at 0 is 0.
- Taylor polynomial
- \(\sum_{k=0}^n \frac{f^{(k)}(a)}{k!}(x - a)^k\).
- Remainder
- \(f(x) - T_n(x)\), the error of the approximation.
- Taylor series
- The infinite sum, as \(n \to \infty\).
- Analytic
- Equal to its Taylor series near every point.
- Smooth
- Having derivatives of every order.