Why This Matters
In single-variable calculus you learned how to find the rate of change of a function that depends on one input. But the real world rarely has just one knob to turn. A multivariable function such as the temperature across a metal plate depends on both the x-coordinate and the y-coordinate. To understand how temperature changes as you move east, you hold the y-coordinate fixed and differentiate with respect to x alone. That is a partial derivative.
Partial derivatives are the foundation of all multivariable calculus. They appear in gradient descent (the algorithm that trains every modern neural network), in physics (heat equation, wave equation, Maxwell equations), and in economics (marginal cost when you change one factor while holding others constant). Mastering partial notation and the mechanical skill of computing partials unlocks every topic that follows in this domain.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
A partial derivative holds all variables fixed except one, then differentiates with respect to that one variable.
Code Example
// Partial derivatives: approximate numerically
// f(x, y) = x^2 * y + 3*y
function f(x, y) {
return x * x * y + 3 * y;
}
// Partial derivative w.r.t. x at (x, y)
function partialX(fn, x, y, h = 1e-6) {
return (fn(x + h, y) - fn(x - h, y)) / (2 * h);
}
// Partial derivative w.r.t. y at (x, y)
function partialY(fn, x, y, h = 1e-6) {
return (fn(x, y + h) - fn(x, y - h)) / (2 * h);
}
// Evaluate at (2, 5)
console.log("f(2,5):", f(2, 5)); // 35
console.log("df/dx at (2,5):", partialX(f, 2, 5).toFixed(4)); // ~20 (exact: 2*2*5 = 20)
console.log("df/dy at (2,5):", partialY(f, 2, 5).toFixed(4)); // ~7 (exact: 4 + 3 = 7)
// Tangent plane approximation near (2, 5)
function tangentPlane(x, y) {
const a = 2, b = 5;
const fAB = f(a, b);
const fx = partialX(f, a, b);
const fy = partialY(f, a, b);
return fAB + fx * (x - a) + fy * (y - b);
}
console.log("Tangent approx f(2.1, 5.1):", tangentPlane(2.1, 5.1).toFixed(4));
console.log("Actual f(2.1, 5.1):", f(2.1, 5.1).toFixed(4));Interactive Experiment
Try these exercises:
- Compute the partial derivatives of f(x, y) = sin(x) * cos(y) at (0, 0) both analytically and numerically. Do they match?
- Change the step size h from 1e-6 to 0.1 and then to 1e-10. How does the numerical approximation change? Why is very small h not always better?
- Try a function of three variables: f(x, y, z) = xyz. How many partial derivatives does it have?
- Compare the tangent-plane approximation to the actual value as you move further from the base point. When does the approximation break down?
- Compute the second partial derivative d2f/dxdy and d2f/dydx for f(x, y) = x^2 * y + 3y. Are they equal? (Clairaut theorem says they should be.)
Quick Quiz
Coding Challenge
Write a function called `approxPartials` that takes x and y as inputs and returns the numerical partial derivatives df/dx and df/dy of the function f(x, y) = x^2 * y + sin(x * y) at the given point. Use central differences with h = 1e-5. Return the two values as a comma-separated string rounded to 4 decimal places: `df/dx,df/dy`.
Real-World Usage
Partial derivatives are everywhere in science and engineering:
- Machine learning: Gradient descent computes the partial derivative of the loss function with respect to every model weight, then nudges each weight in the direction that reduces loss.
- Physics: The heat equation, wave equation, and Navier-Stokes equations are all partial differential equations expressing how quantities change with respect to space and time.
- Economics: Marginal cost and marginal revenue are partial derivatives of cost and revenue functions with respect to quantity, holding other factors fixed.
- Computer graphics: Surface normals, which determine how light bounces off objects, are computed from partial derivatives of the surface parametrization.
- Optimization: Finding the minimum of a function of many variables requires setting all partial derivatives to zero and solving the resulting system of equations.