12. The multivariable chain rule
§2.4's chain rule handled one function feeding into another, \frac{dy}{dx}=\frac{dy}{du}\cdot\frac{du}{dx}. When z=f(x,y) and both x and y themselves depend on some other variable, there are now two paths a change can travel through — and the chain rule needs to add up both of them. This lesson builds that rule, and shows it silently contains both §6.0's parametric-curve derivative and §2.9's implicit differentiation as special cases.
The single-parameter case
If z=f(x,y) with x=x(t) and y=y(t), then z ultimately depends on t alone, through two separate routes — one through x, one through y:
\frac{dz}{dt}=\frac{\partial z}{\partial x}\cdot\frac{dx}{dt}+\frac{\partial z}{\partial y}\cdot\frac{dy}{dt}
Each term is an ordinary chain-rule product, and the two get added, because a small change in t pushes z through both channels simultaneously — a change in x contributes its share, a change in y contributes its own, independently, and the total effect is their sum. This "multiply along each path, then add every path" structure is the defining feature of the multivariable chain rule, and it generalizes to any number of intermediate variables the same way.
This formula is exactly §9.4's tangent-vector construction, generalized from a curve \vec r(t) living directly in space to a curve traced on a surface z=f(x,y): parametrize a path (x(t),y(t)) in the domain, and \frac{dz}{dt} tracks how the height changes while walking that path.
The two-parameter case
If z=f(x,y) with x=x(s,t) and y=y(s,t) (both intermediate variables now depend on two new variables), the chain rule applies once per new variable, holding the other fixed — exactly the "one variable at a time" spirit of partial derivatives themselves (§10.2):
\frac{\partial z}{\partial s}=\frac{\partial z}{\partial x}\cdot\frac{\partial x}{\partial s}+\frac{\partial z}{\partial y}\cdot\frac{\partial y}{\partial s}
\frac{\partial z}{\partial t}=\frac{\partial z}{\partial x}\cdot\frac{\partial x}{\partial t}+\frac{\partial z}{\partial y}\cdot\frac{\partial y}{\partial t}
Same structure as the single-parameter case, applied separately for each new variable — this is exactly how §11's change-of-variables integrals (polar coordinates and beyond) will connect derivatives across coordinate systems.
Implicit differentiation, recovered as a special case
§2.9 found \frac{dy}{dx} for curves defined implicitly by F(x,y)=0, using ad hoc algebraic manipulation. The multivariable chain rule derives the same result systematically: treat y as a function of x along the curve (so F(x,y(x))=0 for every x on the curve), and differentiate both sides with respect to x using the chain rule, noting \frac{dx}{dx}=1:
\frac{dF}{dx}=F_x\cdot1+F_y\cdot\frac{dy}{dx}=0\ \Longrightarrow\ \frac{dy}{dx}=-\frac{F_x}{F_y}
This single formula replaces every step-by-step implicit-differentiation derivation from §2.9 — no more differentiating term-by-term and collecting \frac{dy}{dx} afterward; just compute two partial derivatives and divide.
Doing it in Python
The single-parameter chain rule, applied to a curve traced on a surface — and confirmed against direct substitution:
import sympy as sp
t, x, y = sp.symbols('t x y')
z = x**2 * y
x_t, y_t = sp.cos(t), sp.sin(t)
f_x = sp.diff(z, x)
f_y = sp.diff(z, y)
dx_dt = sp.diff(x_t, t)
dy_dt = sp.diff(y_t, t)
dz_dt_chain = sp.simplify(f_x.subs({x: x_t, y: y_t}) * dx_dt + f_y.subs({x: x_t, y: y_t}) * dy_dt)
print(f"chain rule: dz/dt = {dz_dt_chain}")
z_direct = z.subs({x: x_t, y: y_t})
dz_dt_direct = sp.simplify(sp.diff(z_direct, t))
print(f"direct: dz/dt = {dz_dt_direct}")
print(f"match: {sp.simplify(dz_dt_chain - dz_dt_direct) == 0}")
Implicit differentiation, rebuilt from the multivariable chain rule instead of §2.9's term-by-term approach:
import sympy as sp
x, y = sp.symbols('x y')
F = x**2 + y**2 - 25 # the circle x^2+y^2=25
F_x = sp.diff(F, x)
F_y = sp.diff(F, y)
dy_dx = -F_x / F_y
print(f"F_x = {F_x}, F_y = {F_y}")
print(f"dy/dx = -F_x/F_y = {dy_dx}")
The two-parameter chain rule, computing \frac{\partial z}{\partial s} directly and confirming it against substitution:
import sympy as sp
s, t, x, y = sp.symbols('s t x y')
z = x*y + x**2
x_st = s + t
y_st = s - t
f_x = sp.diff(z, x)
f_y = sp.diff(z, y)
dx_ds = sp.diff(x_st, s)
dy_ds = sp.diff(y_st, s)
dz_ds_chain = sp.simplify(f_x.subs({x: x_st, y: y_st}) * dx_ds + f_y.subs({x: x_st, y: y_st}) * dy_ds)
z_direct = z.subs({x: x_st, y: y_st})
dz_ds_direct = sp.simplify(sp.diff(z_direct, s))
print(f"chain rule: dz/ds = {dz_ds_chain}")
print(f"direct: dz/ds = {dz_ds_direct}")
Worked example
For z=x^2y with x=\cos t, y=\sin t, find \dfrac{dz}{dt} at t=\dfrac\pi4 using the chain rule.
\frac{\partial z}{\partial x}=2xy,\qquad\frac{\partial z}{\partial y}=x^2
\frac{dx}{dt}=-\sin t,\qquad\frac{dy}{dt}=\cos t
\frac{dz}{dt}=(2xy)(-\sin t)+(x^2)(\cos t)
Substitute x=\cos t, y=\sin t:
\frac{dz}{dt}=2\cos t\sin t(-\sin t)+\cos^2t\cos t=-2\sin^2t\cos t+\cos^3t
At t=\dfrac\pi4: \sin\dfrac\pi4=\cos\dfrac\pi4=\dfrac{\sqrt2}2, so \sin^2\dfrac\pi4=\dfrac12:
\frac{dz}{dt}\bigg|_{t=\pi/4}=-2\left(\frac12\right)\left(\frac{\sqrt2}2\right)+\left(\frac{\sqrt2}2\right)^3=-\frac{\sqrt2}2+\frac{2\sqrt2}8=-\frac{\sqrt2}2+\frac{\sqrt2}4
=\boxed{-\frac{\sqrt2}4}
Sanity check. Direct substitution: z(t)=\cos^2t\sin t, and differentiating this ordinary single-variable function directly (product and chain rule) should give the identical result — which the "Doing it in Python" section already confirmed symbolically for the general case, a strong structural guarantee that the chain-rule route and the substitute- first route can never disagree. At t=\frac\pi4, z is momentarily decreasing (\frac{dz}{dt}<0), consistent with the sign of -\frac{\sqrt2}4. ✓
Your turn
1. For z=x^2+y^2 with x=e^t, y=e^{-t}, find \dfrac{dz}{dt} using the chain rule.
2. Use the implicit-differentiation shortcut \dfrac{dy}{dx}=-\dfrac{F_x}{F_y} to find \dfrac{dy}{dx} for the curve x^3+y^3=6xy (the folium of Descartes — compare to how §2.9 would have derived this term by term).
3. True or false: the multivariable chain rule requires x(t) and y(t) to be independent of each other.
Solutions
1. \dfrac{\partial z}{\partial x}=2x, $\dfrac{\partial z}{\partial y}=2y$, \dfrac{dx}{dt}=e^t, \dfrac{dy}{dt}=-e^{-t}.
\frac{dz}{dt}=2x\cdot e^t+2y\cdot(-e^{-t})=2e^t\cdot e^t-2e^{-t}\cdot e^{-t}=2e^{2t}-2e^{-2t}
\boxed{\frac{dz}{dt}=2e^{2t}-2e^{-2t}}
2. F(x,y)=x^3+y^3-6xy. F_x=3x^2-6y, F_y=3y^2-6x.
\frac{dy}{dx}=-\frac{3x^2-6y}{3y^2-6x}=\boxed{\frac{2y-x^2}{y^2-2x}}
— found in two lines, versus differentiating x^3+y^3=6xy term by term (product rule on the right side) and algebraically isolating \frac{dy}{dx} by hand, §2.9's original, more error-prone route to the same answer.
3. False. The formula works precisely because x(t) and y(t) can be (and usually are) related to each other only through their shared dependence on t — that's the entire point of parametrizing a path in the (x,y)-domain. Nothing requires x and y to be "independent" in any statistical sense; the chain rule's two terms simply account for however each one separately happens to move as t changes, whatever that relationship is.
Check yourself in code
For z=x^2y with x=\cos t, y=\sin t, compute \dfrac{dz}{dt} using the chain rule and evaluate it at t=\dfrac\pi4.
Print exactly this:
dz/dt = -2*sin(t)**2*cos(t) + cos(t)**3
at t=pi/4: -sqrt(2)/4
import sympy as sp
t, x, y = sp.symbols('t x y')
z = x**2 * y
x_t, y_t = sp.cos(t), sp.sin(t)
f_x = sp.diff(z, x)
f_y = sp.diff(z, y)
dx_dt = sp.diff(x_t, t)
dy_dt = sp.diff(y_t, t)
dz_dt = sp.expand(f_x.subs({x: x_t, y: y_t}) * dx_dt + f_y.subs({x: x_t, y: y_t}) * dy_dt)
print("dz/dt = ...")
print("at t=pi/4: ...")
import sympy as sp
t, x, y = sp.symbols('t x y')
z = x**2 * y
x_t, y_t = sp.cos(t), sp.sin(t)
f_x = sp.diff(z, x)
f_y = sp.diff(z, y)
dx_dt = sp.diff(x_t, t)
dy_dt = sp.diff(y_t, t)
dz_dt = sp.expand(f_x.subs({x: x_t, y: y_t}) * dx_dt + f_y.subs({x: x_t, y: y_t}) * dy_dt)
print(f"dz/dt = {dz_dt}")
print(f"at t=pi/4: {sp.simplify(dz_dt.subs(t, sp.pi/4))}")
The multivariable chain rule adds up one ordinary chain-rule product per intermediate variable — \frac{dz}{dt}=z_x\frac{dx}{dt}+z_y\frac{dy}{dt} when x,y both depend on a single t, or the analogous partial-derivative version when they depend on several new variables at once. Two earlier results fall out of it directly: §6.0's parametric derivative is this formula applied to a curve, and §2.9's implicit differentiation collapses to the single formula \frac{dy}{dx}=-\frac{F_x}{F_y}, replacing an entire term-by-term derivation with two partial derivatives and a division.
Next: generalizing the slope idea one more time — not just along the two coordinate directions, but along any direction at all, culminating in the gradient vector.