Math Applets

Taylor’s theorem

Taylor polynomial, remainder term:

Let IRI \subseteq \mathbb{R} be an interval, x0Ix_0 \in I, and f:IRf : I \to \mathbb{R} an nn times differentiable function.

i) The polynomial function Tn:RR,xk=0nf(k)(x0)k!(xx0)kT_n : \mathbb{R} \to \mathbb{R}, \qquad x \mapsto \sum_{k=0}^n \frac{f^{(k)}(x_0)}{k!}\,(x - x_0)^k is called the n-th Taylor polynomial of ff in the expansion point x0x_0.

ii) The function Rn:IR,  xf(x)Tn(x)R_n : I \to \mathbb{R}, \; x \mapsto f(x) - T_n(x) is the remainder term corresponding to TnT_n.


Taylor’s theorem:

Let IRI \subseteq \mathbb{R} be an interval, x0Ix_0 \in I, and f:IRf : I \to \mathbb{R} an nn times differentiable function in x0x_0, where n1n \ge 1.
Then the following statements hold:

i) (Taylor’s formula) For all xIx \in I, f(x)=k=0nf(k)(x0)k!(xx0)k+Rn(x),f(x) = \sum_{k=0}^n \frac{f^{(k)}(x_0)}{k!}\,(x - x_0)^k + R_n(x), where limxx0Rn(x)(xx0)n=0.\lim_{x \to x_0} \frac{R_n(x)}{(x - x_0)^n} = 0.

ii) (Lagrange remainder) If ff is even (n+1)(n+1) times differentiable, then for every xI{x0}x \in I \setminus \{x_0\} there exists a
ξ\xi between xx and x0x_0 such that Rn(x)=f(n+1)(ξ)(n+1)!(xx0)n+1.R_n(x) = \frac{f^{(n+1)}(\xi)}{(n+1)!}\,(x - x_0)^{n+1}.


Example 1: f(x)=exf(x)=e^x

How to use

  • Visualize Taylor’s formula for f(x)=sin(x)f(x)=\sin(x) by comparing the function with its Taylor polynomial TnT_n around a movable expansion point x0x_0.
  • See the remainder term at a chosen point xx: Rn(x)=f(x)Tn(x).R_n(x)=f(x)-T_n(x).
  • Drag the blue point x0x_0 on the curve to choose the expansion point.
  • Move the slider nn to select the degree of the Taylor polynomial TnT_n.
  • Drag the orange point xx on the curve to choose where you evaluate the approximation.
  • The blue curve is f(x)=sin(x)f(x)=\sin(x).
  • The pink curve is the Taylor polynomial Tn(x)T_n(x) centered at x0x_0.
  • The green vertical dashed segment at the current xx is the remainder Rn(x)R_n(x): its length is f(x)Tn(x)|f(x)-T_n(x)|.
  • The endpoints of the green segment are (x,f(x))(x,f(x)) and (x,Tn(x))(x,T_n(x)).
  • Fix x0x_0 and drag xx close to x0x_0: the green segment becomes small, illustrating that Tn(x)T_n(x) approximates f(x)f(x) well near the expansion point.
  • Keep x0x_0 fixed and increase nn: the pink curve typically matches the blue curve better near x0x_0, and the remainder at the chosen xx usually decreases.
  • For a fixed degree nn, move xx farther away from x0x_0: the remainder generally grows, showing that Taylor polynomials are local approximations.
Loading graph…
  • Hold Shift + scroll to zoom
  • Hold Shift + drag to move
  • Points shaped like <> act as sliders

Example 2: g(x)=x5xg(x)=x^5|x|

How to use

  • See that Taylor’s theorem needs enough differentiability at the expansion point.
  • For g(x)=x5x,g(x)=x^5|x|, the function is 55-times differentiable at x0=0x_0=0, but not 66-times differentiable at x0=0x_0=0. The applet shows what goes wrong when you try to use degree n=6n=6 near 00.
  • Drag the blue point x0x_0 on the curve to choose the expansion point.
  • Move the slider nn (allowed values 0,,60,\dots,6).
  • Drag the orange point xx on the curve to choose where you evaluate the approximation.
  • The blue curve is g(x)g(x).
  • The pink curve is the Taylor polynomial Tn(x)T_n(x) around the chosen x0x_0 (only shown when the required derivatives exist).
  • The green vertical dashed segment at the current xx is the remainder Rn(x)=g(x)Tn(x)R_n(x)=g(x)-T_n(x) (its length is g(x)Tn(x)|g(x)-T_n(x)|).
  • If the Taylor polynomial is not defined (the “failure case”), the applet hides TnT_n and RnR_n, and the graph of gg turns red as a warning.
  • First set n=5n=5 and move x0x_0 close to 00: the Taylor polynomial is still defined, and near x0x_0 the remainder segment tends to get small.
  • Now set n=6n=6 and drag x0x_0 toward 00:
    • as x0x_0 gets sufficiently close to 00, the applet declares the Taylor polynomial undefined (pink curve and green remainder disappear, and gg turns red).
    • this corresponds to the fact that g(6)(0)g^{(6)}(0) does not exist, so the degree-6 Taylor polynomial at x0=0x_0=0 is not well-defined.
  • Even before the polynomial disappears, you can observe instability for n=6n=6 when x0x_0 is near 00:
    • keep n=6n=6,
    • choose x0x_0 close to 00,
    • move the evaluation point xx a bit away from x0x_0,
    • notice that the remainder segment R6(x)R_6(x) can become very large.

Loading graph…
  • Hold Shift + scroll to zoom
  • Hold Shift + drag to move
  • Points shaped like <> act as sliders

Description

Reference: Lecture Notes Calculus 1 ( May22,2022 ) Definition6.6 and Theorem6.19 page 115

In both applets:

  • Drag the blue point x0x_0 to choose the expansion point.
  • Use the slider nn to choose the Taylor degree.
  • Drag the orange point xx to evaluate the approximation at a point.
  • The vertical segment labelled Rn(x)R_n(x) visualizes the approximation error at the current xx.

Example 1: f(x)=exf(x)=e^x

Link to code.

For the exponential function, all derivatives exist everywhere and satisfy

f(k)(x0)=ex0.f^{(k)}(x_0)=e^{x_0}.

Hence the Taylor polynomial is well-defined for every degree nn and every expansion point x0x_0.

In the code, the Taylor polynomial is implemented as in the definition:

const T = (x: number) => {
  const x0 = getX0();
  const n = getN();
  let s = 0;
  const dx = x - x0;

  for (let k = 0; k <= n; k++) {
    s += (fDerivAt(k, x0) / factorial(k)) * Math.pow(dx, k);
  }
  return s;
};

The remainder is drawn as a vertical segment at the current x:

createSegment(board, [
  [() => getX(), () => f(getX())],
  [() => getX(), () => T(getX())],
], {
  name: "Rₙ(x)",
  dash: 2,
  strokeWidth: 4,
  withLabel: true,
}, COLORS.green);

Example 2: g(x)=x5xg(x)=x^5|x|

Link to code.

In this applet we use

g(x)=x5x.g(x)=x^5|x|.

Equivalently,

g(x)=sgn(x)x6,g(x)=\operatorname{sgn}(x)\,x^6,

so it coincides with x6x^6 for x>0x>0 and with x6-x^6 for x<0x<0.

The nn-th Taylor polynomial of a function ff at the expansion point x0x_0 is defined by

const T = (x: number) => {
  const x0 = getX0();
  const n = getN();
  const dx = x - x0;

  let s = 0;
  for (let k = 0; k <= n; k++) {
    const dk = gDerivAt(k, x0); // g^(k)(x0)
    s += (dk / factorial(k)) * Math.pow(dx, k);
  }
  return s;
};

For x0x \neq 0, since

g(x)=sgn(x)x6,g(x) = \operatorname{sgn}(x)\, x^6,

the function is a polynomial on each side of 00.

At x=0x = 0 we have

g(k)(0)=0for k=0,1,2,3,4,5,g^{(k)}(0) = 0 \quad \text{for } k = 0,1,2,3,4,5,

but the sixth derivative does not exist, because the left and right limits differ:

limx0+g(6)(x)=6!=720,limx0g(6)(x)=6!=720.\lim_{x \to 0^+} g^{(6)}(x) = 6! = 720, \qquad \lim_{x \to 0^-} g^{(6)}(x) = -6! = -720.

Therefore, gg is five times differentiable at 00, but not six times differentiable at 00.

In the applet, this situation is handled by declaring the Taylor polynomial undefined when x0x_0 is sufficiently close to 00 and n6n \ge 6:

const EPS = 0.05;
const taylorIsDefined = () =>
  !(Math.abs(getX0()) < EPS && getN() >= 6);

The Taylor graph and the remainder segment are hidden whenever this condition fails:

const updateVisibility = () => {
  const v = taylorIsDefined();
  tGraph.setAttribute({ visible: v });
  rSeg.setAttribute({ visible: v });
};

board.on("update", updateVisibility);
updateVisibility();

To observe the failure, drag the blue point to x00x_0 \approx 0 and set the slider to n=6n = 6. The Taylor polynomial disappears because gg is not six times differentiable at 00.