Why This Matters
A Taylor series expresses a function as an infinite polynomial whose coefficients are determined by the function's derivatives at a single point. If you know the value of f, f prime, f double prime, and all higher derivatives at x = a, you can reconstruct the entire function (within the radius of convergence) as a power series centered at a. This is one of the most powerful ideas in all of mathematics: local information (derivatives at one point) encodes global behavior.
When the expansion is centered at x = 0, the result is called a Maclaurin series. The Maclaurin series for e^x is 1 + x + x^2/2! + x^3/3! + ..., and it converges for every real number. The Maclaurin series for sin(x) is x - x^3/3! + x^5/5! - ..., and it too converges everywhere. These formulas are not just theoretical -- they are how computers actually calculate these functions.
A Taylor polynomial is a finite truncation of the Taylor series. The nth-degree Taylor polynomial uses derivatives through order n and provides an approximation that becomes more accurate as n increases (within the interval of convergence). Taylor polynomials are the foundation of numerical analysis, error estimation, and scientific computing.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
Taylor series build an infinite polynomial from derivatives at a single point. Truncating at degree n gives a Taylor polynomial approximation with a quantifiable error bound.
Code Example
// Taylor Series Approximations
function factorial(n) {
let r = 1;
for (let i = 2; i <= n; i++) r *= i;
return r;
}
// Taylor polynomial for e^x centered at 0
function taylorExp(x, degree) {
let sum = 0;
for (let n = 0; n <= degree; n++) {
sum += Math.pow(x, n) / factorial(n);
}
return sum;
}
console.log("=== e^x Taylor polynomials at x = 1 ===");
for (const deg of [1, 3, 5, 10, 15]) {
const approx = taylorExp(1, deg);
const error = Math.abs(approx - Math.E);
console.log(`T_${deg}(1) = ${approx.toFixed(8)}, error = ${error.toExponential(2)}`);
}
// Taylor polynomial for sin(x) centered at 0
function taylorSin(x, degree) {
let sum = 0;
for (let n = 0; n <= degree; n++) {
const k = 2 * n + 1; // only odd terms
if (k > degree) break;
sum += Math.pow(-1, n) * Math.pow(x, k) / factorial(k);
}
return sum;
}
console.log("\n=== sin(x) Taylor polynomials at x = pi/4 ===");
const xVal = Math.PI / 4;
for (const deg of [1, 3, 5, 7, 11]) {
const approx = taylorSin(xVal, deg);
const error = Math.abs(approx - Math.sin(xVal));
console.log(`T_${deg}(pi/4) = ${approx.toFixed(8)}, error = ${error.toExponential(2)}`);
}
// Taylor polynomial for cos(x) centered at 0
function taylorCos(x, degree) {
let sum = 0;
for (let n = 0; n <= degree; n++) {
const k = 2 * n; // only even terms
if (k > degree) break;
sum += Math.pow(-1, n) * Math.pow(x, k) / factorial(k);
}
return sum;
}
console.log("\n=== cos(x) at x = pi/3 ===");
const x2 = Math.PI / 3;
console.log("T_10:", taylorCos(x2, 10).toFixed(8));
console.log("Exact:", Math.cos(x2).toFixed(8));Interactive Experiment
Try these exercises:
- Plot the Taylor polynomials T_1, T_3, T_5, T_9 for sin(x) alongside the actual sin(x) from -2pi to 2pi. Watch how higher-degree polynomials match further from the center.
- Compute T_5 for e^x at x = 0.1 and x = 10. The error at x = 0.1 is tiny, but at x = 10 it is huge. Why?
- Find the smallest degree n such that the Taylor polynomial for e^x at x = 1 has error less than 10^(-10).
- Compare the Maclaurin series for ln(1 + x) at x = 0.5 and x = 0.99. How many terms do you need for 4-digit accuracy in each case?
- Compute the Taylor series for 1/(1-x) centered at a = 2 (not 0). What is the radius of convergence?
Quick Quiz
Coding Challenge
Write a function called `taylorApprox` that takes a string funcName ('exp' or 'sin'), a number x, and a degree n. It should compute the nth-degree Maclaurin (Taylor at 0) polynomial approximation. For exp: sum of x^k/k! for k=0..n. For sin: sum of (-1)^k * x^(2k+1) / (2k+1)! for 2k+1 at most n. Return the approximation rounded to 6 decimal places as a string.
Real-World Usage
Taylor series are used pervasively in computation and engineering:
- CPU math libraries: The sin, cos, exp, and log functions in every programming language are computed using optimized Taylor (or Chebyshev) polynomial approximations in hardware or firmware.
- Physics: Linearization of physical laws uses first-order Taylor approximations. Small-angle approximation (sin(x) is approximately x) is a Taylor truncation.
- Machine learning: Gradient descent is based on first-order Taylor approximation. Second-order methods like Newton method use the quadratic Taylor polynomial.
- Error analysis: The Lagrange remainder formula quantifies approximation error. This is how numerical analysts determine precision requirements.
- Differential equations: Series solution methods assume the solution is a Taylor series and solve for the coefficients recursively.