TExcelTAD
Home › Calculus in Depth › Partial Derivatives

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 f(x,y)f(x, y), the partial derivatives at (a,b)(a, b) are

fx(a,b)=lim⁡h→0f(a+h,b)−f(a,b)hfy(a,b)=lim⁡h→0f(a,b+h)−f(a,b)h\begin{aligned} f_x(a, b) &= \lim_{h \to 0} \frac{f(a + h, b) - f(a, b)}{h} \\[1ex] f_y(a, b) &= \lim_{h \to 0} \frac{f(a, b + h) - f(a, b)}{h} \end{aligned}

when the limits exist. As functions, fxf_x and fyf_y are written in several equivalent ways:

Leibniz subscript operator
∂f∂x\frac{\partial f}{\partial x} fxf_x, f1f_1 D1fD_1 f, DxfD_x f
∂f∂y\frac{\partial f}{\partial y} fyf_y, f2f_2 D2fD_2 f, DyfD_y f
∂2f∂x2\frac{\partial^2 f}{\partial x^2} fxxf_{xx} D11fD_{11} f
∂2f∂y ∂x=∂∂y(∂f∂x)\frac{\partial^2 f}{\partial y\,\partial x} = \frac{\partial}{\partial y}\left(\frac{\partial f}{\partial x}\right) fxyf_{xy} D12fD_{12} f

Note the order: fxyf_{xy} means "first xx, then yy", and in Leibniz form the variable written closest to ff is the first one used.

Rule for computing: to find fxf_x, treat yy as a constant and differentiate with respect to xx using the one-variable rules.

Example: f(x,y)=x3y2−4xsin⁡(y)+e2x−yf(x, y) = x^3y^2 - 4x\sin(y) + e^{2x - y}.

fx=3x2y2−4sin⁡y+2e2x−yfy=2x3y−4xcos⁡y−e2x−y\begin{aligned} f_x &= 3x^2y^2 - 4\sin y + 2e^{2x - y} \\ f_y &= 2x^3y - 4x\cos y - e^{2x - y} \end{aligned}

Geometric meaning

Fixing y=by = b slices the surface z=f(x,y)z = f(x, y) with the vertical plane y=by = b. The slice is the curve z=f(x,b)z = f(x, b), and fx(a,b)f_x(a, b) is the slope of its tangent line at x=ax = a. Likewise fy(a,b)f_y(a, b) is the slope of the trace in the plane x=ax = a. The two tangent lines span the tangent plane when ff is differentiable.

fxf_x is also a rate of change: if T(x,y)T(x, y) is temperature in °C and xx is in metres, then TxT_x is in °C per metre in the east-west direction.

Implicit partial differentiation

When zz is defined implicitly by an equation such as x2+y2+z2+xyz=4x^2 + y^2 + z^2 + xyz = 4, differentiate both sides with respect to xx, treating yy as constant and zz as a function of (x,y)(x, y):

2x+2z∂z∂x+yz+xy∂z∂x=0∂z∂x=−2x+yz2z+xy\begin{aligned} 2x + 2z\frac{\partial z}{\partial x} + yz + xy\frac{\partial z}{\partial x} &= 0 \\ \frac{\partial z}{\partial x} &= -\frac{2x + yz}{2z + xy} \end{aligned}

Higher derivatives and Clairaut's theorem

Differentiating again gives four second partials fxxf_{xx}, fxyf_{xy}, fyxf_{yx}, fyyf_{yy}. For almost every function you meet, the two mixed ones agree.

Clairaut's theorem. If fxyf_{xy} and fyxf_{yx} are both continuous on a disk around (a,b)(a, b), then fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b).

Proof sketch. Look at the "second difference" Δ(h)=f(a+h,b+h)−f(a+h,b)−f(a,b+h)+f(a,b)\Delta(h) = f(a + h, b + h) - f(a + h, b) - f(a, b + h) + f(a, b). Applying the Mean Value Theorem twice in one order shows Δ(h)=h2fxy(α,β)\Delta(h) = h^2 f_{xy}(\alpha, \beta) for some point (α,β)(\alpha, \beta) in the square of side hh; doing it in the other order gives Δ(h)=h2fyx(γ,δ)\Delta(h) = h^2 f_{yx}(\gamma, \delta) for another point. Divide by h2h^2 and let h→0h \to 0; continuity makes both sides tend to their values at (a,b)(a, b).

The hypothesis matters. The classic counterexample is

f(x,y)=xy(x2−y2)x2+y2for (x,y)≠(0,0),f(0,0)=0f(x, y) = \frac{xy(x^2 - y^2)}{x^2 + y^2} \quad \text{for } (x, y) \ne (0, 0), \qquad f(0, 0) = 0
python · try it yourself
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 −1-1 and 1, possible only because fxyf_{xy} is not continuous at (0,0)(0, 0).

Partial differential equations

Equations that relate partial derivatives describe physical fields:

PDE name describes
uxx+uyy=0u_{xx} + u_{yy} = 0 Laplace steady temperature, electrostatic potential
ut=kuxxu_t = k u_{xx} heat (diffusion) temperature spreading along a rod
utt=c2uxxu_{tt} = c^2 u_{xx} wave vibrating strings, sound

Solutions of Laplace's equation are called harmonic. Checking a candidate is pure partial differentiation:

python · try it yourself
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 ∂L/∂wi\partial L/\partial w_i for every weight wiw_i: 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. fx(a,b)≈[f(a+h,b)−f(a−h,b)]/(2h)f_x(a, b) \approx [f(a + h, b) - f(a - h, b)]/(2h) 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 uxxu_{xx} by [u(x+h)−2u(x)+u(x−h)]/h2[u(x + h) - 2u(x) + u(x - h)]/h^2 on a grid; the Laplacian stencil also appears in image processing as an edge detector.
python · try it yourself
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 h2h^2 until rounding takes over: at h=10−9h = 10^{-9} the subtraction of nearly equal numbers loses digits, which is why gradient checkers use hh around 10−510^{-5} to 10−610^{-6} in double precision.

Exercises

Exercise 1: Compute partials

Find fxf_x and fyf_y for f(x,y)=yln⁡(x2+y)f(x, y) = y \ln(x^2 + y).

Answer

fx=2xy/(x2+y)f_x = 2xy/(x^2 + y), fy=ln⁡(x2+y)+y/(x2+y)f_y = \ln(x^2 + y) + y/(x^2 + y).

Solution
fx:y is constant;y⋅2xx2+yfy:product rule;1⋅ln⁡(x2+y)+y⋅1x2+y\begin{aligned} f_x\text{:} &\quad \text{$y$ is constant;} \quad y \cdot \frac{2x}{x^2 + y} \\ f_y\text{:} &\quad \text{product rule;} \quad 1 \cdot \ln(x^2 + y) + y \cdot \frac{1}{x^2 + y} \end{aligned}

Exercise 2: Mixed partials

For f(x,y)=x2e3y+sin⁡(xy)f(x, y) = x^2 e^{3y} + \sin(xy), compute fxyf_{xy} and fyxf_{yx} and confirm they agree.

Answer

fxy=fyx=6xe3y+cos⁡(xy)−xysin⁡(xy)f_{xy} = f_{yx} = 6x e^{3y} + \cos(xy) - xy\sin(xy).

Solution
fx=2xe3y+ycos⁡(xy)fxy=6xe3y+cos⁡(xy)−xysin⁡(xy)fy=3x2e3y+xcos⁡(xy)fyx=6xe3y+cos⁡(xy)−xysin⁡(xy)\begin{aligned} f_x &= 2x e^{3y} + y\cos(xy) \\ f_{xy} &= 6x e^{3y} + \cos(xy) - xy\sin(xy) \\ f_y &= 3x^2 e^{3y} + x\cos(xy) \\ f_{yx} &= 6x e^{3y} + \cos(xy) - xy\sin(xy) \end{aligned}

Both mixed partials are continuous everywhere, so Clairaut guarantees equality.

Exercise 3: Implicit

Check that (1,1,2)(1, 1, 2) satisfies xz+y2z3=10xz + y^2z^3 = 10, which defines zz as a function of (x,y)(x, y) near that point, then find ∂z/∂y\partial z/\partial y there.

Answer

The point satisfies 1⋅2+1⋅8=101 \cdot 2 + 1 \cdot 8 = 10. ∂z/∂y=−16/13≈−1.231\partial z/\partial y = -16/13 \approx -1.231.

Solution
∂∂y:xzy+2yz3+3y2z2zy=0zy=−2yz3x+3y2z2at (1,1,2):−2⋅1⋅81+3⋅1⋅4=−1613\begin{aligned} \frac{\partial}{\partial y}\text{:} &\quad xz_y + 2yz^3 + 3y^2z^2z_y = 0 \\ z_y &= -\frac{2yz^3}{x + 3y^2z^2} \\ \text{at } (1, 1, 2)\text{:} &\quad \frac{-2 \cdot 1 \cdot 8}{1 + 3 \cdot 1 \cdot 4} = -\frac{16}{13} \end{aligned}

Exercise 4: Harmonic or not (code)

Use SymPy to check which of u1=x3−3xy2u_1 = x^3 - 3xy^2, u2=x3+y3u_2 = x^3 + y^3 and u3=e−ycos⁡xu_3 = e^{-y}\cos x is harmonic.

Answer

u1u_1 and u3u_3 are harmonic; u2u_2 is not (uxx+uyy=6x+6yu_{xx} + u_{yy} = 6x + 6y).

Solution
python · try it yourself
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 ∂f/∂y\partial f/\partial y for f(x,y)f(x, y), you…

  1. differentiate in xx, then in yy
  2. treat xx as a constant and differentiate with respect to yy
  3. set y=0y = 0 and differentiate
  4. average the slopes in xx and yy

Clairaut's theorem guarantees fxy=fyxf_{xy} = f_{yx} at a point when…

  1. ff is continuous there
  2. fxf_x and fyf_y exist there
  3. fxyf_{xy} and fyxf_{yx} are continuous near the point
  4. ff is a polynomial in xx only

Which function satisfies Laplace's equation uxx+uyy=0u_{xx} + u_{yy} = 0?

  1. x2+y2x^2 + y^2
  2. x2−y2x^2 - y^2
  3. x3x^3
  4. exeye^x e^y