Unit 3, lesson 17

The Multivariable Chain Rule

How to differentiate a composition of multivariable functions by multiplying Jacobian matrices or summing over the routes of a dependency diagram, with every derivative evaluated at the right point.

  • Theory part 33
  • Practice part 34
  • Derivatives and Approximation

A drone flies through a room where the temperature varies from place to place. As the drone moves, each of its coordinates changes, and each change affects the recorded temperature at its own rate. The chain rule adds these contributions up. In matrix form it says something short and memorable, the derivative of a composition is the product of the derivatives.

Key terms

Composition of multivariable functions

Definition Let U⊆RnU \subseteq \mathbb{R}^n and V⊆RmV \subseteq \mathbb{R}^m be open, let g ⁣:U→Rmg \colon U \to \mathbb{R}^m with g(U)⊆Vg(U) \subseteq V, and let f ⁣:V→Rpf \colon V \to \mathbb{R}^p. The composition f∘g ⁣:U→Rpf \circ g \colon U \to \mathbb{R}^p is

(f∘g)(x)=f(g(x)).(f \circ g)(\mathbf{x}) = f\big(g(\mathbf{x})\big).

The condition g(U)⊆Vg(U) \subseteq V makes sure that every output of gg is an allowed input of ff.

In plain words Feed the inputs into gg, then feed what comes out into ff. The middle variables are the outputs of gg.

Example Let f(x,y)=x2yf(x, y) = x^2 y and let g(t)=⟨cos⁡t,sin⁡t⟩g(t) = \langle \cos t, \sin t \rangle, a point moving around the unit circle. Then

(f∘g)(t)=cos⁡2t sin⁡t.(f \circ g)(t) = \cos^2 t \, \sin t.

At t=π4t = \frac{\pi}{4} the point is (22,22)\left( \frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2} \right) and the value is 24\frac{\sqrt{2}}{4}.

Jacobian multiplication

Definition With UU, VV, ff and gg as above, suppose gg is differentiable at a\mathbf{a} in UU and ff is differentiable at the point g(a)g(\mathbf{a}). Then f∘gf \circ g is differentiable at a\mathbf{a} and

D(f∘g)(a)=Df(g(a)) Dg(a).D(f \circ g)(\mathbf{a}) = Df\big(g(\mathbf{a})\big)\, Dg(\mathbf{a}).

In matrices, the p×np \times n Jacobian of f∘gf \circ g at a\mathbf{a} is the p×mp \times m Jacobian of ff evaluated at g(a)g(\mathbf{a}) times the m×nm \times n Jacobian of gg evaluated at a\mathbf{a}. The hypothesis on ff is differentiability, not mere existence of partial derivatives. For f(x,y)=xyx2+y2f(x, y) = \frac{xy}{x^2 + y^2} with f(0,0)=0f(0, 0) = 0 and g(t)=⟨t,t⟩g(t) = \langle t, t \rangle, both partial derivatives of ff at the origin are 00, so a formal product of partial derivatives would predict (f∘g)′(0)=0(f \circ g)'(0) = 0. Yet f(g(t))=12f(g(t)) = \frac{1}{2} for t≠0t \ne 0 and f(g(0))=0f(g(0)) = 0, so the composition is not even continuous at 00. The rule fails because ff is not differentiable at the origin.

In plain words Each derivative is a matrix, and composing functions corresponds to multiplying those matrices. Evaluate the outer derivative where the inner function lands, not at the original input.

Example Let g(u,v)=⟨uv, u+v⟩g(u, v) = \langle uv, \ u + v \rangle and f(x,y)=⟨x2−y, xy⟩f(x, y) = \langle x^2 - y, \ xy \rangle, both polynomial and so differentiable everywhere. At (u,v)=(1,2)(u, v) = (1, 2) the inner point is g(1,2)=(2,3)g(1, 2) = (2, 3). The two Jacobians are

Jg(1,2)=[vu11](1,2)=[2111]\begin{aligned} Jg(1, 2) &= \begin{bmatrix} v & u \\ 1 & 1 \end{bmatrix}_{(1,2)} \\[0.4em] &= \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} \end{aligned}

and

Jf(2,3)=[2x−1yx](2,3)=[4−132].\begin{aligned} Jf(2, 3) &= \begin{bmatrix} 2x & -1 \\ y & x \end{bmatrix}_{(2,3)} \\[0.4em] &= \begin{bmatrix} 4 & -1 \\ 3 & 2 \end{bmatrix}. \end{aligned}

Their product is

J(f∘g)(1,2)=[4−132][2111]=[7385].\begin{aligned} J(f \circ g)(1, 2) &= \begin{bmatrix} 4 & -1 \\ 3 & 2 \end{bmatrix} \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} \\[0.4em] &= \begin{bmatrix} 7 & 3 \\ 8 & 5 \end{bmatrix}. \end{aligned}

As a check, the composition is ⟨u2v2−u−v, u2v+uv2⟩\langle u^2 v^2 - u - v, \ u^2 v + u v^2 \rangle, whose partial derivatives at (1,2)(1, 2) are 77, 33, 88 and 55.

One independent parameter

Definition Let f ⁣:V→Rf \colon V \to \mathbb{R} with V⊆R2V \subseteq \mathbb{R}^2 open, and let x(t)x(t) and y(t)y(t) be functions on an open interval II with (x(t),y(t))(x(t), y(t)) in VV. If xx and yy are differentiable at tt and ff is differentiable at (x(t),y(t))(x(t), y(t)), then z(t)=f(x(t),y(t))z(t) = f(x(t), y(t)) is differentiable at tt and

dzdt=∂f∂xdxdt+∂f∂ydydt,\frac{dz}{dt} = \frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y} \frac{dy}{dt},

where both partial derivatives are evaluated at (x(t),y(t))(x(t), y(t)). This is the Jacobian product of a 1×21 \times 2 row and a 2×12 \times 1 column. With nn middle variables there are nn terms.

In plain words As tt moves, xx and yy move, and each one pushes zz at its own rate. Add the two pushes.

Example For f(x,y)=x2yf(x, y) = x^2 y on the circle x=cos⁡tx = \cos t, y=sin⁡ty = \sin t at t=π4t = \frac{\pi}{4}, the point is (22,22)\left( \frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2} \right). There fx=2xy=1f_x = 2xy = 1 and fy=x2=12f_y = x^2 = \frac{1}{2}, while x′=−22x' = -\frac{\sqrt{2}}{2} and y′=22y' = \frac{\sqrt{2}}{2}. So

dzdt=1⋅(−22)+12⋅22=−24.\begin{aligned} \frac{dz}{dt} &= 1 \cdot \left( -\frac{\sqrt{2}}{2} \right) + \frac{1}{2} \cdot \frac{\sqrt{2}}{2} \\[0.4em] &= -\frac{\sqrt{2}}{4}. \end{aligned}

Differentiating cos⁡2tsin⁡t\cos^2 t \sin t directly gives −2cos⁡tsin⁡2t+cos⁡3t-2\cos t \sin^2 t + \cos^3 t, which is also −24-\frac{\sqrt{2}}{4} at t=π4t = \frac{\pi}{4}.

Several independent parameters

Definition Let z=f(x,y)z = f(x, y) with ff defined on an open set V⊆R2V \subseteq \mathbb{R}^2, and let x=x(s,t)x = x(s, t) and y=y(s,t)y = y(s, t) be defined on an open set WW of the stst plane with (x(s,t),y(s,t))(x(s, t), y(s, t)) in VV for all (s,t)(s, t) in WW. If xx and yy are differentiable at (s,t)(s, t) and ff is differentiable at (x(s,t),y(s,t))(x(s, t), y(s, t)), then

∂z∂s=∂f∂x∂x∂s+∂f∂y∂y∂s,∂z∂t=∂f∂x∂x∂t+∂f∂y∂y∂t,\begin{aligned} \frac{\partial z}{\partial s} &= \frac{\partial f}{\partial x} \frac{\partial x}{\partial s} + \frac{\partial f}{\partial y} \frac{\partial y}{\partial s}, \\[0.4em] \frac{\partial z}{\partial t} &= \frac{\partial f}{\partial x} \frac{\partial x}{\partial t} + \frac{\partial f}{\partial y} \frac{\partial y}{\partial t}, \end{aligned}

with the partial derivatives of ff evaluated at (x(s,t),y(s,t))(x(s, t), y(s, t)). Each formula is one entry of the product of a 1×21 \times 2 Jacobian and a 2×22 \times 2 Jacobian.

In plain words Hold one parameter fixed and apply the one parameter rule in the other. Do it once for each parameter.

Example Let z=x2+xyz = x^2 + xy in polar coordinates x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta, at (r,θ)=(2,π4)(r, \theta) = \left(2, \frac{\pi}{4}\right). The point is (2,2)(\sqrt{2}, \sqrt{2}), where fx=2x+y=32f_x = 2x + y = 3\sqrt{2} and fy=x=2f_y = x = \sqrt{2}. Also xr=yr=22x_r = y_r = \frac{\sqrt{2}}{2}, xθ=−rsin⁡θ=−2x_\theta = -r\sin\theta = -\sqrt{2} and yθ=rcos⁡θ=2y_\theta = r\cos\theta = \sqrt{2}. So

∂z∂r=32⋅22+2⋅22=4,∂z∂θ=32(−2)+2⋅2=−4.\begin{aligned} \frac{\partial z}{\partial r} &= 3\sqrt{2} \cdot \tfrac{\sqrt{2}}{2} + \sqrt{2} \cdot \tfrac{\sqrt{2}}{2} = 4, \\[0.4em] \frac{\partial z}{\partial \theta} &= 3\sqrt{2}(-\sqrt{2}) + \sqrt{2} \cdot \sqrt{2} = -4. \end{aligned}

Dependency diagrams

Definition A dependency diagram is a tree with the final variable at the top, the middle variables below it, and the independent variables at the bottom. Each edge is labeled with the partial derivative of the upper variable with respect to the lower one. Under the hypotheses of the chain rule, the partial derivative of the top variable with respect to an independent variable is the sum, over all routes from the top down to that variable, of the product of the labels along the route. Every label is evaluated at the actual point, the middle variables at their values there.

In plain words Draw who depends on whom. Each route from the top to your variable gives one product, and you add the products. Routes that never reach the variable contribute nothing.

Example Let w=xeyw = x e^y with x=s2+tx = s^2 + t and y=sty = st. Here xx depends on both ss and tt, and so does yy, so there are two routes to ss and two to tt. At (s,t)=(1,1)(s, t) = (1, 1) we have x=2x = 2 and y=1y = 1, so wx=ey=ew_x = e^y = e and wy=xey=2ew_y = x e^y = 2e, while xs=2x_s = 2, ys=t=1y_s = t = 1, xt=1x_t = 1 and yt=s=1y_t = s = 1. Adding the products along the routes gives

∂w∂s=e⋅2+2e⋅1=4e,∂w∂t=e⋅1+2e⋅1=3e.\begin{aligned} \frac{\partial w}{\partial s} &= e \cdot 2 + 2e \cdot 1 = 4e, \\[0.4em] \frac{\partial w}{\partial t} &= e \cdot 1 + 2e \cdot 1 = 3e. \end{aligned}

A common slip is to evaluate wxw_x and wyw_y at (s,t)=(1,1)(s, t) = (1, 1) instead of at (x,y)=(2,1)(x, y) = (2, 1).

Total versus partial derivative

Definition Let T(x,y,t)T(x, y, t) be differentiable on an open set of R3\mathbb{R}^3, and let x(t)x(t) and y(t)y(t) be differentiable on an open interval with (x(t),y(t),t)(x(t), y(t), t) in that set. The partial derivative ∂T∂t\frac{\partial T}{\partial t} is the rate of change of TT in tt with xx and yy held fixed, here at x=x(t)x = x(t) and y=y(t)y = y(t). The total derivative of TT along the path is the derivative of the composition t↦T(x(t),y(t),t)t \mapsto T(x(t), y(t), t),

dTdt=∂T∂t+∂T∂xdxdt+∂T∂ydydt,\frac{dT}{dt} = \frac{\partial T}{\partial t} + \frac{\partial T}{\partial x} \frac{dx}{dt} + \frac{\partial T}{\partial y} \frac{dy}{dt},

with all partial derivatives of TT evaluated at (x(t),y(t),t)(x(t), y(t), t). The two derivatives are different numbers in general, so the notation must say which is meant.

In plain words The partial derivative is what a thermometer fixed to the floor sees. The total derivative is what a thermometer riding along the path sees, which includes the effect of moving.

Example Let T(x,y,t)=20+x2y−2tT(x, y, t) = 20 + x^2 y - 2t and let the path be x=1+tx = 1 + t, y=3−ty = 3 - t. At t=1t = 1 the point is (2,2)(2, 2), where Tx=2xy=8T_x = 2xy = 8, Ty=x2=4T_y = x^2 = 4 and Tt=−2T_t = -2. Also x′=1x' = 1 and y′=−1y' = -1. So

dTdt=−2+8⋅1+4⋅(−1)=2,\frac{dT}{dt} = -2 + 8 \cdot 1 + 4 \cdot (-1) = 2,

while ∂T∂t=−2\frac{\partial T}{\partial t} = -2. The fixed thermometer sees cooling and the moving one sees warming.

Check yourself

  1. Let z=x2yz = x^2 y with x=1+tx = 1 + t and y=t2y = t^2. Use the chain rule to find dzdt\frac{dz}{dt} at t=2t = 2.
Show the answer

At t=2t = 2 the point is (3,4)(3, 4), where zx=2xy=24z_x = 2xy = 24 and zy=x2=9z_y = x^2 = 9. With x′=1x' = 1 and y′=2t=4y' = 2t = 4,

dzdt=24⋅1+9⋅4=60.\frac{dz}{dt} = 24 \cdot 1 + 9 \cdot 4 = 60.
  1. Let g(t)=⟨cos⁡t,sin⁡t⟩g(t) = \langle \cos t, \sin t \rangle and F(x,y)=⟨x2−y2, 2xy⟩F(x, y) = \langle x^2 - y^2, \ 2xy \rangle. Find (F∘g)′(0)(F \circ g)'(0) by multiplying Jacobians.
Show the answer

Both maps are differentiable everywhere. The inner point is g(0)=(1,0)g(0) = (1, 0) and g′(0)=⟨0,1⟩g'(0) = \langle 0, 1 \rangle. The outer Jacobian at (1,0)(1, 0) is

JF(1,0)=[2x−2y2y2x](1,0)=[2002],\begin{aligned} JF(1, 0) &= \begin{bmatrix} 2x & -2y \\ 2y & 2x \end{bmatrix}_{(1,0)} \\[0.4em] &= \begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}, \end{aligned}

and multiplying it by the column g′(0)g'(0) gives (F∘g)′(0)=⟨0,2⟩(F \circ g)'(0) = \langle 0, 2 \rangle. This agrees with F(g(t))=⟨cos⁡2t,sin⁡2t⟩F(g(t)) = \langle \cos 2t, \sin 2t \rangle.

  1. Let f(x,t)=xtf(x, t) = xt and w(t)=f(t2,t)w(t) = f(t^2, t). Find ∂f∂t\frac{\partial f}{\partial t} and dwdt\frac{dw}{dt} at t=1t = 1.
Show the answer

At t=1t = 1 the point is (x,t)=(1,1)(x, t) = (1, 1). The partial derivative is ft=x=1f_t = x = 1. The total derivative adds the effect of x=t2x = t^2 moving,

dwdt=ft+fx⋅2t=1+1⋅2=3,\frac{dw}{dt} = f_t + f_x \cdot 2t = 1 + 1 \cdot 2 = 3,

which matches w(t)=t3w(t) = t^3.

How this lesson connects

It also uses Differentiability and Jacobian matrices, Partial derivatives and One-variable chain and product rules.