When both inputs of f(x,y) depend on a third variable t, the output depends on t too. Think of t as time and of (x(t),y(t)) as a point moving across the plane; z=f(x(t),y(t)) is the height of the surface above it.
Take a rectangle whose width is x(t)=3+2t cm and height y(t)=2−t cm, t seconds from now. Its area is A=xy. At t=0 it is 3 by 2, its width grows at 2 cm per second, and its height shrinks at 1 cm per second.
Take the two changes one at a time, with the partial derivatives of lesson 4.1.2. With the height held at 2, the growing width adds area at Ax⋅x′=y⋅x′=2×2=4 cm² per second. With the width held at 3, the shrinking height changes it at Ay⋅y′=x⋅y′=3×(−1)=−3, so together they give 1 cm² per second.
Expanding confirms it. A(t)=(3+2t)(2−t)=6+t−2t2 has slope 1−4t, which is 1 at t=0. Chord slopes from t=0 give 0.8, 0.98 and 0.998 for steps 0.1, 0.01 and 0.001.
Rule: Chain rule along a path
dtdz=fxdtdx+fydtdy
One term for each input: its partial derivative times its rate of change. The partials are taken at the moving point (x(t),y(t)). Each term is in units of z per unit of t; with one input, this is the chain rule of lesson 2.3.3.
The rates (x′(t),y′(t)) form the velocityr′(t) of the moving point, so the rule is a dot product: dtdz=∇f⋅r′(t). At speed 1 this is the directional derivative of lesson 4.2.1; at speed 2 the height changes twice as fast.
A second example
Follow the tilted bowl f(x,y)=x2+xy+y2−3x of lesson 4.2.1 along the path x=t2, y=1−t. At t=1 the point is (1,0), where fx=2x+y−3=−1 and fy=x+2y=1. The rates are x′=2t=2 and y′=−1:
dtdz=(−1)(2)+(1)(−1)=−3
Substituting first gives the same answer. z(t)=t4−t3−t2−2t+1, so z′(t)=4t3−3t2−2t−2, and z′(1)=4−3−2−2=−3. Central differences of z(t) at 1 agree:
step h
0.1
0.01
0.001
central difference
−2.97
−2.9997
−2.999997
The tilted bowl seen along the path (t2,1−t). At t=1 the velocity points mostly downhill, against ∇f, so z falls at rate −3. Where the path runs along a level curve, at t=1.38, z stops falling: there ∇f⋅r′=0.
Try it
SymPy substitutes the path into f, then differentiates in t. The loop prints central differences of z(t) at 1.
The last line is the chain rule itself: ∇f at (1,0) dotted with the velocity (2,−1).
⌘/Ctrl + Enter runs the cell
Pulling together, pulling apart, or not at all
Each term carries its own sign, so the inputs can add to the change or work against each other.
Pulling apart. In the rectangle at t=0, the width adds 4 and the height takes away 3. By t=1 the rectangle is 5 by 1, so the terms are 1×2=2 and 5×(−1)=−5: the area now shrinks at 3 cm² per second.
Along a level curve. On the circle x=cost, y=sint, the function f=x2+y2 is always 1. The two terms, 2x⋅(−sint) and 2y⋅cost, cancel exactly: at t=6π they are −0.866025 and 0.866025.
At a flat point. Where ∇f=0, dtdz=0 whatever the velocity.
The circle is one case of a general fact. A path along a level curve has its velocity at right angles to ∇f (lesson 4.2.1), so ∇f⋅r′=0. In the figure, that happens at t=1.38.
When time is an input too
Sometimes t is one of the inputs itself: z=f(t,y(t)). Then the rule has a term for t directly and a term for t acting through y.
Rule: Partial and total derivative
dtdz=∂t∂f+∂y∂fdtdy
The partial ∂t∂f holds y fixed. The total derivative dtdz lets y move with t as well.
Take f(t,y)=ty with y=t2, so z=t3 and dtdz=3t2=3 at t=1. The partial ft=y=1 is only part of it. The rest, fy⋅y′=t⋅2t=2, is the effect of y moving.
Case study 4.2.4 meets both kinds: an option's value changes with time directly, and through the stock price and volatility, which move as time passes.
Try it
The first line is the rectangle at t=1, from the chain rule and from A(t). Then the two cancelling terms on the circle at 6π.
SymPy checks the total derivative of z=ty with y=t2, against its partial ft=y.
⌘/Ctrl + Enter runs the cell
The total differential
Multiply the chain rule by a short time dt. The point moves by small steps dx and dy, and the height by about fxdx+fydy. The same estimate holds for any small steps from a point, whatever path they come from.
Rule: Total differential
Δf≈df=fxdx+fydy=∇f⋅(dxdy)
dx and dy are small steps in x and y, in their own units. Δf is the true change and df its first-order estimate. With more inputs there is one term per input.
In words: f(a+dx,b+dy)≈f(a,b)+fxdx+fydy, with the partials taken at (a,b). The right side is the tangent plane: the flat surface that touches f at (a,b) with the same slopes. It is the degree-1 copy of lesson 2.7.1, in two variables.
Example 1: the rectangle. Grow the 3 by 2 rectangle by dx=0.1 and dy=0.05. Then dA=ydx+xdy=0.2+0.15=0.35, while the true change is 3.1×2.05−6=0.355. The estimate misses only the small corner, dx⋅dy=0.005.
A rectangle of area xy grown by dx and dy, steps drawn large. The total differential ydx+xdy counts the two strips; it misses only the corner dxdy, whose area falls like the square of the steps.
Halve both steps and the corner, which is the error, falls to a quarter: 0.00125. Halve them again and it is 0.0003125.
Example 2: a distance. Take f(x,y)=x2+y2 at (3,4), where f=5 and ∇f=(0.6,0.8) (lesson 4.2.1). For steps dx=0.1 and dy=−0.2, df=0.06−0.16=−0.1. So 3.12+3.82≈4.9; the true value is 4.90408.
steps (dx,dy)
(0.1,−0.2)
(0.05,−0.1)
(0.025,−0.05)
(0.0125,−0.025)
true change Δf
−0.09592
−0.04899
−0.024749
−0.012437
estimate df
−0.1
−0.05
−0.025
−0.0125
error Δf−df
0.00408
0.00101
0.000251
0.0000627
Each halving divides the error by about 4: the ratios are 4.04, 4.02 and 4.01.
Rule: How good the estimate is
Δf−df≈C×(step)2
Near the point the error behaves like the square of the steps, as for the tangent line of lesson 2.7.1. Make every step k times smaller and the error falls about k2 times. Lesson 4.3.1 finds the constant C from the second partial derivatives.
Three variables, and where it fails
With three inputs the estimate has three terms. A box 2 by 3 by 4 cm has volume V=xyz=24 cm³. Lengthen each side by 0.1 cm: dV=yzdx+xzdy+xydz=12(0.1)+8(0.1)+6(0.1)=2.6, against a true change of 2.691.
The estimate fails in two ways. Large steps: from (3,4), the steps (2,−4) reach (5,0), again at distance 5, so the true change is 0; the estimate says −2. Corners: the cone at the origin has no partial derivatives (lesson 4.2.1), so it has no tangent plane and no df there.
Try it
The first loop prints the rectangle's true change, its estimate, the error and dx⋅dy, for the steps above and two halvings. The second loop prints the distance table.
Then the box, and the large step on the distance. 6.27e-05 is Python's way of writing 0.0000627.
⌘/Ctrl + Enter runs the cell
Two inner variables
Now let x and y each depend on two variables, s and t. Then z has two partial derivatives, and each follows the chain rule with one of s, t moving and the other held fixed.
Rule: Chain rule, two inner variables
∂s∂z=fxxs+fyys∂t∂z=fxxt+fyyt
xs is the partial of x in s, and so on. As before, one term per input of f, and the partials of f are taken at the point (x,y).
Example: polar coordinates. A point at distance r from the origin, at angle θ, has x=rcosθ and y=rsinθ, as in the polar form of lesson 1.7.3. Take f=xy, so fx=y and fy=x. The inner partials are xr=cosθ, yr=sinθ, xθ=−rsinθ and yθ=rcosθ.
At r=2, θ=6π, the point is (3,1)≈(1.732051,1), with cosθ≈0.866025 and sinθ=0.5. Then
zrzθ=ycosθ+xsinθ=3=−yrsinθ+xrcosθ=2
In numbers, zr=0.866025+0.866025≈1.732051 and zθ=−1+3=2.
Substituting first agrees: z=r2cosθsinθ, so zr=2rcosθsinθ=3 and zθ=r2(cos2θ−sin2θ)=4×0.5=2.
In matrix form, the row of answers is the gradient, written as a row, times the matrix of inner partials (lesson 3.2.1):
(zrzθ)=(fxfy)(xryrxθyθ)
That matrix is called the Jacobian matrix of the map from (r,θ) to (x,y); lesson 4.7.2 uses it to change variables in integrals.
Try it
The gradient (y,x) at (3,1) times the Jacobian matrix gives (zr,zθ). Central differences in r and in θ agree.
SymPy differentiates z=r2cosθsinθ directly.
⌘/Ctrl + Enter runs the cell
Lesson 4.3.1 adds second-order terms to the total differential. Case study 4.2.4 uses the first-order estimate to split a day's change in an option's value into its causes.
Common mistakes
One term per input. For the rectangle at t=0, dtdA=4−3=1; leaving out the height gives 4.
Take the partials at the moving point. At t=1 the rectangle is 5 by 1, so the terms are 1×2 and 5×(−1), not the values at t=0.
∂ and d are different. For f=ty with y=t2, the partial ft is 1 but dtdz is 3.
The total differential is for small steps. Its error grows like the square of the steps: the step (2,−4) on the distance gives −2 for a true change of 0.
Steps in the inputs' own units.dx must be in the units fx is measured per; mixing centimetres and metres, or percent and decimals, gives nonsense.
No tangent plane at a corner. Where a partial does not exist, neither does df.
The multivariable chain rule and the total differential
0 of 12 correct
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
How to type answers
Powers with ^: x^7, 2^(1/3), a^-2.
Multiply with * or by writing side by side: 3x^2, 2(x+1).
ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
Your first answer to each question is saved: it counts towards your score and brings the question back for review.
Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.
Summary card
Along a path, dtdz=fxdtdx+fydtdy=∇f⋅r′(t): one term per input, with the partials taken at the moving point.
The terms can add or cancel. Along a level curve the velocity is at right angles to ∇f, so dtdz=0.
When t is an input itself, dtdz=∂t∂f+∂y∂fdtdy: the partial holds the other inputs fixed, the total derivative does not.
Total differential: Δf≈df=fxdx+fydy, the tangent-plane estimate. Its error falls like the square of the steps, and it fails for large steps and at corners.
With two inner variables, zs=fxxs+fyys and zt=fxxt+fyyt: the gradient, as a row, times the Jacobian matrix.