calculus30 min

The Derivative Definition

The derivative as the limit of the difference quotient, instantaneous rate of change, and the tangent line

0/9Not Started

Why This Matters

The derivative answers one of the most fundamental questions in science: how fast is something changing right now? Not on average over an hour or a second, but at this exact instant. The speedometer in a car, the slope of a hill at your feet, the rate at which a population grows at midnight -- all of these are derivatives.

Formally, the derivative is the instantaneous rate of change of a function, defined as the limit of the difference quotient. You take two points on a curve, compute the slope of the line between them (the secant line), and then let those points slide together until you have the slope at a single point. That limiting slope is the derivative.

Geometrically, the derivative at a point gives the slope of the tangent line -- the line that just touches the curve at that point without crossing it (locally). The tangent line is the best linear approximation to the function near that point, and this idea of local linear approximation is what makes calculus so powerful for physics, engineering, economics, and machine learning.

Define Terms

Visual Model

Secant LineSlope between two points
Difference Quotient(f(a+h) - f(a)) / h
Limit h -> 0Let the gap shrink to zero
Tangent LineSlope at a single point
Derivative f prime(a)Instantaneous rate of change
VelocityDerivative of position
Slope Functionf prime(x) for all x

The full process at a glance. Click Start tour to walk through each step.

The derivative is the limit of the difference quotient: the secant line becomes the tangent line as h approaches 0.

Code Example

Code
// Approximate the derivative using the difference quotient
function numericalDerivative(f, x, h = 0.00001) {
  return (f(x + h) - f(x - h)) / (2 * h);  // Central difference
}

// Test with f(x) = x^2, derivative should be 2x
const f = (x) => x * x;
console.log("f(x) = x^2");
console.log("f prime(3) approx:", numericalDerivative(f, 3).toFixed(6));  // 6
console.log("f prime(3) exact: 6");

// Test with f(x) = x^3, derivative should be 3x^2
const g = (x) => x * x * x;
console.log("\ng(x) = x^3");
console.log("g prime(2) approx:", numericalDerivative(g, 2).toFixed(6));  // 12
console.log("g prime(2) exact: 12");

// Show how the difference quotient converges
function showConvergence(f, a, exactDerivative) {
  console.log(`\nConvergence at x = ${a} (exact = ${exactDerivative}):`);
  let h = 1;
  for (let i = 0; i < 8; i++) {
    const approx = (f(a + h) - f(a)) / h;
    const error = Math.abs(approx - exactDerivative);
    console.log(`h = ${h.toExponential(0)}: approx = ${approx.toFixed(8)}, error = ${error.toExponential(2)}`);
    h /= 10;
  }
}

showConvergence(x => x * x, 3, 6);

// Tangent line: y = f(a) + f prime(a) * (x - a)
function tangentLine(f, a) {
  const slope = numericalDerivative(f, a);
  const yIntercept = f(a) - slope * a;
  console.log(`\nTangent to x^2 at x=${a}: y = ${slope.toFixed(2)}x + ${yIntercept.toFixed(2)}`);
}
tangentLine(x => x * x, 3);  // y = 6x - 9

Interactive Experiment

Try these exercises:

  • Compare the forward difference (f(x+h) - f(x))/h with the central difference (f(x+h) - f(x-h))/(2h). Which converges faster? Why?
  • Compute the derivative of sin(x) at x = 0 numerically. What value do you get? Compare with cos(0).
  • Plot the tangent line and the original function at the same point. How close is the tangent line to the curve near that point?
  • Find a function where the derivative does not exist at x = 0 (hint: try |x|). What happens to the difference quotient?
  • Compute the derivative of e^x at several points. What do you notice about the relationship between the function and its derivative?

Quick Quiz

Coding Challenge

Approximate Derivative Using the Limit Definition

Write a function called `derivative` that takes a function f and a value x, and returns the approximate derivative using the central difference formula: (f(x + h) - f(x - h)) / (2 * h) with h = 0.00001. Round the result to 4 decimal places.

Loading editor...

Real-World Usage

Derivatives are everywhere in science and engineering:

  • Physics: Velocity is the derivative of position; acceleration is the derivative of velocity. Newton built mechanics on derivatives.
  • Machine learning: Backpropagation computes derivatives (gradients) of the loss function to update neural network weights. Training is gradient descent.
  • Economics: Marginal cost is the derivative of the total cost function. Marginal revenue is the derivative of total revenue.
  • Engineering: Stress analysis, fluid dynamics, and circuit analysis all use derivatives to model rates of change in physical systems.
  • Computer graphics: Surface normals (for lighting calculations) are computed from partial derivatives of surface equations.

Connections