Partial Derivatives
A partial derivative measures how a function of several variables changes when you move one variable and freeze all the others. It is an ordinary one-variable derivative taken along a coordinate direction. This lesson defines partial derivatives as limits, interprets them as slopes of traces, covers higher-order and mixed partials with Clairaut's theorem (and a function where it fails), and meets the partial differential equations that govern heat, waves and potentials.
For a gentler first pass, see Partial Derivatives in the survey course.
Definition and notation
For , the partial derivatives at are
when the limits exist. As functions, and are written in several equivalent ways:
| Leibniz | subscript | operator |
|---|---|---|
| , | , | |
| , | , | |
Note the order: means "first , then ", and in Leibniz form the variable written closest to is the first one used.
Rule for computing: to find , treat as a constant and differentiate with respect to using the one-variable rules.
Example: .
Geometric meaning
Fixing slices the surface with the vertical plane . The slice is the curve , and is the slope of its tangent line at . Likewise is the slope of the trace in the plane . The two tangent lines span the tangent plane when is differentiable.
is also a rate of change: if is temperature in °C and is in metres, then is in °C per metre in the east-west direction.
Implicit partial differentiation
When is defined implicitly by an equation such as , differentiate both sides with respect to , treating as constant and as a function of :
Higher derivatives and Clairaut's theorem
Differentiating again gives four second partials , , , . For almost every function you meet, the two mixed ones agree.
Clairaut's theorem. If and are both continuous on a disk around , then .
Proof sketch. Look at the "second difference" . Applying the Mean Value Theorem twice in one order shows for some point in the square of side ; doing it in the other order gives for another point. Divide by and let ; continuity makes both sides tend to their values at .
The hypothesis matters. The classic counterexample is
import sympy as sp
x, y, h = sp.symbols("x y h", real=True)
f = x * y * (x**2 - y**2) / (x**2 + y**2)
fx = sp.simplify(sp.diff(f, x)) # valid away from the origin
fy = sp.simplify(sp.diff(f, y))
# At the origin, f(h,0) = f(0,h) = 0, so f_x(0,0) = f_y(0,0) = 0.
# Mixed partials at the origin from the definition:
fxy0 = sp.limit((fx.subs({x: 0, y: h}) - 0) / h, h, 0) # d/dy of f_x
fyx0 = sp.limit((fy.subs({x: h, y: 0}) - 0) / h, h, 0) # d/dx of f_y
print("f_xy(0,0) =", fxy0)
print("f_yx(0,0) =", fyx0)
print("away from 0, f_xy - f_yx =", sp.simplify(sp.diff(fx, y) - sp.diff(fy, x)))f_xy(0,0) = -1
f_yx(0,0) = 1
away from 0, f_xy - f_yx = 0
Away from the origin the mixed partials agree (Clairaut applies there); at the origin they are and 1, possible only because is not continuous at .
Partial differential equations
Equations that relate partial derivatives describe physical fields:
| PDE | name | describes |
|---|---|---|
| Laplace | steady temperature, electrostatic potential | |
| heat (diffusion) | temperature spreading along a rod | |
| wave | vibrating strings, sound |
Solutions of Laplace's equation are called harmonic. Checking a candidate is pure partial differentiation:
import sympy as sp
x, y, t, c, k = sp.symbols("x y t c k", positive=True)
candidates = {
"e^x sin y (Laplace)": (sp.exp(x) * sp.sin(y), lambda u: sp.diff(u, x, 2) + sp.diff(u, y, 2)),
"ln(x^2+y^2) (Laplace)": (sp.log(x**2 + y**2), lambda u: sp.diff(u, x, 2) + sp.diff(u, y, 2)),
"x^2 - y^2 + xy (Laplace)": (x**2 - y**2 + x * y, lambda u: sp.diff(u, x, 2) + sp.diff(u, y, 2)),
"e^(-k t) sin x (heat)": (sp.exp(-k * t) * sp.sin(x), lambda u: sp.diff(u, t) - k * sp.diff(u, x, 2)),
"sin(x - c t) (wave)": (sp.sin(x - c * t), lambda u: sp.diff(u, t, 2) - c**2 * sp.diff(u, x, 2)),
"x^3 (Laplace)": (x**3, lambda u: sp.diff(u, x, 2) + sp.diff(u, y, 2)),
}
for name, (u, residual) in candidates.items():
print(f"{name:26s} residual = {sp.simplify(residual(u))}")e^x sin y (Laplace) residual = 0
ln(x^2+y^2) (Laplace) residual = 0
x^2 - y^2 + xy (Laplace) residual = 0
e^(-k t) sin x (heat) residual = 0
sin(x - c t) (wave) residual = 0
x^3 (Laplace) residual = 6*x
In software
- Gradients of losses. Training a model needs for every weight : a partial derivative, because all other weights are held fixed. The vector of them is the gradient (see Directional Derivatives and the Gradient Vector).
- Finite differences and gradient checking. is how numerical code estimates a partial derivative, and how autodiff implementations are tested: compare the analytic gradient with central differences for a few random coordinates.
- Simulation. Heat, fluid and wave solvers replace by on a grid; the Laplacian stencil also appears in image processing as an edge detector.
import math
f = lambda x, y: x**3 * y**2 - 4 * x * math.sin(y) + math.exp(2 * x - y)
fx = lambda x, y: 3 * x**2 * y**2 - 4 * math.sin(y) + 2 * math.exp(2 * x - y)
a, b = 0.5, 1.2
for h in [1e-1, 1e-3, 1e-5, 1e-9]:
central = (f(a + h, b) - f(a - h, b)) / (2 * h)
print(f"h={h:.0e} estimate {central:.10f} error {abs(central - fx(a, b)):.2e}")h=1e-01 estimate -0.9853565740 error 2.53e-02
h=1e-03 estimate -1.0106923061 error 2.53e-06
h=1e-05 estimate -1.0106948375 error 2.52e-10
h=1e-09 estimate -1.0106948611 error 2.34e-08
The error shrinks like until rounding takes over: at the subtraction of nearly equal numbers loses digits, which is why gradient checkers use around to in double precision.
Exercises
Exercise 1: Compute partials
Find and for .
Answer
, .
Solution
Exercise 2: Mixed partials
For , compute and and confirm they agree.
Answer
.
Solution
Both mixed partials are continuous everywhere, so Clairaut guarantees equality.
Exercise 3: Implicit
Check that satisfies , which defines as a function of near that point, then find there.
Answer
The point satisfies . .
Solution
Exercise 4: Harmonic or not (code)
Use SymPy to check which of , and is harmonic.
Answer
and are harmonic; is not ().
Solution
import sympy as sp
x, y = sp.symbols("x y")
for u in [x**3 - 3*x*y**2, x**3 + y**3, sp.exp(-y) * sp.cos(x)]:
print(u, "->", sp.simplify(sp.diff(u, x, 2) + sp.diff(u, y, 2)))x**3 - 3*x*y**2 -> 0
x**3 + y**3 -> 6*x + 6*y
exp(-y)*cos(x) -> 0
Test yourself
To compute for , you…
- differentiate in , then in
- treat as a constant and differentiate with respect to
- set and differentiate
- average the slopes in and
Clairaut's theorem guarantees at a point when…
- is continuous there
- and exist there
- and are continuous near the point
- is a polynomial in only
Which function satisfies Laplace's equation ?