Calculus

Taylor Series

Express any smooth function as a polynomial of derivatives

A Taylor series writes a smooth function as an infinite polynomial built from its derivatives at one point. f(x) = f(a) + f'(a)(x−a) + f''(a)/2 · (x−a)² + ... It's how computers compute sin, cos, e^x, and how physicists derive small-angle approximations. Truncate after a few terms and you get a polynomial that approximates the function near the chosen point — the basis of every linearization in science.

  • Taylor series of f around a∑_{n=0}^∞ f^(n)(a)/n! · (x−a)^n
  • Maclaurin seriesTaylor series with a = 0
  • Common Maclaurine^x, sin, cos, ln(1+x), 1/(1−x)
  • ConvergenceWithin radius of convergence (depends on f)
  • Used inNumerical computation, physics approximations, machine learning
  • YearBrook Taylor, 1715 (general theorem); known special cases earlier

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

The Taylor series formula

For a function f infinitely differentiable at a point a, the Taylor series of f around a is:

f(x) = f(a) + f'(a)(x − a) + f''(a)/2! · (x − a)² + f'''(a)/3! · (x − a)³ + ...

     = ∑_{n=0}^∞ (f^(n)(a) / n!) · (x − a)^n

Each term — the n-th derivative at a, divided by n factorial, multiplied by (x − a)^n. Together they form a polynomial that matches f and all its derivatives at a.

The Maclaurin series is the special case a = 0 — Taylor expansion around the origin.

Famous Maclaurin series

FunctionSeriesRadius of convergence
e^x1 + x + x²/2! + x³/3! + ...∞ (everywhere)
sin(x)x − x³/3! + x⁵/5! − x⁷/7! + ...∞ (everywhere)
cos(x)1 − x²/2! + x⁴/4! − x⁶/6! + ...∞ (everywhere)
ln(1 + x)x − x²/2 + x³/3 − x⁴/4 + ...1 (|x| < 1)
1/(1 − x)1 + x + x² + x³ + ... (geometric series)1
arctan(x)x − x³/3 + x⁵/5 − x⁷/7 + ...1
(1 + x)^p1 + px + p(p−1)/2! · x² + ... (binomial series)1 (general p), full real line for p ∈ ℕ

Memorize the first three. They're the building blocks of nearly every applied calculation, and Euler's formula e^(ix) = cos(x) + i sin(x) is the visible algebraic relationship between them.

Worked examples

Example 1 — derive the Maclaurin series for e^x

Compute derivatives at 0 — f(x) = e^x, f'(x) = e^x, f''(x) = e^x, ... — every derivative is e^x. So f^(n)(0) = e⁰ = 1 for all n.

e^x = ∑_{n=0}^∞ 1/n! · x^n
   = 1 + x + x²/2! + x³/3! + x⁴/4! + ...

Plug in x = 1 — e = 1 + 1 + 1/2 + 1/6 + 1/24 + ... ≈ 2.71828. The series converges to e.

Example 2 — compute sin(0.1) using Taylor series

sin(0.1) ≈ 0.1 − 0.1³/6 + 0.1⁵/120 − ...
        ≈ 0.1 − 0.000166667 + 0.00000008333 − ...
        ≈ 0.099833

The actual value is 0.099833417... — already accurate to 6 decimal places after just three terms because higher terms vanish quickly for small x. This is why small-angle approximations work — for |x| ≪ 1, terms beyond the first are negligible.

Example 3 — small-angle approximations in physics

Pendulum motion — d²θ/dt² = −(g/L) sin(θ). For small θ, sin(θ) ≈ θ (first Taylor term):

d²θ/dt² ≈ −(g/L) θ

This is the simple harmonic oscillator — solvable exactly with sin and cos. The exact equation has no closed-form solution. The approximation works because for swing angles < ~10°, neglecting θ³/6 introduces error < 1%.

Taylor series vs minimax polynomials in computing

Computers compute sin, cos, e^x using polynomial approximations — but not exactly Taylor. Why?

Taylor polynomial (degree n)Minimax polynomial (Remez algorithm)
Optimizes forAccuracy near expansion pointUniform accuracy across an interval
Error structureTiny near a, growing with |x − a|Roughly equal across the interval
Use caseTheory, approximations near a pointLibrary implementations of math functions
Coefficient computationTrivial — derivatives at aNumerical optimization (Remez)

Math libraries (libm, glibc, Intel MKL) use minimax polynomials with hand-tuned coefficients. The first 5-10 terms of e^x's Maclaurin series gives ~6 digits accuracy near 0; minimax polynomial of similar degree gives 6 digits accuracy across an entire interval. For library purposes, uniform accuracy is the priority.

JavaScript — Taylor series in practice

// Compute exp(x) via Maclaurin series
function expTaylor(x, terms = 20) {
  let sum = 0;
  let term = 1;  // x^0 / 0! = 1
  for (let n = 0; n < terms; n++) {
    sum += term;
    term *= x / (n + 1);  // efficient: avoid recomputing factorials
  }
  return sum;
}

console.log(expTaylor(1));        // ≈ 2.71828 (e)
console.log(expTaylor(2));        // ≈ 7.389 (e²)
console.log(expTaylor(-3, 50));  // ≈ 0.0498 (e⁻³)

// sin via Maclaurin
function sinTaylor(x, terms = 20) {
  // Reduce x to [-π, π] for accuracy with finite terms
  x = x % (2 * Math.PI);
  if (x > Math.PI) x -= 2 * Math.PI;
  let sum = 0, term = x;
  for (let n = 0; n < terms; n++) {
    sum += term;
    term *= -x*x / ((2*n + 2) * (2*n + 3));
  }
  return sum;
}

// Verify against built-in
console.log(sinTaylor(Math.PI / 4));  // ≈ 0.7071 (= √2/2)
console.log(Math.sin(Math.PI / 4));   // 0.7071...

// Truncation error decreases with each term added
function truncationError(f, taylorN, x) {
  return Math.abs(f(x) - taylorN(x));
}

Where Taylor series appear

  • Numerical computation of transcendental functions. sin, cos, exp, log, arctan — all computed via polynomial approximations derived from Taylor.
  • Linearization in physics. Small-angle pendulum, small-amplitude oscillations, weak-field general relativity, perturbation theory — all keep Taylor's first one or two terms and discard the rest.
  • Numerical methods. Newton's method for root-finding uses linear Taylor approximation. Runge-Kutta methods for differential equations use higher-order Taylor terms. Finite-difference methods come from Taylor.
  • Probability and statistics. Approximating moments, deriving asymptotic distributions, central-limit-theorem-style arguments.
  • Computer graphics — shading and lighting. Polynomial approximations of physically-based reflectance functions for real-time rendering.
  • Machine learning — automatic differentiation. Taylor expansions of loss functions in gradient descent, second-order methods (Newton, Gauss-Newton), and natural gradients.

Common mistakes

  • Forgetting the n! denominator. Each term has 1/n! — easy to drop. The factorial is what makes the series converge for entire functions.
  • Using a Taylor series outside its radius of convergence. For 1/(1−x), the series converges only for |x| < 1. At x = 0.99, you can use it; at x = 1.5, the series diverges and gives nonsense.
  • Confusing power series with Taylor series. Every Taylor series is a power series, but not vice versa — power series can come from other sources (e.g., generating functions in combinatorics).
  • Confusing convergent series with converging-to-the-function. Counter-example — f(x) = e^(−1/x²) for x ≠ 0 and f(0) = 0 is C^∞ at 0 with all derivatives = 0, so its Taylor series at 0 is identically 0 — not equal to f for any x ≠ 0. Smooth ≠ analytic. For most "nice" functions, Taylor series do converge to f within their radius.
  • Truncating without bounding the error. If you truncate at degree n, the Lagrange remainder bounds your error using f^(n+1)(c) — for some c. Knowing this bound is what makes truncated Taylor approximations safe.
  • Computing factorials directly for large n. 100! overflows even 64-bit integers. Use the recurrence — coefficient_{n+1} = coefficient_n × x/(n+1) — to avoid factorials altogether.

Frequently asked questions

How does a Taylor series approximate a function?

Each term contributes a higher-order correction. The 0th term is f(a) — the function value at the expansion point. The 1st-order term is f'(a)(x−a) — linear approximation. The 2nd-order is f''(a)/2 · (x−a)² — accounts for curvature. Higher terms refine further. Near a, low-order terms dominate; far from a, you may need many or infinitely many terms.

What's the difference between Taylor and Maclaurin?

Maclaurin series is just Taylor series at a = 0. Special case, special name. Most "famous" series — for e^x, sin, cos, ln(1+x), arctan, etc. — are Maclaurin series. Taylor series at general a are essentially the same with a translation of variables.

When does a Taylor series converge?

Within the radius of convergence — a number R such that the series converges for |x − a| &lt; R. For e^x, sin, cos, the radius is infinite — converge everywhere. For 1/(1−x) at a = 0, radius is 1 — diverges for |x| ≥ 1. For ln(1+x) at a = 0, radius is 1. Outside the radius, the series diverges (sum is ∞).

What's the small-angle approximation?

For small θ — sin(θ) ≈ θ, cos(θ) ≈ 1 − θ²/2, tan(θ) ≈ θ. These are the first few terms of the Taylor series at 0. Used pervasively in physics (pendulums, optics, mechanics) when angles are small enough that higher-order terms are negligible. The simple harmonic oscillator equation dθ²/dt² = −g/L · sin(θ) becomes the linear dθ²/dt² = −g/L · θ via small-angle approximation.

How do computers compute sin(x), cos(x), e^x?

Argument reduction (use periodicity to bring x into a small range), then evaluate a truncated Taylor (or related) polynomial. Modern math libraries use minimax polynomial approximations (slightly different from Taylor — optimized for uniform error rather than near-zero accuracy) but the principle is the same. Hardware FPU uses CORDIC and similar algorithms; libm uses polynomials.

What's a Taylor remainder?

When you truncate a Taylor series, the remainder is the error from omitted terms. The Lagrange form of the remainder — R_n(x) = f^(n+1)(c)/(n+1)! · (x−a)^(n+1) for some c between a and x. Bounds the truncation error using the (n+1)-th derivative. Used to prove Taylor approximations are accurate enough for some application.

When does Taylor series fail?

When the function isn't smooth enough (not infinitely differentiable). When the series doesn't converge (outside the radius of convergence). When the series converges but to a different function (rare — happens for f(x) = e^(−1/x²), whose Taylor series at 0 is identically zero but f isn't). For analytic functions (which include most "nice" functions), the series converges to f within its radius.