Ran Wei/ Calculus/Module 17
中文
Calculus · Part V · Several variables

Module 17Partial derivatives and the gradient

Extend the derivative to functions of several variables. You will read surfaces and contour maps, compute partial derivatives, tangent planes and linear approximations, and use the chain rule with tree diagrams; then you will find the direction of steepest ascent with the gradient and put it to work as machine learning does, in gradient descent and backpropagation.

⏱ 270 minYou need: Modules 1 to 16, especially limits (Module 2), the chain rule (Module 5), linearisation (Module 7), gradient descent (Module 8), and vectors, the dot product and planes (Module 16)

In this module you will

  • Describe a function of two or three variables by its domain, its graph, and its level curves or level surfaces
  • Decide whether a limit in two variables exists, by comparing paths or by squeezing
  • Compute partial derivatives of every order, and use Clairaut’s theorem
  • Find tangent planes and linear approximations, and explain why differentiability needs more than partial derivatives
  • Apply the chain rule with tree diagrams, including implicit differentiation
  • Compute directional derivatives and gradients, and use them for steepest ascent, gradient descent and backpropagation
1

Functions of several variables

So far this series has concentrated on functions of one independent variable. Most quantities depend on several. The volume of a cylindrical can depends on its radius rr and its height h:h\mathclose{\text{:}} V=πr2h.V = \pi r^2 h\mathclose{\text{.}} The temperature on a weather map depends on two coordinates, the temperature in a room on three, and the error of a machine-learning model on all of its parameters, often millions of them. This module extends the derivative to such functions. Two variables already show the main new ideas, and most of what follows carries over to three variables, or to a million, unchanged.

Definition 17.1Function of two variables

A function of two variables ff is a rule that assigns to each ordered pair of real numbers (x,y)(x, y) in a set DD exactly one real number f(x,y),f(x, y)\mathclose{\text{,}} read “f of x, y”. The set D,D\mathclose{\text{,}} a set of points of the plane, is the domain of f,f\mathclose{\text{,}} and the set of all values f(x,y)f(x, y) for (x,y)(x, y) in DD is its range. A function of three variables assigns a number f(x,y,z)f(x, y, z) to each point (x,y,z)(x, y, z) of a set DD in space.

As in Module 1, when a function is given by a formula and nothing is said about its domain, the domain is the set of all points at which the formula gives a real number. One often writes z=f(x,y)z = f(x, y) and calls xx and yy the independent variables and zz the dependent variable.

Example 17.1Domains and ranges✓ Checked

Find the domain and the range of (a) f(x,y)=9−x2−y2f(x, y) = \sqrt{9 - x^2 - y^2} and (b) g(x,y)=ln⁡(y−x2).g(x, y) = \ln(y - x^2)\mathclose{\text{.}}

(a) The square root needs 9−x2−y2≥0,9 - x^2 - y^2 \ge 0\mathclose{\text{,}} that is, x2+y2≤9.x^2 + y^2 \le 9\mathclose{\text{.}} Since x2+y2x^2 + y^2 is the square of the distance from (x,y)(x, y) to the origin (Module 16), the domain is the disc of radius 3 centred at the origin, together with its edge, the circle x2+y2=9.x^2 + y^2 = 9\mathclose{\text{.}} On the domain, 9−x2−y29 - x^2 - y^2 lies between 0 and 9, so f(x,y)f(x, y) lies between 0 and 3. Every number in [0,3][0, 3] is a value: along the xx-axis, f(x,0)=9−x2f(x, 0) = \sqrt{9 - x^2} runs through all of [0,3][0, 3] as xx runs from 3 down to 0. The range is [0,3].[0, 3]\mathclose{\text{.}}

(b) The logarithm needs y−x2>0,y - x^2 > 0\mathclose{\text{,}} that is, y>x2:y > x^2\mathclose{\text{:}} the domain is the region above the parabola y=x2,y = x^2\mathclose{\text{,}} without the parabola itself. Along the yy-axis, g(0,y)=ln⁡yg(0, y) = \ln y takes every real value as yy runs through (0,∞),(0, \infty)\mathclose{\text{,}} so the range is R.\R\mathclose{\text{.}}

Graphs

The graph of a function ff of two variables is the set of points (x,y,z)(x, y, z) in space with z=f(x,y)z = f(x, y) and (x,y)(x, y) in the domain. Above each point (x,y)(x, y) of the domain it has exactly one point, at height f(x,y).f(x, y)\mathclose{\text{.}} For a continuous function on a region of the plane, picture the graph as a surface (Figure 17.1, left). The graph of f(x,y)=9−x2−y2f(x, y) = \sqrt{9 - x^2 - y^2} from Example 17.1 is a dome: squaring z=9−x2−y2z = \sqrt{9 - x^2 - y^2} gives x2+y2+z2=9x^2 + y^2 + z^2 = 9 with z≥0,z \ge 0\mathclose{\text{,}} the upper half of the sphere of radius 3 centred at the origin. The graph of a linear function f(x,y)=ax+by+cf(x, y) = ax + by + c is a plane (Module 16).

Drawing a surface by hand is hard, and even a computer’s picture of one hides some parts behind others. Mapmakers met this problem long ago.

Level curves and contour maps

A hiking map does not show a mountain in three dimensions. It draws contour lines, each joining the points at one height above sea level, and labels them with their heights. Weather maps do the same with isotherms, curves of equal temperature, and isobars, curves of equal air pressure.

Definition 17.2Level curves

The level sets of a function ff of two variables are the sets of points satisfying f(x,y)=k,f(x, y) = k\mathclose{\text{,}} for constants kk in the range of f.f\mathclose{\text{.}} They are usually curves, called level curves, but a level set can also be a single point or a whole region. A drawing of level curves for equally spaced values of k,k\mathclose{\text{,}} labelled with the values, is a contour map of f.f\mathclose{\text{.}}

The level curve f(x,y)=kf(x, y) = k is the set of points of the domain above which the surface has height k:k\mathclose{\text{:}} cut the surface with the horizontal plane z=k,z = k\mathclose{\text{,}} and look at the cut from above. Figure 17.1 shows a surface with two peaks, with its level curves drawn on it at their heights, and the contour map that they make.

Left: the graph of f(x, y) = (x^2 + 3y^2)e^{1 - x^2 - y^2}, a landscape with two peaks of height 3 at (0, pm1), a pit at the origin and two passes at (pm1, 0). Its level curves f = 0.5, 1, 1.5, 2, 2.5 are drawn on the surface at their heights. Right: the same level curves seen from above, the contour map. The level curve f = 1 crosses itself at the passes.
Figure 17.1

Left: the graph of f(x,y)=(x2+3y2)e1−x2−y2,f(x, y) = (x^2 + 3y^2)e^{1 - x^2 - y^2}\mathclose{\text{,}} a landscape with two peaks of height 3 at (0,±1),(0, \pm1)\mathclose{\text{,}} a pit at the origin and two passes at (±1,0).(\pm1, 0)\mathclose{\text{.}} Its level curves f=0.5,1,1.5,2,2.5f = 0.5, 1, 1.5, 2, 2.5 are drawn on the surface at their heights. Right: the same level curves seen from above, the contour map. The level curve f=1f = 1 crosses itself at the passes.

A contour map is read like this:

  • Where the level curves crowd together, the surface is steep; where they spread out, it is gentle. Equal steps in height take little horizontal distance on a steep slope.
  • Small closed level curves nested around a point mark a peak or a pit; the labels tell you which.
  • At the passes in Figure 17.1, the level curve f=1f = 1 crosses itself.
Example 17.2Level curves of a dome✓ Checked

Describe the level sets f(x,y)=kf(x, y) = k of f(x,y)=9−x2−y2f(x, y) = \sqrt{9 - x^2 - y^2} for k=0,1,2,3,k = 0, 1, 2, 3\mathclose{\text{,}} and explain how they show the shape of the dome.

For 0≤k≤3,0 \le k \le 3\mathclose{\text{,}} 9−x2−y2=k\sqrt{9 - x^2 - y^2} = k means 9−x2−y2=k29 - x^2 - y^2 = k^2 (both sides are non-negative, so squaring loses nothing), that is,

x2+y2=9−k2,x^2 + y^2 = 9 - k^2,

the circle centred at the origin with radius 9−k2.\sqrt{9 - k^2}\mathclose{\text{.}} The radii are 3, 8≈2.83,\sqrt8 \approx 2.83\mathclose{\text{,}} 5≈2.24\sqrt5 \approx 2.24 and 0: for k=3k = 3 the “circle” is the single point (0,0),(0, 0)\mathclose{\text{,}} the top of the dome. The gaps between consecutive circles are about 0.17, 0.59 and 2.24. The circles crowd together near the edge, where the dome is steep (its sides are vertical there), and spread out near the top, where it is nearly flat.

Watch out

A contour map without labels cannot tell a peak from a pit: both can have nested closed curves. Read the labels. And do not confuse level curves with the graph: the positive level curves of f(x,y)=x2+y2f(x, y) = x^2 + y^2 are circles, while its level set at 0 is a point. Its graph is a bowl, the surface z=x2+y2,z = x^2 + y^2\mathclose{\text{,}} whose horizontal cuts at positive heights are those circles.

Three variables and level surfaces

The graph of a function of three variables would need four dimensions. Instead, one studies its level surfaces f(x,y,z)=k.f(x, y, z) = k\mathclose{\text{.}} For the temperature in a room, they are the surfaces of equal temperature. For f(x,y,z)=x2+y2+z2,f(x, y, z) = x^2 + y^2 + z^2\mathclose{\text{,}} the square of the distance from the origin, the level surface f=kf = k is the sphere of radius k\sqrt k centred at the origin when k>0,k > 0\mathclose{\text{,}} the single point (0,0,0)(0, 0, 0) when k=0,k = 0\mathclose{\text{,}} and empty when k<0.k < 0\mathclose{\text{.}} Section 17.6 finds tangent planes to level surfaces.

2

Limits and continuity

On the number line, xx can approach aa from two sides only. In the plane, (x,y)(x, y) can approach (a,b)(a, b) from every direction, along straight lines, spirals or any other path, and a limit must not depend on the path.

Definition 17.3Limit

Let ff be defined at every point of a disc centred at (a,b),(a, b)\mathclose{\text{,}} except perhaps at (a,b)(a, b) itself. Then

lim⁡(x,y)→(a,b)f(x,y)=L,\lim_{(x, y)\to(a, b)} f(x, y) = L,

read “the limit of f of x, y as (x, y) approaches (a, b) is L”, if for every number ε>0\varepsilon > 0 there is a number δ>0\delta > 0 such that ∣f(x,y)−L∣<ε\abs{f(x, y) - L} < \varepsilon for every point (x,y)(x, y) with

0<(x−a)2+(y−b)2<δ.0 < \sqrt{(x - a)^2 + (y - b)^2} < \delta.

This is the ε–δ definition of Section 2.7, with the distance ∣x−a∣\abs{x - a} on the line replaced by the distance in the plane: the values f(x,y)f(x, y) are as close to LL as you like at all points close enough to (a,b),(a, b)\mathclose{\text{,}} in whatever direction they lie. (A disc centred at (a,b)(a, b) is the set of points at a distance less than some radius ρ>0\rho > 0 from it. When (a,b)(a, b) is on the edge of the domain, as (3,0)(3, 0) is for the dome of Example 17.1, the same definition is used with (x,y)(x, y) restricted to the domain, as one-sided limits restrict xx to one side.)

The limit laws of Module 2 hold, with the same proofs: limits of sums, products and quotients are the sums, products and quotients of the limits (for quotients, when the limit of the denominator is not 0). In particular, for a polynomial in xx and y,y\mathclose{\text{,}} or a rational function whose denominator is not 0 at (a,b),(a, b)\mathclose{\text{,}} the limit is the value. For example, lim⁡(x,y)→(1,2)x2y+1x+y=2+13=1.\lim_{(x,y)\to(1,2)} \dfrac{x^2 y + 1}{x + y} = \dfrac{2 + 1}{3} = 1\mathclose{\text{.}}

Paths

Here is a function with no limit at the origin:

f(x,y)=xyx2+y2,(x,y)≠(0,0).f(x, y) = \frac{xy}{x^2 + y^2}, \qquad (x, y) \ne (0, 0).

Approach the origin along four lines, with x=tx = t shrinking towards 0:

ttf(t,0)f(t, 0)f(t,t)f(t, t)f(t,2t)f(t, 2t)f(t,−t)f(t, -t)
0.10.1000.50.50.40.4−0.5-0.5
0.010.01000.50.50.40.4−0.5-0.5
0.0010.001000.50.50.40.4−0.5-0.5
−0.001-0.001000.50.50.40.4−0.5-0.5

Along each line the values do not change at all, but they differ from line to line: 0 along the xx-axis, 0.5 along y=x,y = x\mathclose{\text{,}} 0.4 along y=2xy = 2x and −0.5-0.5 along y=−x.y = -x\mathclose{\text{.}} However close to the origin you look, there are values near 0.5 and values near −0.5,-0.5\mathclose{\text{,}} so no single number LL satisfies Definition 17.3.

Theorem 17.1Limits along paths

Suppose that lim⁡(x,y)→(a,b)f(x,y)=L,\lim_{(x, y)\to(a, b)} f(x, y) = L\mathclose{\text{,}} and let x(t)x(t) and y(t)y(t) be functions with x(t)→ax(t) \to a and y(t)→by(t) \to b as t→t0.t \to t_0\mathclose{\text{.}} Suppose also that (x(t),y(t))\big(x(t), y(t)\big) lies in the domain of ff and differs from (a,b)(a, b) for t≠t0t \ne t_0 near t0.t_0\mathclose{\text{.}} Then

lim⁡t→t0f(x(t),y(t))=L.\lim_{t\to t_0} f\big(x(t), y(t)\big) = L.

So if ff approaches different numbers along two such paths, or no number along one of them, then lim⁡(x,y)→(a,b)f(x,y)\lim_{(x, y)\to(a, b)} f(x, y) does not exist.

Proof

Let ε>0,\varepsilon > 0\mathclose{\text{,}} and take δ\delta as in Definition 17.3. As t→t0,t \to t_0\mathclose{\text{,}} the distance (x(t)−a)2+(y(t)−b)2\sqrt{(x(t) - a)^2 + (y(t) - b)^2} tends to 0, so it is less than δ\delta for every t≠t0t \ne t_0 close enough to t0;t_0\mathclose{\text{;}} and it is not 0 there, since the point is not (a,b).(a, b)\mathclose{\text{.}} For those t,t\mathclose{\text{,}} ∣f(x(t),y(t))−L∣<ε,\abs{f(x(t), y(t)) - L} < \varepsilon\mathclose{\text{,}} which is what lim⁡t→t0f(x(t),y(t))=L\lim_{t\to t_0} f(x(t), y(t)) = L means. If the limit existed, it would therefore be the limit along every path, which is impossible when two paths give different numbers.

∎
Example 17.3A limit that depends on the path✓ Checked

Show that lim⁡(x,y)→(0,0)xyx2+y2\lim_{(x, y)\to(0, 0)} \dfrac{xy}{x^2 + y^2} does not exist.

Along the line y=mx,y = mx\mathclose{\text{,}} with x≠0,x \ne 0\mathclose{\text{,}}

f(x,mx)=x⋅mxx2+m2x2=mx2(1+m2)x2=m1+m2.f(x, mx) = \frac{x \cdot mx}{x^2 + m^2x^2} = \frac{m x^2}{(1 + m^2)x^2} = \frac{m}{1 + m^2}.

So ff is constant along each line through the origin: 0 along the xx-axis (m=0)m = 0\mathclose{\text{)}} and 12\tfrac12 along y=xy = x (m=1).m = 1\mathclose{\text{).}} Two paths give two different limits, so by Theorem 17.1 the limit does not exist. Near the origin the graph is a twisted surface: every value from −12-\tfrac12 to 12\tfrac12 (the range of m/(1+m2))m/(1 + m^2)\mathclose{\text{)}} is taken on a whole line through the origin, arbitrarily close to it.

Watch out

Agreement along every straight line does not prove that a limit exists. For g(x,y)=x2yx4+y2,g(x, y) = \dfrac{x^2 y}{x^4 + y^2}\mathclose{\text{,}} every line through the origin gives the limit 0: along y=mx,y = mx\mathclose{\text{,}} g=mxx2+m2,g = \dfrac{mx}{x^2 + m^2}\mathclose{\text{,}} which tends to 0 (for m=0m = 0 it is 0), and along the yy-axis g=0.g = 0\mathclose{\text{.}} But along the parabola y=x2,y = x^2\mathclose{\text{,}} g=x42x4=12.g = \dfrac{x^4}{2x^4} = \dfrac12\mathclose{\text{.}} The limit does not exist. To prove that a limit exists, you need an argument that covers all points near (a,b)(a, b) at once.

Squeezing

The squeeze theorem of Section 2.6 gives such an argument.

Theorem 17.2The squeeze theorem in two variables

Suppose that ∣f(x,y)−L∣≤g(x,y)\abs{f(x, y) - L} \le g(x, y) for every point (x,y)≠(a,b)(x, y) \ne (a, b) of a disc centred at (a,b),(a, b)\mathclose{\text{,}} and that lim⁡(x,y)→(a,b)g(x,y)=0.\lim_{(x, y)\to(a, b)} g(x, y) = 0\mathclose{\text{.}} Then lim⁡(x,y)→(a,b)f(x,y)=L.\lim_{(x, y)\to(a, b)} f(x, y) = L\mathclose{\text{.}}

Proof

Let ε>0.\varepsilon > 0\mathclose{\text{.}} Since g→0,g \to 0\mathclose{\text{,}} there is a δ>0,\delta > 0\mathclose{\text{,}} which may be taken no larger than the radius of the disc, such that g(x,y)<εg(x, y) < \varepsilon whenever 0<(x−a)2+(y−b)2<δ.0 < \sqrt{(x - a)^2 + (y - b)^2} < \delta\mathclose{\text{.}} For those points, ∣f(x,y)−L∣≤g(x,y)<ε.\abs{f(x, y) - L} \le g(x, y) < \varepsilon\mathclose{\text{.}}

∎
Example 17.4A limit by squeezing✓ Checked

Find lim⁡(x,y)→(0,0)3x2yx2+y2.\lim_{(x, y)\to(0, 0)} \dfrac{3x^2 y}{x^2 + y^2}\mathclose{\text{.}}

Along the line y=mxy = mx the function is 3mx3(1+m2)x2=3mx1+m2,\dfrac{3m x^3}{(1 + m^2)x^2} = \dfrac{3m x}{1 + m^2}\mathclose{\text{,}} which tends to 0, and along the yy-axis it is 0. So if the limit exists, it is 0 (Theorem 17.1). To prove that it exists, squeeze. For (x,y)≠(0,0),(x, y) \ne (0, 0)\mathclose{\text{,}} x2≤x2+y2,x^2 \le x^2 + y^2\mathclose{\text{,}} so x2x2+y2≤1\dfrac{x^2}{x^2 + y^2} \le 1 and

∣3x2yx2+y2−0∣=3∣y∣ x2x2+y2≤3∣y∣.\abs{\frac{3x^2 y}{x^2 + y^2} - 0} = 3\abs{y}\,\frac{x^2}{x^2 + y^2} \le 3\abs{y}.

As (x,y)→(0,0),(x, y) \to (0, 0)\mathclose{\text{,}} 3∣y∣→0,3\abs{y} \to 0\mathclose{\text{,}} because ∣y∣≤x2+y2.\abs{y} \le \sqrt{x^2 + y^2}\mathclose{\text{.}} By Theorem 17.2 the limit is 0. In ε–δ terms, δ=ε/3\delta = \varepsilon/3 works: x2+y2<ε/3\sqrt{x^2 + y^2} < \varepsilon/3 gives 3∣y∣<ε.3\abs{y} < \varepsilon\mathclose{\text{.}}

Continuity

Definition 17.4Continuity

Let ff be defined on a disc centred at (a,b).(a, b)\mathclose{\text{.}} Then ff is continuous at (a,b)(a, b) if

lim⁡(x,y)→(a,b)f(x,y)=f(a,b).\lim_{(x, y)\to(a, b)} f(x, y) = f(a, b).

It is continuous on a set if it is continuous at every point of the set (at points on the edge of the domain, with the limit taken over points of the domain).

As in Module 3, sums, products and quotients of continuous functions are continuous (quotients where the denominator is not 0), and so are compositions: if g(x,y)g(x, y) is continuous at (a,b)(a, b) and a function hh of one variable is continuous at g(a,b),g(a, b)\mathclose{\text{,}} then h(g(x,y))h\big(g(x, y)\big) is continuous at (a,b).(a, b)\mathclose{\text{.}} Since xx and yy themselves are continuous, every polynomial in xx and yy is continuous everywhere, every rational function wherever its denominator is not 0, and functions such as exysin⁡ye^{xy}\sin y and ln⁡(x2+y2)\ln(x^2 + y^2) wherever they are defined.

At a point where a formula breaks down, look closer. The functions of Examples 17.3 and 17.4 are both undefined at the origin. Give each the value 0 there: the function of Example 17.4 becomes continuous everywhere, since its limit at the origin is 0, but the function of Example 17.3 is not continuous at the origin, since it has no limit there. It returns in Section 17.4, as a warning.

3

Partial derivatives

Take a can of radius r=3r = 3 cm and height h=10h = 10 cm, with volume V(3,10)=90π≈282.7V(3, 10) = 90\pi \approx 282.7 cm³. How fast does the volume change when the radius changes and the height does not? Widen the can by Δ\Delta cm, or make it Δ\Delta cm taller, and divide each change of volume by Δ:\Delta\mathclose{\text{:}}

Δ\DeltaV(3+Δ,10)−V(3,10)Δ\dfrac{V(3 + \Delta, 10) - V(3, 10)}{\Delta}V(3,10+Δ)−V(3,10)Δ\dfrac{V(3, 10 + \Delta) - V(3, 10)}{\Delta}
11219.911219.91128.274328.2743
0.10.1191.637191.63728.274328.2743
0.010.01188.810188.81028.274328.2743
0.0010.001188.527188.52728.274328.2743
−0.001-0.001188.464188.46428.274328.2743

With the height held at 10, V=10πr2V = 10\pi r^2 is a function of rr alone, and the first column approaches its derivative at r=3,r = 3\mathclose{\text{,}} 20πr=60π≈188.5.20\pi r = 60\pi \approx 188.5\mathclose{\text{.}} With the radius held at 3, V=9πhV = 9\pi h is a linear function of h,h\mathclose{\text{,}} and the second column is its slope, 9π≈28.27,9\pi \approx 28.27\mathclose{\text{,}} whatever Δ\Delta is. These two numbers are the partial derivatives of VV at (3,10):(3, 10)\mathclose{\text{:}} near this size the volume grows by about 188.5 cm³ per centimetre of radius and by about 28.3 cm³ per centimetre of height. Widening the can adds volume more than six times as fast as lengthening it.

Definition 17.5Partial derivatives

Let ff be a function of two variables defined on a disc centred at (a,b).(a, b)\mathclose{\text{.}} The partial derivative of ff with respect to xx at (a,b)(a, b) is

fx(a,b)=lim⁡h→0f(a+h,b)−f(a,b)h,f_x(a, b) = \lim_{h\to0}\frac{f(a + h, b) - f(a, b)}{h},

and the partial derivative with respect to yy is

fy(a,b)=lim⁡h→0f(a,b+h)−f(a,b)h,f_y(a, b) = \lim_{h\to0}\frac{f(a, b + h) - f(a, b)}{h},

provided that the limits exist.

fxf_x reads “f sub x”. Other notations are ∂f∂x,\dfrac{\partial f}{\partial x}\mathclose{\text{,}} read “partial f by partial x” (the rounded ∂,\partial\mathclose{\text{,}} read “partial”, warns that ff has other variables, held fixed), and ∂z∂x\dfrac{\partial z}{\partial x} when z=f(x,y).z = f(x, y)\mathclose{\text{.}} Letting the point vary gives two new functions of two variables, fx(x,y)f_x(x, y) and fy(x,y).f_y(x, y)\mathclose{\text{.}}

The definition says that fx(a,b)f_x(a, b) is the ordinary derivative at aa of the function of one variable x↦f(x,b),x \mapsto f(x, b)\mathclose{\text{,}} in which yy is frozen at b.b\mathclose{\text{.}} That gives the rule for computing partial derivatives.

Key idea

To find fx,f_x\mathclose{\text{,}} treat yy as a constant and differentiate with respect to xx by the rules of Modules 4 to 6. To find fy,f_y\mathclose{\text{,}} treat xx as a constant and differentiate with respect to y.y\mathclose{\text{.}}

Geometrically, the vertical plane y=by = b cuts the surface z=f(x,y)z = f(x, y) along the curve z=f(x,b),z = f(x, b)\mathclose{\text{,}} and fx(a,b)f_x(a, b) is the slope of that curve at the point P(a,b,f(a,b)):P(a, b, f(a, b))\mathclose{\text{:}} the rate at which the surface rises as you move from PP in the direction of the positive xx-axis. Likewise fy(a,b)f_y(a, b) is the slope of the curve cut by the plane x=ax = a (Figure 17.2, left). For f(x,y)=6−x2−2y2f(x, y) = 6 - x^2 - 2y^2 at P(1,1,3),P(1, 1, 3)\mathclose{\text{,}} the plane y=1y = 1 cuts out the curve z=4−x2,z = 4 - x^2\mathclose{\text{,}} of slope −2x=−2-2x = -2 at x=1,x = 1\mathclose{\text{,}} and the plane x=1x = 1 cuts out z=5−2y2,z = 5 - 2y^2\mathclose{\text{,}} of slope −4y=−4-4y = -4 at y=1.y = 1\mathclose{\text{.}} So fx(1,1)=−2f_x(1, 1) = -2 and fy(1,1)=−4;f_y(1, 1) = -4\mathclose{\text{;}} by the rule, fx=−2xf_x = -2x and fy=−4yf_y = -4y everywhere.

Left: the surface z = 6 - x^2 - 2y^2 and the point P(1, 1, 3). The plane y = 1 cuts out the blue curve z = 4 - x^2, whose tangent line at P (dark) has slope fx(1, 1) = -2; the plane x = 1 cuts out the orange curve z = 5 - 2y^2, whose tangent line (red) has slope fy(1, 1) = -4. Right: the tangent plane z = 9 - 2x - 4y at P (Section 17.4) contains both tangent lines.
Figure 17.2

Left: the surface z=6−x2−2y2z = 6 - x^2 - 2y^2 and the point P(1,1,3).P(1, 1, 3)\mathclose{\text{.}} The plane y=1y = 1 cuts out the blue curve z=4−x2,z = 4 - x^2\mathclose{\text{,}} whose tangent line at PP (dark) has slope fx(1,1)=−2;f_x(1, 1) = -2\mathclose{\text{;}} the plane x=1x = 1 cuts out the orange curve z=5−2y2,z = 5 - 2y^2\mathclose{\text{,}} whose tangent line (red) has slope fy(1,1)=−4.f_y(1, 1) = -4\mathclose{\text{.}} Right: the tangent plane z=9−2x−4yz = 9 - 2x - 4y at PP (Section 17.4) contains both tangent lines.

Computing partial derivatives

Example 17.5Partial derivatives by the rules✓ Checked

Find the partial derivatives of (a) f(x,y)=x3y2−5xy+2y3,f(x, y) = x^3y^2 - 5xy + 2y^3\mathclose{\text{,}} with their values at (1,2),(1, 2)\mathclose{\text{,}} (b) g(x,y)=sin⁡(xy2)g(x, y) = \sin(xy^2) and (c) q(x,y)=xx2+y2.q(x, y) = \dfrac{x}{x^2 + y^2}\mathclose{\text{.}}

(a) With yy held constant, y2y^2 is a constant factor of x3y2,x^3y^2\mathclose{\text{,}} −5y-5y a constant factor of x,x\mathclose{\text{,}} and 2y32y^3 a constant:

fx=3x2y2−5y,fy=2x3y−5x+6y2.f_x = 3x^2y^2 - 5y, \qquad f_y = 2x^3y - 5x + 6y^2.

At (1,2):(1, 2)\mathclose{\text{:}} fx(1,2)=12−10=2f_x(1, 2) = 12 - 10 = 2 and fy(1,2)=4−5+24=23.f_y(1, 2) = 4 - 5 + 24 = 23\mathclose{\text{.}}

(b) By the chain rule, with the inner function xy2,xy^2\mathclose{\text{,}} whose partial derivatives are y2y^2 and 2xy:2xy\mathclose{\text{:}}

gx=y2cos⁡(xy2),gy=2xycos⁡(xy2).g_x = y^2\cos(xy^2), \qquad g_y = 2xy\cos(xy^2).

(c) By the quotient rule. With yy constant, the derivative of the denominator is 2x,2x\mathclose{\text{,}} so

qx=(x2+y2)−x⋅2x(x2+y2)2=y2−x2(x2+y2)2.\begin{aligned} q_x &= \frac{(x^2 + y^2) - x \cdot 2x}{(x^2 + y^2)^2} \\ &= \frac{y^2 - x^2}{(x^2 + y^2)^2}. \end{aligned}

With xx constant, the numerator is a constant, so

qy=−x⋅2y(x2+y2)2=−2xy(x2+y2)2,q_y = -\frac{x \cdot 2y}{(x^2 + y^2)^2} = -\frac{2xy}{(x^2 + y^2)^2},

both for (x,y)≠(0,0).(x, y) \ne (0, 0)\mathclose{\text{.}}

Watch out

When you differentiate with respect to x,x\mathclose{\text{,}} a factor that contains only yy is a constant: ∂∂x(x3y2)=3x2y2,\dfrac{\partial}{\partial x}\big(x^3y^2\big) = 3x^2y^2\mathclose{\text{,}} not 3x2y2+2x3y,3x^2y^2 + 2x^3y\mathclose{\text{,}} and ∂∂x(y3)=0.\dfrac{\partial}{\partial x}\big(y^3\big) = 0\mathclose{\text{.}} The product rule is needed only when both factors contain x.x\mathclose{\text{.}}

For a function of three variables, fx,f_x\mathclose{\text{,}} fyf_y and fzf_z are defined in the same way, each with the other two variables held fixed. For w=xy2z3:w = xy^2z^3\mathclose{\text{:}} wx=y2z3,w_x = y^2z^3\mathclose{\text{,}} wy=2xyz3w_y = 2xyz^3 and wz=3xy2z2.w_z = 3xy^2z^2\mathclose{\text{.}}

Higher partial derivatives

The partial derivatives fxf_x and fyf_y are again functions of xx and y.y\mathclose{\text{.}} Where their partial derivatives exist, these are the four second partial derivatives of f:f\mathclose{\text{:}}

fxx=(fx)x=∂2f∂x2,fxy=(fx)y=∂2f∂y ∂x,fyx=(fy)x=∂2f∂x ∂y,fyy=(fy)y=∂2f∂y2.\begin{aligned} f_{xx} &= (f_x)_x = \frac{\partial^2 f}{\partial x^2}, & f_{xy} &= (f_x)_y = \frac{\partial^2 f}{\partial y\,\partial x}, \\ f_{yx} &= (f_y)_x = \frac{\partial^2 f}{\partial x\,\partial y}, & f_{yy} &= (f_y)_y = \frac{\partial^2 f}{\partial y^2}. \end{aligned}

fxyf_{xy} reads “f sub x y”. Mind the order: in fxyf_{xy} you differentiate first with respect to x,x\mathclose{\text{,}} then y,y\mathclose{\text{,}} reading from left to right; in ∂2f∂y ∂x,\dfrac{\partial^2 f}{\partial y\,\partial x}\mathclose{\text{,}} the same derivative, you read from right to left. fxyf_{xy} and fyxf_{yx} are the mixed partial derivatives.

Example 17.6Second partial derivatives✓ Checked

Find the four second partial derivatives of f(x,y)=x3y2−5xy+2y3f(x, y) = x^3y^2 - 5xy + 2y^3 from Example 17.5, and the mixed partial derivatives of g(x,y)=sin⁡(xy2).g(x, y) = \sin(xy^2)\mathclose{\text{.}}

From fx=3x2y2−5yf_x = 3x^2y^2 - 5y and fy=2x3y−5x+6y2:f_y = 2x^3y - 5x + 6y^2\mathclose{\text{:}}

fxx=6xy2,fxy=6x2y−5,fyx=6x2y−5,fyy=2x3+12y.\begin{aligned} f_{xx} &= 6xy^2, & f_{xy} &= 6x^2y - 5, \\ f_{yx} &= 6x^2y - 5, & f_{yy} &= 2x^3 + 12y. \end{aligned}

For g,g\mathclose{\text{,}} differentiate gx=y2cos⁡(xy2)g_x = y^2\cos(xy^2) with respect to y,y\mathclose{\text{,}} and gy=2xycos⁡(xy2)g_y = 2xy\cos(xy^2) with respect to x,x\mathclose{\text{,}} each by the product rule and the chain rule:

gxy=2ycos⁡(xy2)−y2sin⁡(xy2)⋅2xy=2ycos⁡(xy2)−2xy3sin⁡(xy2),gyx=2ycos⁡(xy2)−2xysin⁡(xy2)⋅y2=2ycos⁡(xy2)−2xy3sin⁡(xy2).\begin{aligned} g_{xy} &= 2y\cos(xy^2) - y^2\sin(xy^2)\cdot 2xy \\ &= 2y\cos(xy^2) - 2xy^3\sin(xy^2), \\ g_{yx} &= 2y\cos(xy^2) - 2xy\sin(xy^2)\cdot y^2 \\ &= 2y\cos(xy^2) - 2xy^3\sin(xy^2). \end{aligned}

Both times the mixed partial derivatives agree, though they were computed in different ways.

The agreement is no accident.

Theorem 17.3Clairaut’s theorem

Suppose that ff is defined on a disc DD that contains the point (a,b).(a, b)\mathclose{\text{.}} If the functions fxyf_{xy} and fyxf_{yx} are both continuous on D,D\mathclose{\text{,}} then fxy(a,b)=fyx(a,b).f_{xy}(a, b) = f_{yx}(a, b)\mathclose{\text{.}}

The mixed partial derivatives in Examples 17.5 and 17.6 are continuous wherever the functions are defined, so there the order of differentiation does not matter. The hypothesis cannot be dropped: Exercise 17.10 gives a function with fxy(0,0)=−1f_{xy}(0, 0) = -1 but fyx(0,0)=1.f_{yx}(0, 0) = 1\mathclose{\text{.}} The theorem extends to higher derivatives: for example, fxyy=fyxy=fyyxf_{xyy} = f_{yxy} = f_{yyx} on a disc where all partial derivatives through order 3 exist and are continuous.

Going deeperThe proof of Clairaut’s theorem

A first reading may skip this proof. It uses the Mean Value Theorem (Theorem 8.4) four times. For a small h≠0,h \ne 0\mathclose{\text{,}} so small that the square with corners (a,b)(a, b) and (a+h,b+h)(a + h, b + h) lies in D,D\mathclose{\text{,}} consider the combination of four values

Δ(h)=f(a+h,b+h)−f(a+h,b)−f(a,b+h)+f(a,b).\begin{aligned} \Delta(h) &= f(a + h, b + h) - f(a + h, b) \\ &\quad - f(a, b + h) + f(a, b). \end{aligned}

First grouping. Let G(x)=f(x,b+h)−f(x,b),G(x) = f(x, b + h) - f(x, b)\mathclose{\text{,}} so that Δ(h)=G(a+h)−G(a).\Delta(h) = G(a + h) - G(a)\mathclose{\text{.}} The partial derivative fxf_x exists on DD (it must, for fxyf_{xy} to exist there), so GG is differentiable, with G′(x)=fx(x,b+h)−fx(x,b).G'(x) = f_x(x, b + h) - f_x(x, b)\mathclose{\text{.}} By the Mean Value Theorem there is a number cc between aa and a+ha + h with

Δ(h)=h G′(c)=h(fx(c,b+h)−fx(c,b)).\begin{aligned} \Delta(h) &= h\,G'(c) \\ &= h\big(f_x(c, b + h) - f_x(c, b)\big). \end{aligned}

The function y↦fx(c,y)y \mapsto f_x(c, y) has the derivative fxy(c,y),f_{xy}(c, y)\mathclose{\text{,}} so by the Mean Value Theorem again there is a number dd between bb and b+hb + h with fx(c,b+h)−fx(c,b)=h fxy(c,d).f_x(c, b + h) - f_x(c, b) = h\,f_{xy}(c, d)\mathclose{\text{.}} So Δ(h)=h2fxy(c,d).\Delta(h) = h^2 f_{xy}(c, d)\mathclose{\text{.}}

Second grouping. Let H(y)=f(a+h,y)−f(a,y),H(y) = f(a + h, y) - f(a, y)\mathclose{\text{,}} so that Δ(h)=H(b+h)−H(b).\Delta(h) = H(b + h) - H(b)\mathclose{\text{.}} The same two steps, first in yy and then in x,x\mathclose{\text{,}} give numbers c′c' and d′,d'\mathclose{\text{,}} within ∣h∣\abs{h} of aa and b,b\mathclose{\text{,}} with Δ(h)=h2fyx(c′,d′).\Delta(h) = h^2 f_{yx}(c', d')\mathclose{\text{.}}

So fxy(c,d)=fyx(c′,d′)f_{xy}(c, d) = f_{yx}(c', d') for every small h≠0.h \ne 0\mathclose{\text{.}} As h→0,h \to 0\mathclose{\text{,}} both points (c,d)(c, d) and (c′,d′)(c', d') approach (a,b),(a, b)\mathclose{\text{,}} and since fxyf_{xy} and fyxf_{yx} are continuous there, the two sides approach fxy(a,b)f_{xy}(a, b) and fyx(a,b).f_{yx}(a, b)\mathclose{\text{.}} Equal quantities have equal limits.

Many laws of physics are equations between partial derivatives, called partial differential equations. For a thin, uniform rod insulated along its sides, with no internal heat sources, the temperature u(x,t)u(x, t) is modelled by the heat equation ut=k uxx,u_t = k\,u_{xx}\mathclose{\text{,}} with constant k>0k > 0 determined by the material. For a thin, uniform flat plate insulated on its faces, with no internal heat sources, steady temperatures satisfy Laplace’s equation uxx+uyy=0u_{xx} + u_{yy} = 0 (Exercise 17.9). Solving such equations is beyond this course, but checking a solution needs only partial derivatives: u=e−tsin⁡xu = e^{-t}\sin x satisfies the heat equation with k=1,k = 1\mathclose{\text{,}} since ut=−e−tsin⁡xu_t = -e^{-t}\sin x and uxx=−e−tsin⁡x.u_{xx} = -e^{-t}\sin x\mathclose{\text{.}}

Compute itPartial derivatives with SymPy

sp.diff takes partial derivatives: name the variable, and SymPy holds the others fixed. Several variables in a row give higher derivatives, taken in the order written:

Python
import sympy as sp
x, y = sp.symbols('x y')
f = x**3*y**2 - 5*x*y + 2*y**3                  # Example 17.5
print(sp.diff(f, x), '|', sp.diff(f, y))
print(sp.diff(f, x, y), '|', sp.diff(f, y, x))  # f_xy and f_yx
print(sp.diff(f, x).subs({x: 1, y: 2}))         # f_x(1, 2)
Output
3*x**2*y**2 - 5*y | 2*x**3*y - 5*x + 6*y**2
6*x**2*y - 5 | 6*x**2*y - 5
2

sp.diff(f, x, y) differentiates first with respect to x,x\mathclose{\text{,}} then y:y\mathclose{\text{:}} it is fxy.f_{xy}\mathclose{\text{.}} A repeated variable can be given with a count: sp.diff(f, x, 2) is fxx.f_{xx}\mathclose{\text{.}} The can from the start of this section:

Python
r, h = sp.symbols('r h', positive=True)
V = sp.pi*r**2*h
print(sp.diff(V, r), '|', sp.diff(V, h))
Vr = sp.diff(V, r).subs({r: 3, h: 10})     # V_r(3, 10)
print(Vr, '=', sp.N(Vr))
Output
2*pi*h*r | pi*r**2
60*pi = 188.495559215388

SymPy writes 2πrh2\pi rh as 2*pi*h*r, with the factors in its own order. At (3,10)(3, 10) it is 60π≈188.5,60\pi \approx 188.5\mathclose{\text{,}} the number that the first column of the table at the start of this section approaches.

4

Tangent planes and linear approximation

Zoom in on the graph of a differentiable function of one variable and it looks more and more like a straight line, its tangent line; Section 7.2 turned that into linear approximation. Zoom in on a smooth surface, and it looks more and more like a plane, its tangent plane.

Which plane? A plane through the point P(a,b,c)P(a, b, c) that is not vertical has an equation z−c=A(x−a)+B(y−b)z - c = A(x - a) + B(y - b) (Module 16). The vertical plane y=by = b cuts it along the line z−c=A(x−a),z - c = A(x - a)\mathclose{\text{,}} of slope A.A\mathclose{\text{.}} If the plane is to touch the surface at P,P\mathclose{\text{,}} this line should be the tangent line of the curve that the same vertical plane cuts out of the surface, whose slope is fx(a,b).f_x(a, b)\mathclose{\text{.}} So A=fx(a,b),A = f_x(a, b)\mathclose{\text{,}} and in the same way B=fy(a,b):B = f_y(a, b)\mathclose{\text{:}} the tangent plane is the plane through the two tangent lines of Figure 17.2.

Definition 17.6Tangent plane

Suppose that the partial derivatives of ff exist on a disc centred at (a,b)(a, b) and are continuous at (a,b).(a, b)\mathclose{\text{.}} The tangent plane to the surface z=f(x,y)z = f(x, y) at the point P(a,b,f(a,b))P(a, b, f(a, b)) is the plane

z=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b).\begin{aligned} z = f(a, b) &+ f_x(a, b)(x - a) \\ &+ f_y(a, b)(y - b). \end{aligned}

This continuity condition guarantees that the plane fits the surface in every direction, not only in the two directions of the slices. The subsection on differentiability below explains why having partial derivatives alone is not enough.

Example 17.7A tangent plane✓ Checked

Find the tangent plane to the surface z=6−x2−2y2z = 6 - x^2 - 2y^2 at P(1,1,3).P(1, 1, 3)\mathclose{\text{.}}

The partial derivatives fx=−2xf_x = -2x and fy=−4yf_y = -4y are polynomials, continuous everywhere, and at (1,1)(1, 1) they are −2-2 and −4-4 (Section 17.3). The tangent plane is

z=3−2(x−1)−4(y−1),that is,z=9−2x−4y.\begin{aligned} z &= 3 - 2(x - 1) - 4(y - 1), \\ \text{that is,}\quad z &= 9 - 2x - 4y. \end{aligned}

It passes through P:P\mathclose{\text{:}} 9−2−4=3.9 - 2 - 4 = 3\mathclose{\text{.}} The surface lies below it, because the difference is

(6−x2−2y2)−(9−2x−4y)=−(x−1)2−2(y−1)2,\begin{aligned} &(6 - x^2 - 2y^2) - (9 - 2x - 4y) \\ &\quad= -(x - 1)^2 - 2(y - 1)^2, \end{aligned}

which is negative except at (1,1).(1, 1)\mathclose{\text{.}} Like the graph of a concave down function and its tangent lines (Module 8), the surface bends away below its tangent plane (Figure 17.2, right).

The function whose graph is the tangent plane,

L(x,y)=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b),\begin{aligned} L(x, y) = f(a, b) &+ f_x(a, b)(x - a) \\ &+ f_y(a, b)(y - b), \end{aligned}

is the linearisation of ff at (a,b),(a, b)\mathclose{\text{,}} and f(x,y)≈L(x,y)f(x, y) \approx L(x, y) for (x,y)(x, y) near (a,b)(a, b) is the linear approximation of ff at (a,b).(a, b)\mathclose{\text{.}} With Δx=x−a\Delta x = x - a and Δy=y−b\Delta y = y - b it reads

f(a+Δx,b+Δy)≈f(a,b)+fx(a,b) Δx+fy(a,b) Δy:\begin{aligned} f(a + \Delta x, b + \Delta y) &\approx f(a, b) \\ &\quad + f_x(a, b)\,\Delta x \\ &\quad + f_y(a, b)\,\Delta y: \end{aligned}

each variable contributes its own rate times its own change.

Example 17.8Linear approximation of a hypotenuse✓ Checked

A right triangle with legs 3 and 4 has hypotenuse 5. Use the linearisation of f(x,y)=x2+y2f(x, y) = \sqrt{x^2 + y^2} at (3,4)(3, 4) to estimate the hypotenuse when the legs are 3.02 and 3.97.

By the chain rule, fx=xx2+y2f_x = \dfrac{x}{\sqrt{x^2 + y^2}} and fy=yx2+y2,f_y = \dfrac{y}{\sqrt{x^2 + y^2}}\mathclose{\text{,}} which are continuous wherever (x,y)≠(0,0).(x, y) \ne (0, 0)\mathclose{\text{.}} At (3,4)(3, 4) they are 35\tfrac35 and 45,\tfrac45\mathclose{\text{,}} so

L(x,y)=5+35(x−3)+45(y−4).L(x, y) = 5 + \tfrac35(x - 3) + \tfrac45(y - 4).

With Δx=0.02\Delta x = 0.02 and Δy=−0.03,\Delta y = -0.03\mathclose{\text{,}}

L(3.02,3.97)=5+0.6(0.02)+0.8(−0.03)=5+0.012−0.024=4.988.\begin{aligned} L(3.02, 3.97) &= 5 + 0.6(0.02) + 0.8(-0.03) \\ &= 5 + 0.012 - 0.024 = 4.988. \end{aligned}

A calculator gives 3.022+3.972=24.8813≈4.98812:\sqrt{3.02^2 + 3.97^2} = \sqrt{24.8813} \approx 4.98812\mathclose{\text{:}} the estimate is off by about 0.00012.

How good is the approximation in general? Move from (3,4)(3, 4) to (3+t,4−t),(3 + t, 4 - t)\mathclose{\text{,}} a distance 2 ∣t∣\sqrt2\,\abs{t} away, and compare ff with L:L\mathclose{\text{:}}

ttffLLf−Lf - Lf−L2 t\dfrac{f - L}{\sqrt2\,t}
0.10.14.981974.981974.984.980.001967480.001967480.01391220.0139122
0.010.014.998024.998024.9984.9981.96078×10−51.96078\times10^{-5}0.001386480.00138648
0.0010.0014.999804.999804.99984.99981.96008×10−71.96008\times10^{-7}0.0001385980.000138598

As in Module 7, the error f−Lf - L shrinks about a hundredfold each time the distance shrinks tenfold, so the error divided by the distance, in the last column, tends to 0: near (3,4)(3, 4) the error is small even compared with the distance from (3,4).(3, 4)\mathclose{\text{.}} That property is what makes a plane tangent.

Differentiability

Definition 17.7Differentiability

A function ff defined on a disc centred at (a,b)(a, b) is differentiable at (a,b)(a, b) if fx(a,b)f_x(a, b) and fy(a,b)f_y(a, b) exist and the error of its linearisation, E(x,y)=f(x,y)−L(x,y),E(x, y) = f(x, y) - L(x, y)\mathclose{\text{,}} satisfies

lim⁡(x,y)→(a,b)E(x,y)(x−a)2+(y−b)2=0.\lim_{(x, y)\to(a, b)}\frac{E(x, y)}{\sqrt{(x - a)^2 + (y - b)^2}} = 0.

It is differentiable on a set if it is differentiable at every point of the set.

For one variable, Theorem 7.1 showed that E(x)/(x−a)→0E(x)/(x - a) \to 0 whenever f′(a)f'(a) exists. For two variables the two partial derivatives are not enough, as the Going deeper box below shows: differentiability asks the plane to fit in every direction at once. Two theorems make the definition usable. The first is the analogue of Theorem 4.1.

Theorem 17.4Differentiable functions are continuous

If ff is differentiable at (a,b),(a, b)\mathclose{\text{,}} then ff is continuous at (a,b).(a, b)\mathclose{\text{.}}

Proof

Write ρ=(x−a)2+(y−b)2.\rho = \sqrt{(x - a)^2 + (y - b)^2}\mathclose{\text{.}} For (x,y)≠(a,b),(x, y) \ne (a, b)\mathclose{\text{,}}

f(x,y)=L(x,y)+E(x,y)ρ ρ.f(x, y) = L(x, y) + \frac{E(x, y)}{\rho}\,\rho.

As (x,y)→(a,b):(x, y) \to (a, b)\mathclose{\text{:}} L(x,y)→L(a,b)=f(a,b),L(x, y) \to L(a, b) = f(a, b)\mathclose{\text{,}} because LL is a polynomial; E/ρ→0,E/\rho \to 0\mathclose{\text{,}} by differentiability; and ρ→0.\rho \to 0\mathclose{\text{.}} So f(x,y)→f(a,b)+0⋅0=f(a,b).f(x, y) \to f(a, b) + 0 \cdot 0 = f(a, b)\mathclose{\text{.}}

∎
Theorem 17.5Continuous partial derivatives give differentiability

If fxf_x and fyf_y exist on a disc centred at (a,b)(a, b) and are continuous at (a,b),(a, b)\mathclose{\text{,}} then ff is differentiable at (a,b).(a, b)\mathclose{\text{.}}

The proof is in the Going deeper box below. Theorem 17.5 is how differentiability is checked in practice. Polynomials are differentiable everywhere, and functions such as exysin⁡ye^{xy}\sin y or ln⁡(x2+y2)\ln(x^2 + y^2) wherever they are defined: the rules give partial derivatives that are again formulas of the same kind, continuous there. The definition of the tangent plane (Definition 17.6) uses this sufficient condition. More generally, differentiability itself gives the tangent plane by the same formula, even if the partial derivatives are not continuous.

Going deeperPartial derivatives are not enough

A first reading may skip this box. Let f(x,y)=xyx2+y2f(x, y) = \dfrac{xy}{x^2 + y^2} for (x,y)≠(0,0)(x, y) \ne (0, 0) and f(0,0)=0,f(0, 0) = 0\mathclose{\text{,}} the function of Example 17.3. On both axes ff is 0, so

fx(0,0)=lim⁡h→0f(h,0)−f(0,0)h=lim⁡h→00−0h=0,\begin{aligned} f_x(0, 0) &= \lim_{h\to0}\frac{f(h, 0) - f(0, 0)}{h} \\ &= \lim_{h\to0}\frac{0 - 0}{h} = 0, \end{aligned}

and fy(0,0)=0f_y(0, 0) = 0 in the same way. Both partial derivatives exist, and the linearisation at the origin is L(x,y)=0.L(x, y) = 0\mathclose{\text{.}} But ff is not continuous at the origin (Section 17.2), so by Theorem 17.4 it is not differentiable there, and the plane z=0z = 0 is no tangent plane: along the line y=xy = x the surface stays at height 12,\tfrac12\mathclose{\text{,}} however close to the origin. The partial derivatives see only the slices along the two axes, where this surface has height 0; along the other lines through the origin it has other heights.

Proof of Theorem 17.5. Let (x,y)≠(a,b)(x, y) \ne (a, b) be in the disc, and write Δx=x−a,\Delta x = x - a\mathclose{\text{,}} Δy=y−b\Delta y = y - b and ρ=Δx2+Δy2>0.\rho = \sqrt{\Delta x^2 + \Delta y^2} > 0\mathclose{\text{.}} Go from (a,b)(a, b) to (x,y)(x, y) in two legs, first changing y,y\mathclose{\text{,}} then x:x\mathclose{\text{:}}

f(x,y)−f(a,b)=[f(x,y)−f(a,y)]+[f(a,y)−f(a,b)].\begin{aligned} f(x, y) - f(a, b) &= \big[f(x, y) - f(a, y)\big] \\ &\quad + \big[f(a, y) - f(a, b)\big]. \end{aligned}

For each nonzero leg, the Mean Value Theorem applies to ff as a function of that variable alone. The brackets are fx(c,y) Δxf_x(c, y)\,\Delta x and fy(a,d) Δy,f_y(a, d)\,\Delta y\mathclose{\text{,}} with cc between aa and xx and dd between bb and y.y\mathclose{\text{.}} If Δx=0,\Delta x = 0\mathclose{\text{,}} the first bracket is 0 and we take c=a;c = a\mathclose{\text{;}} if Δy=0,\Delta y = 0\mathclose{\text{,}} take d=bd = b for the same reason. Subtract fx(a,b) Δx+fy(a,b) Δyf_x(a, b)\,\Delta x + f_y(a, b)\,\Delta y from both sides:

E(x,y)=[fx(c,y)−fx(a,b)]Δx+[fy(a,d)−fy(a,b)]Δy.\begin{aligned} E(x, y) &= \big[f_x(c, y) - f_x(a, b)\big]\Delta x \\ &\quad + \big[f_y(a, d) - f_y(a, b)\big]\Delta y. \end{aligned}

Since ∣Δx∣≤ρ\abs{\Delta x} \le \rho and ∣Δy∣≤ρ,\abs{\Delta y} \le \rho\mathclose{\text{,}}

∣E(x,y)∣ρ≤∣fx(c,y)−fx(a,b)∣+∣fy(a,d)−fy(a,b)∣.\begin{aligned} \frac{\abs{E(x, y)}}{\rho} &\le \abs{f_x(c, y) - f_x(a, b)} \\ &\quad + \abs{f_y(a, d) - f_y(a, b)}. \end{aligned}

As (x,y)→(a,b),(x, y) \to (a, b)\mathclose{\text{,}} the points (c,y)(c, y) and (a,d)(a, d) approach (a,b)(a, b) too, so by the continuity of fxf_x and fyf_y at (a,b)(a, b) the right side tends to 0. So does ∣E∣/ρ:\abs{E}/\rho\mathclose{\text{:}} ff is differentiable at (a,b).(a, b)\mathclose{\text{.}}

The total differential

The differentials of Section 7.2 have a version for several variables.

Definition 17.8Total differential

For a differentiable function z=f(x,y),z = f(x, y)\mathclose{\text{,}} let the differentials dxdx and dydy be independent variables. The total differential of zz is

dz=fx(x,y) dx+fy(x,y) dy=∂z∂x dx+∂z∂y dy.dz = f_x(x, y)\,dx + f_y(x, y)\,dy = \frac{\partial z}{\partial x}\,dx + \frac{\partial z}{\partial y}\,dy.

When xx and yy change by dxdx and dy,dy\mathclose{\text{,}} the actual change of zz is Δz=f(x+dx,y+dy)−f(x,y),\Delta z = f(x + dx, y + dy) - f(x, y)\mathclose{\text{,}} while dzdz is the change of the linearisation; Δz≈dz\Delta z \approx dz when dxdx and dydy are small. As in Section 7.3, this propagates measurement errors, now from several measurements at once.

Example 17.9Measurement errors in a can✓ Checked

The radius and the height of a can are measured as r=3r = 3 cm and h=10h = 10 cm, with absolute errors of at most 0.02 cm in rr and 0.05 cm in h.h\mathclose{\text{.}} Estimate the largest possible absolute error in the computed volume V=πr2h,V = \pi r^2 h\mathclose{\text{,}} and the relative error.

dV=Vr dr+Vh dh=2πrh dr+πr2 dh,dV = V_r\,dr + V_h\,dh = 2\pi rh\,dr + \pi r^2\,dh\mathclose{\text{,}} and at (3,10),(3, 10)\mathclose{\text{,}} Vr=60πV_r = 60\pi and Vh=9π.V_h = 9\pi\mathclose{\text{.}} Take drdr and dhdh to be the true values minus the measured values, so dVdV estimates the error with the sign convention of Module 7. The magnitude ∣dV∣\abs{dV} is largest when both terms have the same sign and each measurement error has its largest allowed magnitude:

∣dV∣≤60π(0.02)+9π(0.05)=1.2π+0.45π=1.65π≈5.18 cm3.\begin{aligned} \abs{dV} &\le 60\pi(0.02) + 9\pi(0.05) \\ &= 1.2\pi + 0.45\pi = 1.65\pi \approx 5.18 \text{ cm}^3. \end{aligned}

So the computed volume, 90π≈282.790\pi \approx 282.7 cm³, may be off by about 5.2 cm³. This is an estimate from the tangent plane, not a bound on the exact volume error. Dividing dVdV by the measured volume V=πr2hV = \pi r^2 h gives

dVV=2πrh dr+πr2 dhπr2h=2 drr+dhh,\begin{aligned} \frac{dV}{V} &= \frac{2\pi rh\,dr + \pi r^2\,dh}{\pi r^2 h} \\ &= 2\,\frac{dr}{r} + \frac{dh}{h}, \end{aligned}

The relative error is estimated by ∣dV∣/V.\abs{dV}/V\mathclose{\text{.}} Here this estimate is at most 2⋅0.023+0.0510≈0.0133+0.005=0.0183,2 \cdot \tfrac{0.02}{3} + \tfrac{0.05}{10} \approx 0.0133 + 0.005 = 0.0183\mathclose{\text{,}} about 1.8%. In this estimate the relative error in the radius counts twice, because the radius appears squared.

Watch out

dzdz is not Δz:\Delta z\mathclose{\text{:}} dzdz is the change along the tangent plane and Δz\Delta z the change along the surface. Differentiability makes the approximation accurate for sufficiently small changes. To estimate the largest absolute error, add the sizes of the terms, ∣fx∣∣dx∣+∣fy∣∣dy∣:\abs{f_x}\abs{dx} + \abs{f_y}\abs{dy}\mathclose{\text{:}} errors in two measurements can push the result the same way. This bounds the differential; an exact error bound needs control of the remaining terms.

5

The chain rule

In one variable, rates multiply (Section 5.5). When zz depends on xx and y,y\mathclose{\text{,}} and both depend on time t,t\mathclose{\text{,}} a change in tt reaches zz by two routes, through xx and through y,y\mathclose{\text{,}} and the two contributions add.

Theorem 17.6The chain rule

Suppose that x=x(t)x = x(t) and y=y(t)y = y(t) are differentiable at t0,t_0\mathclose{\text{,}} and that z=f(x,y)z = f(x, y) is differentiable at (x(t0),y(t0)).\big(x(t_0), y(t_0)\big)\mathclose{\text{.}} Then z=f(x(t),y(t))z = f\big(x(t), y(t)\big) is differentiable at t0,t_0\mathclose{\text{,}} and

dzdt=∂z∂x dxdt+∂z∂y dydt,\frac{dz}{dt} = \frac{\partial z}{\partial x}\,\frac{dx}{dt} + \frac{\partial z}{\partial y}\,\frac{dy}{dt},

with the partial derivatives taken at (x(t0),y(t0))\big(x(t_0), y(t_0)\big) and the other derivatives at t0.t_0\mathclose{\text{.}}

Proof

Let Δt≠0,\Delta t \ne 0\mathclose{\text{,}} and let Δx,\Delta x\mathclose{\text{,}} Δy\Delta y and Δz\Delta z be the changes of x,x\mathclose{\text{,}} yy and zz when tt changes from t0t_0 to t0+Δt.t_0 + \Delta t\mathclose{\text{.}} Write ρ=Δx2+Δy2.\rho = \sqrt{\Delta x^2 + \Delta y^2}\mathclose{\text{.}} By the definition of differentiability,

Δz=fx Δx+fy Δy+E,\Delta z = f_x\,\Delta x + f_y\,\Delta y + E,

where E/ρ→0E/\rho \to 0 as (Δx,Δy)→(0,0).(\Delta x, \Delta y) \to (0, 0)\mathclose{\text{.}} Let ε=E/ρ\varepsilon = E/\rho when ρ≠0\rho \ne 0 and ε=0\varepsilon = 0 when ρ=0.\rho = 0\mathclose{\text{.}} Then E=ερE = \varepsilon\rho in both cases: if ρ=0,\rho = 0\mathclose{\text{,}} then xx and yy do not change, so neither does z,z\mathclose{\text{,}} and E=0.E = 0\mathclose{\text{.}} Divide by Δt:\Delta t\mathclose{\text{:}}

ΔzΔt=fx ΔxΔt+fy ΔyΔt+ε ρΔt.\frac{\Delta z}{\Delta t} = f_x\,\frac{\Delta x}{\Delta t} + f_y\,\frac{\Delta y}{\Delta t} + \varepsilon\,\frac{\rho}{\Delta t}.

Let Δt→0.\Delta t \to 0\mathclose{\text{.}} The quotients Δx/Δt\Delta x/\Delta t and Δy/Δt\Delta y/\Delta t tend to dx/dtdx/dt and dy/dt.dy/dt\mathclose{\text{.}} The changes Δx\Delta x and Δy\Delta y tend to 0, because differentiable functions are continuous, so ε→0;\varepsilon \to 0\mathclose{\text{;}} and ∣ρ/Δt∣=(Δx/Δt)2+(Δy/Δt)2\abs{\rho/\Delta t} = \sqrt{(\Delta x/\Delta t)^2 + (\Delta y/\Delta t)^2} stays bounded, since it tends to (dx/dt)2+(dy/dt)2.\sqrt{(dx/dt)^2 + (dy/dt)^2}\mathclose{\text{.}} So the last term tends to 0, and Δz/Δt\Delta z/\Delta t tends to fx dxdt+fy dydt.f_x\,\dfrac{dx}{dt} + f_y\,\dfrac{dy}{dt}\mathclose{\text{.}}

∎
Example 17.10A changing cylinder✓ Checked

The radius of a cylinder grows at 0.1 cm/s while its height shrinks at 0.3 cm/s. At the moment when r=3r = 3 cm and h=10h = 10 cm, is the volume growing or shrinking, and how fast?

By Theorem 17.6,

dVdt=∂V∂r drdt+∂V∂h dhdt=2πrh drdt+πr2 dhdt.\begin{aligned} \frac{dV}{dt} &= \frac{\partial V}{\partial r}\,\frac{dr}{dt} + \frac{\partial V}{\partial h}\,\frac{dh}{dt} \\ &= 2\pi rh\,\frac{dr}{dt} + \pi r^2\,\frac{dh}{dt}. \end{aligned}

At this moment ∂V/∂r=60π,\partial V/\partial r = 60\pi\mathclose{\text{,}} ∂V/∂h=9π,\partial V/\partial h = 9\pi\mathclose{\text{,}} dr/dt=0.1dr/dt = 0.1 and dh/dt=−0.3,dh/dt = -0.3\mathclose{\text{,}} so

dVdt=60π(0.1)+9π(−0.3)=6π−2.7π=3.3π≈10.37 cm3/s.\begin{aligned} \frac{dV}{dt} &= 60\pi(0.1) + 9\pi(-0.3) = 6\pi - 2.7\pi \\ &= 3.3\pi \approx 10.37 \text{ cm}^3/\text{s}. \end{aligned}

The volume is growing. The height shrinks three times as fast as the radius grows, but the volume is more than six times as sensitive to the radius.

Tree diagrams

With more variables, a tree diagram keeps track of the routes (Figure 17.3). Put the dependent variable at the top, the intermediate variables below it and the independent variables at the bottom, and join each variable to the variables it depends on directly. Label each branch with the derivative of the upper variable with respect to the lower one.

Key idea

The derivative of the top variable with respect to a bottom variable is the sum, over all paths from the top down to that variable, of the products of the labels along each path.

Tree diagrams for the chain rule. Left: z = f(x, y), with x and y functions of t; the two paths from z down to t give the two terms of Theorem 17.6. Right: x and y functions of s and t; the two coloured paths from z to s give partial z/partial s, and the two paths to t give partial z/partial t in the same way.
Figure 17.3

Tree diagrams for the chain rule. Left: z=f(x,y),z = f(x, y)\mathclose{\text{,}} with xx and yy functions of t;t\mathclose{\text{;}} the two paths from zz down to tt give the two terms of Theorem 17.6. Right: xx and yy functions of ss and t;t\mathclose{\text{;}} the two coloured paths from zz to ss give ∂z/∂s,\partial z/\partial s\mathclose{\text{,}} and the two paths to tt give ∂z/∂t\partial z/\partial t in the same way.

When xx and yy depend on two variables ss and t,t\mathclose{\text{,}} hold tt fixed: then xx and yy are functions of ss alone, and Theorem 17.6 applies with ss in place of t.t\mathclose{\text{.}} Derivatives with respect to ss with tt held fixed are partial derivatives, so:

Theorem 17.7The chain rule with two parameters

Suppose that x=x(s,t)x = x(s, t) and y=y(s,t)y = y(s, t) have partial derivatives at (s,t),(s, t)\mathclose{\text{,}} and that z=f(x,y)z = f(x, y) is differentiable at (x(s,t),y(s,t)).\big(x(s, t), y(s, t)\big)\mathclose{\text{.}} Then

∂z∂s=∂z∂x ∂x∂s+∂z∂y ∂y∂s,∂z∂t=∂z∂x ∂x∂t+∂z∂y ∂y∂t.\begin{aligned} \frac{\partial z}{\partial s} &= \frac{\partial z}{\partial x}\,\frac{\partial x}{\partial s} + \frac{\partial z}{\partial y}\,\frac{\partial y}{\partial s}, \\ \frac{\partial z}{\partial t} &= \frac{\partial z}{\partial x}\,\frac{\partial x}{\partial t} + \frac{\partial z}{\partial y}\,\frac{\partial y}{\partial t}. \end{aligned}

The same proof, with more terms, gives the general rule of the key idea. Differentiability is defined for nn variables as for two, with the distance in nn dimensions; if uu is a differentiable function of x1,…,xn,x_1, \dots, x_n\mathclose{\text{,}} each of which has partial derivatives with respect to t1,…,tm,t_1, \dots, t_m\mathclose{\text{,}} then for each ii

∂u∂ti=∂u∂x1∂x1∂ti+∂u∂x2∂x2∂ti+⋯+∂u∂xn∂xn∂ti.\frac{\partial u}{\partial t_i} = \frac{\partial u}{\partial x_1}\frac{\partial x_1}{\partial t_i} + \frac{\partial u}{\partial x_2}\frac{\partial x_2}{\partial t_i} + \dots + \frac{\partial u}{\partial x_n}\frac{\partial x_n}{\partial t_i}.
Example 17.11Polar coordinates✓ Checked

Let z=x2y,z = x^2y\mathclose{\text{,}} where x=rcos⁡θx = r\cos\theta and y=rsin⁡θy = r\sin\theta are given by polar coordinates (Module 16). Find ∂z/∂r\partial z/\partial r and ∂z/∂θ\partial z/\partial\theta at r=2,r = 2\mathclose{\text{,}} θ=π/6,\theta = \pi/6\mathclose{\text{,}} and check by substituting first.

The tree is the right-hand one of Figure 17.3, with rr and θ\theta in place of ss and t.t\mathclose{\text{.}} The labels are zx=2xy,z_x = 2xy\mathclose{\text{,}} zy=x2,z_y = x^2\mathclose{\text{,}} xr=cos⁡θ,x_r = \cos\theta\mathclose{\text{,}} yr=sin⁡θ,y_r = \sin\theta\mathclose{\text{,}} xθ=−rsin⁡θx_\theta = -r\sin\theta and yθ=rcos⁡θ,y_\theta = r\cos\theta\mathclose{\text{,}} so

∂z∂r=2xycos⁡θ+x2sin⁡θ,∂z∂θ=−2xy rsin⁡θ+x2 rcos⁡θ.\begin{aligned} \frac{\partial z}{\partial r} &= 2xy\cos\theta + x^2\sin\theta, \\ \frac{\partial z}{\partial \theta} &= -2xy\,r\sin\theta + x^2\,r\cos\theta. \end{aligned}

At r=2r = 2 and θ=π/6,\theta = \pi/6\mathclose{\text{,}} x=2cos⁡π6=3x = 2\cos\frac{\pi}{6} = \sqrt3 and y=2sin⁡π6=1,y = 2\sin\frac{\pi}{6} = 1\mathclose{\text{,}} so

∂z∂r=23⋅32+3⋅12=3+32=92,∂z∂θ=−23⋅2⋅12+3⋅2⋅32=−23+33=3.\begin{aligned} \frac{\partial z}{\partial r} &= 2\sqrt3\cdot\frac{\sqrt3}{2} + 3\cdot\frac12 = 3 + \frac32 = \frac92, \\ \frac{\partial z}{\partial \theta} &= -2\sqrt3\cdot 2\cdot\frac12 + 3\cdot 2\cdot\frac{\sqrt3}{2} \\ &= -2\sqrt3 + 3\sqrt3 = \sqrt3. \end{aligned}

Check: substituting first, z=r3cos⁡2θsin⁡θ,z = r^3\cos^2\theta\sin\theta\mathclose{\text{,}} so ∂z/∂r=3r2cos⁡2θsin⁡θ=3⋅4⋅34⋅12=92.\partial z/\partial r = 3r^2\cos^2\theta\sin\theta = 3 \cdot 4 \cdot \tfrac34 \cdot \tfrac12 = \tfrac92\mathclose{\text{.}} Also ∂z/∂θ=r3cos⁡θ(cos⁡2θ−2sin⁡2θ),\partial z/\partial\theta = r^3\cos\theta(\cos^2\theta - 2\sin^2\theta)\mathclose{\text{,}} which at the given point is 8⋅32(34−12)=3.8\cdot\tfrac{\sqrt3}{2}(\tfrac34 - \tfrac12) = \sqrt3\mathclose{\text{.}} The chain rule needs no such substitution, which for a complicated ff may be impractical.

Watch out

Every path contributes. A common slip is to write ∂z∂s=∂z∂x∂x∂s,\dfrac{\partial z}{\partial s} = \dfrac{\partial z}{\partial x}\dfrac{\partial x}{\partial s}\mathclose{\text{,}} as if the ∂x\partial x's cancelled, and to forget the path through y.y\mathclose{\text{.}} Partial derivatives are not fractions, and with two intermediate variables the chain rule has two terms.

Implicit differentiation

Section 6.4 found slopes of curves such as the circle x2+y2=25x^2 + y^2 = 25 by differentiating their equations. The chain rule explains the method and turns it into a formula. Write the curve as F(x,y)=0,F(x, y) = 0\mathclose{\text{,}} with FF differentiable near the point in question, and suppose that near that point the curve is the graph of a differentiable function y=y(x).y = y(x)\mathclose{\text{.}} Then F(x,y(x))=0F\big(x, y(x)\big) = 0 for all xx near the point. Differentiate with respect to xx by Theorem 17.6, with xx itself as the first intermediate variable (dx/dx=1):dx/dx = 1\mathclose{\text{):}}

Fx+Fy dydx=0,sodydx=−FxFy(Fy≠0).F_x + F_y\,\frac{dy}{dx} = 0, \quad\text{so}\quad \frac{dy}{dx} = -\frac{F_x}{F_y} \quad (F_y \ne 0).

Module 6 promised a theorem that guarantees the function y(x)y(x) whenever the coefficient of dy/dx,dy/dx\mathclose{\text{,}} here Fy,F_y\mathclose{\text{,}} is not 0:

Theorem 17.8The implicit function theorem

Suppose that FF has continuous partial derivatives on a disc centred at (a,b),(a, b)\mathclose{\text{,}} that F(a,b)=0,F(a, b) = 0\mathclose{\text{,}} and that Fy(a,b)≠0.F_y(a, b) \ne 0\mathclose{\text{.}} Then near (a,b)(a, b) the points of the curve F(x,y)=0F(x, y) = 0 form the graph of a differentiable function y=y(x),y = y(x)\mathclose{\text{,}} defined on an open interval containing a,a\mathclose{\text{,}} with y(a)=by(a) = b and

dydx=−Fx(x,y)Fy(x,y).\frac{dy}{dx} = -\frac{F_x(x, y)}{F_y(x, y)}.

Its proof belongs to a course in analysis; this series uses the theorem without proof.

Example 17.12The folium of Descartes again✓ Checked

Find dy/dxdy/dx on the folium x3+y3=6xyx^3 + y^3 = 6xy of Example 6.5 with the formula, and the slope at (3,3).(3, 3)\mathclose{\text{.}}

Write the curve as F(x,y)=x3+y3−6xy=0.F(x, y) = x^3 + y^3 - 6xy = 0\mathclose{\text{.}} Then Fx=3x2−6yF_x = 3x^2 - 6y and Fy=3y2−6x,F_y = 3y^2 - 6x\mathclose{\text{,}} so where y2≠2x,y^2 \ne 2x\mathclose{\text{,}}

dydx=−3x2−6y3y2−6x=2y−x2y2−2x,\frac{dy}{dx} = -\frac{3x^2 - 6y}{3y^2 - 6x} = \frac{2y - x^2}{y^2 - 2x},

the answer of Example 6.5. At (3,3),(3, 3)\mathclose{\text{,}} Fy=27−18=9≠0,F_y = 27 - 18 = 9 \ne 0\mathclose{\text{,}} and the slope is 6−99−6=−1.\dfrac{6 - 9}{9 - 6} = -1\mathclose{\text{.}} At the origin Fx=Fy=0:F_x = F_y = 0\mathclose{\text{:}} the implicit function theorem says nothing there, and indeed the curve crosses itself.

In the same way, if FF has continuous partial derivatives near a point on F(x,y,z)=0F(x, y, z) = 0 and Fz≠0F_z \ne 0 there, the equation defines zz as a differentiable function of xx and yy near that point (the theorem has a version for three variables). Holding yy fixed and differentiating F(x,y,z(x,y))=0F\big(x, y, z(x, y)\big) = 0 with respect to xx gives Fx+Fz ∂z∂x=0,F_x + F_z\,\dfrac{\partial z}{\partial x} = 0\mathclose{\text{,}} and similarly for y:y\mathclose{\text{:}}

∂z∂x=−FxFz,∂z∂y=−FyFz.\frac{\partial z}{\partial x} = -\frac{F_x}{F_z}, \qquad \frac{\partial z}{\partial y} = -\frac{F_y}{F_z}.

Example 17.14 uses these formulas.

6

Directional derivatives and the gradient

Stand on a hillside. How steep the ground is depends on which way you face: straight up the slope it is steep, along the slope it is level. The partial derivatives fxf_x and fyf_y give the slopes in two directions only, east and north on a map. This section finds the slope in every direction, and the direction in which it is steepest.

Definition 17.9Directional derivative

Let u=⟨u1,u2⟩\vb{u} = \langle u_1, u_2\rangle be a unit vector. The directional derivative of ff at (a,b)(a, b) in the direction of u\vb{u} is

Duf(a,b)=lim⁡h→0f(a+hu1,b+hu2)−f(a,b)h,D_{\vb{u}} f(a, b) = \lim_{h\to0}\frac{f(a + hu_1, b + hu_2) - f(a, b)}{h},

provided that the limit exists.

DufD_{\vb{u}} f reads “D sub u of f”. The point (a+hu1,b+hu2)(a + hu_1, b + hu_2) lies on the line through (a,b)(a, b) in the direction of u,\vb{u}\mathclose{\text{,}} at a distance ∣h∣\abs{h} from (a,b),(a, b)\mathclose{\text{,}} because ∥u∥=1;\norm{\vb{u}} = 1\mathclose{\text{;}} so Duf(a,b)D_{\vb{u}} f(a, b) is the rate of change of ff per unit of distance as you move from (a,b)(a, b) in that direction. For u=i=⟨1,0⟩\vb{u} = \vb{i} = \langle 1, 0\rangle it is fx(a,b),f_x(a, b)\mathclose{\text{,}} and for u=j=⟨0,1⟩\vb{u} = \vb{j} = \langle 0, 1\rangle it is fy(a,b).f_y(a, b)\mathclose{\text{.}}

Definition 17.10Gradient

Provided that its partial derivatives exist, the gradient of ff at (a,b)(a, b) is the vector

∇f(a,b)=⟨fx(a,b),fy(a,b)⟩.\nabla f(a, b) = \big\langle f_x(a, b), f_y(a, b)\big\rangle.

For a function of three variables, ∇f=⟨fx,fy,fz⟩.\nabla f = \langle f_x, f_y, f_z\rangle\mathclose{\text{.}}

The symbol ∇\nabla is called “nabla”, and ∇f\nabla f reads “del f” or “grad f”. The gradient of a function of two variables is a vector in the plane of its domain; when nonzero, it gives a direction on the contour map. If ff is differentiable at (a,b),(a, b)\mathclose{\text{,}} the linear approximation of Section 17.4 reads f(a+Δx,b+Δy)≈f(a,b)+∇f(a,b)⋅⟨Δx,Δy⟩,f(a + \Delta x, b + \Delta y) \approx f(a, b) + \nabla f(a, b)\cdot\langle\Delta x, \Delta y\rangle\mathclose{\text{,}} with the dot product of Module 16. Directional derivatives come from the gradient in the same way.

Theorem 17.9Directional derivatives from the gradient

If ff is differentiable at (a,b),(a, b)\mathclose{\text{,}} then ff has a directional derivative at (a,b)(a, b) in the direction of every unit vector u=⟨u1,u2⟩,\vb{u} = \langle u_1, u_2\rangle\mathclose{\text{,}} and

Duf(a,b)=∇f(a,b)⋅u=fx(a,b) u1+fy(a,b) u2.\begin{aligned} D_{\vb{u}} f(a, b) &= \nabla f(a, b)\cdot\vb{u} \\ &= f_x(a, b)\,u_1 + f_y(a, b)\,u_2. \end{aligned}
Proof

Let g(h)=f(a+hu1,b+hu2).g(h) = f(a + hu_1, b + hu_2)\mathclose{\text{.}} The limit that defines Duf(a,b)D_{\vb{u}} f(a, b) is lim⁡h→0g(h)−g(0)h=g′(0).\lim_{h\to0}\dfrac{g(h) - g(0)}{h} = g'(0)\mathclose{\text{.}} Here gg is ff composed with x(h)=a+hu1x(h) = a + hu_1 and y(h)=b+hu2,y(h) = b + hu_2\mathclose{\text{,}} whose derivatives are u1u_1 and u2.u_2\mathclose{\text{.}} By the chain rule (Theorem 17.6), g′(0)g'(0) exists and

g′(0)=fx(a,b) u1+fy(a,b) u2=∇f(a,b)⋅u.\begin{aligned} g'(0) &= f_x(a, b)\,u_1 + f_y(a, b)\,u_2 \\ &= \nabla f(a, b)\cdot\vb{u}. \end{aligned}
∎
Example 17.13A directional derivative✓ Checked

Let f(x,y)=xey.f(x, y) = xe^y\mathclose{\text{.}} Find the rate of change of ff at (2,0)(2, 0) in the direction of the point (5,4).(5, 4)\mathclose{\text{.}}

fx=eyf_x = e^y and fy=xeyf_y = xe^y are continuous, so ff is differentiable (Theorem 17.5), and ∇f(2,0)=⟨e0,2e0⟩=⟨1,2⟩.\nabla f(2, 0) = \langle e^0, 2e^0\rangle = \langle 1, 2\rangle\mathclose{\text{.}} The direction from (2,0)(2, 0) to (5,4)(5, 4) is v=⟨3,4⟩,\vb{v} = \langle 3, 4\rangle\mathclose{\text{,}} of length 5, so the unit vector in that direction is u=v/∥v∥=⟨35,45⟩.\vb{u} = \vb{v}/\norm{\vb{v}} = \big\langle \tfrac35, \tfrac45\big\rangle\mathclose{\text{.}} By Theorem 17.9,

Duf(2,0)=⟨1,2⟩⋅⟨35,45⟩=35+85=115=2.2.\begin{aligned} D_{\vb{u}} f(2, 0) &= \langle 1, 2\rangle\cdot\big\langle \tfrac35, \tfrac45\big\rangle \\ &= \frac35 + \frac85 = \frac{11}{5} = 2.2. \end{aligned}

Moving from (2,0)(2, 0) towards (5,4),(5, 4)\mathclose{\text{,}} ff increases at 2.2 units per unit of distance, faster than along either axis (fx=1,f_x = 1\mathclose{\text{,}} fy=2).f_y = 2\mathclose{\text{).}}

Steepest ascent

Theorem 17.10The direction of steepest ascent

Let ff be differentiable at (a,b),(a, b)\mathclose{\text{,}} with ∇f(a,b)≠0.\nabla f(a, b) \ne \vb{0}\mathclose{\text{.}} Among all unit vectors u,\vb{u}\mathclose{\text{,}} the directional derivative Duf(a,b)D_{\vb{u}} f(a, b)

  • is largest, equal to ∥∇f(a,b)∥,\norm{\nabla f(a, b)}\mathclose{\text{,}} when u\vb{u} points in the direction of ∇f(a,b);\nabla f(a, b)\mathclose{\text{;}}
  • is smallest, equal to −∥∇f(a,b)∥,-\norm{\nabla f(a, b)}\mathclose{\text{,}} when u\vb{u} points in the opposite direction;
  • is 0 when u\vb{u} is perpendicular to ∇f(a,b).\nabla f(a, b)\mathclose{\text{.}}
Proof

Let θ\theta be the angle between ∇f(a,b)\nabla f(a, b) and u.\vb{u}\mathclose{\text{.}} By Theorem 17.9 and the angle form of the dot product (Module 16),

Duf(a,b)=∇f(a,b)⋅u=∥∇f(a,b)∥ ∥u∥cos⁡θ=∥∇f(a,b)∥cos⁡θ,\begin{aligned} D_{\vb{u}} f(a, b) &= \nabla f(a, b)\cdot\vb{u} \\ &= \norm{\nabla f(a, b)}\,\norm{\vb{u}}\cos\theta \\ &= \norm{\nabla f(a, b)}\cos\theta, \end{aligned}

since ∥u∥=1.\norm{\vb{u}} = 1\mathclose{\text{.}} As u\vb{u} turns, only cos⁡θ\cos\theta changes. It is largest, 1, exactly when θ=0;\theta = 0\mathclose{\text{;}} smallest, −1,-1\mathclose{\text{,}} exactly when θ=π;\theta = \pi\mathclose{\text{;}} and 0 when θ=π/2.\theta = \pi/2\mathclose{\text{.}}

∎

So a nonzero gradient points uphill, in the steepest direction, and its length is the slope in that direction. For f(x,y)=xeyf(x, y) = xe^y at (2,0)(2, 0) (Example 17.13), the steepest rate is ∥⟨1,2⟩∥=5≈2.236,\norm{\langle 1, 2\rangle} = \sqrt5 \approx 2.236\mathclose{\text{,}} in the direction ⟨1,2⟩/5.\langle 1, 2\rangle/\sqrt5\mathclose{\text{.}} The rate 2.2 towards (5,4)(5, 4) comes close to it because ⟨3,4⟩\langle 3, 4\rangle points within about 10.3∘10.3^\circ of ⟨1,2⟩\langle 1, 2\rangle (cos⁡θ=2.2/5).\cos\theta = 2.2/\sqrt5\mathclose{\text{).}} The fastest decrease, at the rate −5,-\sqrt5\mathclose{\text{,}} is in the direction ⟨−1,−2⟩/5,\langle -1, -2\rangle/\sqrt5\mathclose{\text{,}} and the rate of change is 0 in the directions ±⟨2,−1⟩/5.\pm\langle 2, -1\rangle/\sqrt5\mathclose{\text{.}} Section 17.7 uses steps along −∇f-\nabla f to seek smaller values of f.f\mathclose{\text{.}} If the gradient is 0,\vb{0}\mathclose{\text{,}} every directional derivative is 0 and there is no unique steepest direction.

Gradients and level curves

Along the level curve through (a,b),(a, b)\mathclose{\text{,}} ff does not change at all, so its rate of change along the curve should be 0. By Theorem 17.10, that happens in the directions perpendicular to the gradient.

Theorem 17.11The gradient is perpendicular to level curves

Let ff be differentiable at (a,b),(a, b)\mathclose{\text{,}} and let r(t)=⟨x(t),y(t)⟩\vb{r}(t) = \langle x(t), y(t)\rangle be a curve that lies on the level curve f(x,y)=kf(x, y) = k through (a,b),(a, b)\mathclose{\text{,}} with r(t0)=⟨a,b⟩,\vb{r}(t_0) = \langle a, b\rangle\mathclose{\text{,}} differentiable at t0t_0 with r′(t0)≠0.\vb{r}'(t_0) \ne \vb{0}\mathclose{\text{.}} Then

∇f(a,b)⋅r′(t0)=0:\nabla f(a, b)\cdot\vb{r}'(t_0) = 0:

when the gradient is nonzero, it is perpendicular to the tangent vector of the level curve. A zero gradient satisfies the same dot-product identity but supplies no normal direction.

Proof

For every t,t\mathclose{\text{,}} f(x(t),y(t))=k.f\big(x(t), y(t)\big) = k\mathclose{\text{.}} Differentiate both sides at t0,t_0\mathclose{\text{,}} with the chain rule on the left: fx(a,b) x′(t0)+fy(a,b) y′(t0)=0,f_x(a, b)\,x'(t_0) + f_y(a, b)\,y'(t_0) = 0\mathclose{\text{,}} that is, ∇f(a,b)⋅r′(t0)=0.\nabla f(a, b)\cdot\vb{r}'(t_0) = 0\mathclose{\text{.}}

∎

So on a contour map the gradient at each point, where it is not 0,\vb{0}\mathclose{\text{,}} is perpendicular to the contour through the point and points towards higher values. When contours represent equally spaced values, closely spaced contours indicate a large gradient, and widely spaced contours a small one (Figure 17.4, left). For f(x,y)=x2+y2,f(x, y) = x^2 + y^2\mathclose{\text{,}} ∇f=⟨2x,2y⟩\nabla f = \langle 2x, 2y\rangle points straight away from the origin, across the circles x2+y2=kx^2 + y^2 = k at right angles, and its length 2x2+y22\sqrt{x^2 + y^2} grows with the distance from the origin, where circles for equally spaced positive values of kk crowd together.

Left: the contour map of Figure 17.1, with the gradient at points of three level curves, drawn at 0.13 of its length. Each arrow crosses its level curve at a right angle and points uphill; the arrows are longest where the contours crowd together. Right: gradient descent (Section 17.7) on f(x, y) = x^2 + 3y^2 from (3, 1). With the step size eta = 0.1 (blue) the points slide smoothly into the valley; with eta = 0.3 (orange) they zigzag across it, overshooting in the steep y-direction.
Figure 17.4

Left: the contour map of Figure 17.1, with the gradient at points of three level curves, drawn at 0.13 of its length. Each arrow crosses its level curve at a right angle and points uphill; the arrows are longest where the contours crowd together. Right: gradient descent (Section 17.7) on f(x,y)=x2+3y2f(x, y) = x^2 + 3y^2 from (3,1).(3, 1)\mathclose{\text{.}} With the step size η=0.1\eta = 0.1 (blue) the points slide smoothly into the valley; with η=0.3\eta = 0.3 (orange) they zigzag across it, overshooting in the steep yy-direction.

Try it

Choose a function, then click the map, or set xx and yy with the sliders, to pick a point. The red arrow shows a numerical estimate of the gradient, drawn to a scale; the readout gives the estimated length ∥∇f∥.\norm{\nabla f}\mathclose{\text{.}} The green arrow is the unit vector u,\vb{u}\mathclose{\text{,}} at the angle set by its slider; the purple curve is the level curve through the point. For a function differentiable near the chosen point, with nonzero gradient, turn u\vb{u} and watch the estimate of Duf=∇f⋅u:D_{\vb{u}} f = \nabla f\cdot\vb{u}\mathclose{\text{:}} largest when u\vb{u} points along ∇f,\nabla f\mathclose{\text{,}} smallest when it points the opposite way, 0 tangent to the level curve. With x2+y2,x^2 + y^2\mathclose{\text{,}} every nonzero gradient points away from the origin. On the landscape of Figure 17.1, pick a point near a pass at (±1,0),(\pm1, 0)\mathclose{\text{,}} where ∇f\nabla f is almost 0.\vb{0}\mathclose{\text{.}} Then type x e^y, pick the point (2,0)(2, 0) and set the angle to 53∘,53^\circ\mathclose{\text{,}} close to the direction of ⟨3,4⟩:\langle 3, 4\rangle\mathclose{\text{:}} the readout is about 2.199, close to the value 2.2 in Example 17.13.

Level surfaces and tangent planes

The same results hold for differentiable functions of three variables, with ∇f=⟨fx,fy,fz⟩\nabla f = \langle f_x, f_y, f_z\rangle and unit vectors u\vb{u} in space: Duf=∇f⋅u,D_{\vb{u}} f = \nabla f\cdot\vb{u}\mathclose{\text{,}} a nonzero gradient points in the direction of steepest ascent, and, by the proof of Theorem 17.11 with three variables, it is perpendicular to the tangent vector of every differentiable curve through the point that lies on the level surface. A plane is fixed by a point and a nonzero normal vector (Module 16), so the gradient gives tangent planes to regular level surfaces.

Definition 17.11Tangent plane to a level surface

Let FF have continuous partial derivatives in a neighbourhood of a point P(x0,y0,z0)P(x_0, y_0, z_0) of the level set F(x,y,z)=k,F(x, y, z) = k\mathclose{\text{,}} with ∇F(P)≠0.\nabla F(P) \ne \vb{0}\mathclose{\text{.}} The implicit function theorem ensures that this level set is locally a surface. Its tangent plane at PP is the plane through PP with normal vector ∇F(P):\nabla F(P)\mathclose{\text{:}}

Fx(P)(x−x0)+Fy(P)(y−y0)+Fz(P)(z−z0)=0.\begin{aligned} &F_x(P)(x - x_0) + F_y(P)(y - y_0) \\ &\quad + F_z(P)(z - z_0) = 0. \end{aligned}

For ff with continuous partial derivatives, the graph z=f(x,y)z = f(x, y) is the level surface F(x,y,z)=f(x,y)−z=0,F(x, y, z) = f(x, y) - z = 0\mathclose{\text{,}} with ∇F=⟨fx,fy,−1⟩;\nabla F = \langle f_x, f_y, -1\rangle\mathclose{\text{;}} at P(a,b,c)P(a, b, c) Definition 17.11 gives fx(a,b)(x−a)+fy(a,b)(y−b)−(z−c)=0,f_x(a, b)(x - a) + f_y(a, b)(y - b) - (z - c) = 0\mathclose{\text{,}} the tangent plane of Definition 17.6 again.

Example 17.14A tangent plane to a level surface✓ Checked

Find the tangent plane to the surface x2+2y2+3z2=6x^2 + 2y^2 + 3z^2 = 6 at P(1,1,1),P(1, 1, 1)\mathclose{\text{,}} and the partial derivatives ∂z/∂x\partial z/\partial x and ∂z/∂y\partial z/\partial y there.

The point is on the surface, since 1+2+3=6.1 + 2 + 3 = 6\mathclose{\text{.}} With F(x,y,z)=x2+2y2+3z2,F(x, y, z) = x^2 + 2y^2 + 3z^2\mathclose{\text{,}} ∇F=⟨2x,4y,6z⟩,\nabla F = \langle 2x, 4y, 6z\rangle\mathclose{\text{,}} so ∇F(1,1,1)=⟨2,4,6⟩,\nabla F(1, 1, 1) = \langle 2, 4, 6\rangle\mathclose{\text{,}} and the tangent plane is

2(x−1)+4(y−1)+6(z−1)=0,that is,x+2y+3z=6.\begin{aligned} 2(x - 1) + 4(y - 1) + 6(z - 1) &= 0, \\ \text{that is,}\quad x + 2y + 3z &= 6. \end{aligned}

By implicit differentiation (Section 17.5), ∂z∂x=−FxFz=−26=−13\dfrac{\partial z}{\partial x} = -\dfrac{F_x}{F_z} = -\dfrac{2}{6} = -\dfrac13 and ∂z∂y=−FyFz=−46=−23.\dfrac{\partial z}{\partial y} = -\dfrac{F_y}{F_z} = -\dfrac46 = -\dfrac23\mathclose{\text{.}} The two answers agree: solved for z,z\mathclose{\text{,}} the tangent plane is z=2−13x−23y,z = 2 - \tfrac13 x - \tfrac23 y\mathclose{\text{,}} with exactly these slopes.

Watch out

A directional derivative needs a unit vector. With v=⟨3,4⟩\vb{v} = \langle 3, 4\rangle in place of u\vb{u} in Example 17.13, ∇f⋅v=11,\nabla f\cdot\vb{v} = 11\mathclose{\text{,}} five times too large, because v\vb{v} has length 5: divide by the length first. And ∇f\nabla f is a vector, not a number; its length ∥∇f∥\norm{\nabla f} is the steepest slope.

Compute itGradients with SymPy and NumPy

A SymPy Matrix holds a gradient; .dot takes dot products and .norm() lengths. Example 17.13 again:

Python
import sympy as sp
x, y = sp.symbols('x y')
f = x*sp.exp(y)
grad = sp.Matrix([sp.diff(f, x), sp.diff(f, y)])
g = grad.subs({x: 2, y: 0})
u = sp.Matrix([3, 4])/5
print(grad.T, '|', g.T, '|', g.dot(u), '|', g.norm())
Output
Matrix([[exp(y), x*exp(y)]]) | Matrix([[1, 2]]) | 11/5 | sqrt(5)

.T turns the column of the gradient into a row for printing: ∇f=⟨ey,xey⟩,\nabla f = \langle e^y, xe^y\rangle\mathclose{\text{,}} then ⟨1,2⟩\langle 1, 2\rangle at (2,0),(2, 0)\mathclose{\text{,}} Duf=115D_{\vb{u}} f = \tfrac{11}{5} and ∥∇f∥=5.\norm{\nabla f} = \sqrt5\mathclose{\text{.}}

Theorem 17.10 says that no direction beats ∥∇f∥=5.\norm{\nabla f} = \sqrt5\mathclose{\text{.}} Try 720 directions, every half degree, with NumPy:

Python
import numpy as np
gx, gy = 1.0, 2.0                               # grad f(2, 0)
alpha = np.radians(np.arange(0, 360, 0.5))      # the angles of u = <cos a, sin a>
D = gx*np.cos(alpha) + gy*np.sin(alpha)         # D_u f for each direction
k = np.argmax(D)
print(f"largest D_u f: {D[k]:.6f}, at {np.degrees(alpha[k])} degrees")
angle = np.degrees(np.arctan2(gy, gx))           # the direction of grad f
print(f"|grad f| = {np.hypot(gx, gy):.6f}, at {angle:.4f} degrees")
Output
largest D_u f: 2.236067, at 63.50000000000001 degrees
|grad f| = 2.236068, at 63.4349 degrees

The best of the 720 directions, at 63.5∘,63.5^\circ\mathclose{\text{,}} is the one nearest to the direction of the gradient, 63.4349∘,63.4349^\circ\mathclose{\text{,}} and its rate falls short of ∥∇f∥\norm{\nabla f} only in the sixth decimal place. (The digits 00000000000001 are floating-point rounding, from converting radians back to degrees.)

7

Gradient descent

Section 8.7 minimised functions of one variable by stepping against the derivative, xk+1=xk−ηf′(xk).x_{k+1} = x_k - \eta f'(x_k)\mathclose{\text{.}} In several variables the gradient takes the place of the derivative, and Theorem 17.10 says which way to step: along −∇f,-\nabla f\mathclose{\text{,}} the direction of steepest descent.

Definition 17.12Gradient descent

To minimise a differentiable function ff of two (or more) variables, choose a starting point x0\vb{x}_0 and a step size η>0\eta > 0 (the learning rate), and compute

xk+1=xk−η ∇f(xk),k=0,1,2,…\vb{x}_{k+1} = \vb{x}_k - \eta\,\nabla f(\vb{x}_k), \qquad k = 0, 1, 2, \dots

Here xk=⟨xk,yk⟩\vb{x}_k = \langle x_k, y_k\rangle is the kkth point, written as a vector, and f(xk)f(\vb{x}_k) means f(xk,yk).f(x_k, y_k)\mathclose{\text{.}} The iteration requires each new point to remain in the domain of f.f\mathclose{\text{.}}

When the gradient is nonzero, each step moves in the direction of steepest descent, a distance η∥∇f(xk)∥:\eta\norm{\nabla f(\vb{x}_k)}\mathclose{\text{:}} long steps where the surface is steep, short ones where it is flat. By the linear approximation in its gradient form (Section 17.6),

f(xk+1)≈f(xk)+∇f(xk)⋅(xk+1−xk)=f(xk)−η∥∇f(xk)∥2,\begin{aligned} f(\vb{x}_{k+1}) &\approx f(\vb{x}_k) + \nabla f(\vb{x}_k)\cdot(\vb{x}_{k+1} - \vb{x}_k) \\ &= f(\vb{x}_k) - \eta\norm{\nabla f(\vb{x}_k)}^2, \end{aligned}

The predicted change is negative when ∇f(xk)≠0.\nabla f(\vb{x}_k) \ne \vb{0}\mathclose{\text{.}} Differentiability makes the error divided by the step length tend to 0; at a fixed such point, for sufficiently small η>0\eta > 0 the error is smaller in magnitude than 12η∥∇f(xk)∥2,\tfrac12\eta\norm{\nabla f(\vb{x}_k)}^2\mathclose{\text{,}} so the actual change is negative too. How small η\eta must be can depend on the point. The points stop moving only where ∇f=0;\nabla f = \vb{0}\mathclose{\text{;}} Module 18 studies these critical points.

Example 17.15Gradient descent on a bowl✓ Checked

Apply gradient descent to f(x,y)=x2+3y2,f(x, y) = x^2 + 3y^2\mathclose{\text{,}} from (3,1)(3, 1) with η=0.1.\eta = 0.1\mathclose{\text{.}} Find a formula for the kkth point, and the step sizes for which the points approach the minimum at (0,0).(0, 0)\mathclose{\text{.}}

Here ∇f=⟨2x,6y⟩.\nabla f = \langle 2x, 6y\rangle\mathclose{\text{.}} First step: ∇f(3,1)=⟨6,6⟩,\nabla f(3, 1) = \langle 6, 6\rangle\mathclose{\text{,}} so

x1=⟨3,1⟩−0.1 ⟨6,6⟩=⟨2.4,0.4⟩,\vb{x}_1 = \langle 3, 1\rangle - 0.1\,\langle 6, 6\rangle = \langle 2.4, 0.4\rangle,

and ff drops from 12 to 5.76+0.48=6.24.5.76 + 0.48 = 6.24\mathclose{\text{.}} Second step: ∇f(2.4,0.4)=⟨4.8,2.4⟩,\nabla f(2.4, 0.4) = \langle 4.8, 2.4\rangle\mathclose{\text{,}} so x2=⟨1.92,0.16⟩,\vb{x}_2 = \langle 1.92, 0.16\rangle\mathclose{\text{,}} where f=3.7632.f = 3.7632\mathclose{\text{.}} Each step multiplies each coordinate by a fixed factor,

xk+1=xk−2ηxk=(1−2η)xk,yk+1=yk−6ηyk=(1−6η)yk,\begin{aligned} x_{k+1} &= x_k - 2\eta x_k = (1 - 2\eta)x_k, \\ y_{k+1} &= y_k - 6\eta y_k = (1 - 6\eta)y_k, \end{aligned}

so with η=0.1,\eta = 0.1\mathclose{\text{,}} xk=3(0.8)kx_k = 3(0.8)^k and yk=(0.4)k:y_k = (0.4)^k\mathclose{\text{:}}

kkxkx_kyky_kf(xk,yk)f(x_k, y_k)
0033111212
112.42.40.40.46.246.24
221.921.920.160.163.76323.7632
331.5361.5360.0640.0642.371582.37158
441.22881.22880.02560.02561.511921.51192
550.983040.983040.010240.010240.9666820.966682
660.7864320.7864320.0040960.0040960.6185260.618526

From (3,1)(3, 1) the points approach (0,0)(0, 0) exactly when both factors lie strictly between −1-1 and 1, as for the parabola of Section 8.7, once for each coordinate. ∣1−2η∣<1\abs{1 - 2\eta} < 1 needs 0<η<1,0 < \eta < 1\mathclose{\text{,}} and ∣1−6η∣<1\abs{1 - 6\eta} < 1 needs 0<η<13;0 < \eta < \tfrac13\mathclose{\text{;}} so gradient descent converges exactly when 0<η<13.0 < \eta < \tfrac13\mathclose{\text{.}} With η=0.3\eta = 0.3 the factors are 0.4 and −0.8:-0.8\mathclose{\text{:}} yky_k changes sign at every step, and the points zigzag across the valley while closing in slowly (Figure 17.4, right).

Compute itGradient descent with NumPy

Each step is one line:

Python
import numpy as np

def grad(p):                            # f(x, y) = x**2 + 3*y**2
    return np.array([2*p[0], 6*p[1]])

def descent(eta, steps, p=(3.0, 1.0)):
    p = np.array(p)
    for _ in range(steps):
        p = p - eta*grad(p)
    return p

for eta in (0.1, 0.3):
    for k in (1, 2, 5, 10, 20):
        x, y = descent(eta, k)
        print(f"eta = {eta}, k = {k:2d}: ({x:9.6f}, {y:9.6f})")
Output
eta = 0.1, k =  1: ( 2.400000,  0.400000)
eta = 0.1, k =  2: ( 1.920000,  0.160000)
eta = 0.1, k =  5: ( 0.983040,  0.010240)
eta = 0.1, k = 10: ( 0.322123,  0.000105)
eta = 0.1, k = 20: ( 0.034588,  0.000000)
eta = 0.3, k =  1: ( 1.200000, -0.800000)
eta = 0.3, k =  2: ( 0.480000,  0.640000)
eta = 0.3, k =  5: ( 0.030720, -0.327680)
eta = 0.3, k = 10: ( 0.000315,  0.107374)
eta = 0.3, k = 20: ( 0.000000,  0.011529)

With η=0.1\eta = 0.1 the yy-coordinate, multiplied by 0.4 at each step, is soon negligible, and the xx-coordinate, multiplied by 0.8, lags behind: after 20 steps it is still about 0.035. With η=0.3\eta = 0.3 the roles swap: xx shrinks by the factor 0.4, but yy changes sign at every step and shrinks only by the factor 0.8. How many steps until ∥∇f∥<10−8,\norm{\nabla f} < 10^{-8}\mathclose{\text{,}} for different step sizes?

Python
def steps_needed(eta, tol=1e-8, max_steps=10000):
    p = np.array([3.0, 1.0])
    for k in range(max_steps + 1):
        size = np.linalg.norm(grad(p))
        if size < tol:
            return k
        if size >= 1e6 or k == max_steps:
            return None
        p = p - eta*grad(p)

for eta in (0.05, 0.1, 0.2, 0.25, 0.3, 0.33, 0.34):
    k = steps_needed(eta)
    print(f"eta = {eta}: " + (f"{k} steps" if k is not None else "tolerance not reached"))
Output
eta = 0.05: 192 steps
eta = 0.1: 91 steps
eta = 0.2: 40 steps
eta = 0.25: 30 steps
eta = 0.3: 91 steps
eta = 0.33: 1001 steps
eta = 0.34: tolerance not reached

The loop stops after at most 10,000 updates, or earlier if the gradient grows to 106.10^6\mathclose{\text{.}} This also handles bounded sequences that never reach the tolerance, such as the oscillation at η=13;\eta = \tfrac13\mathclose{\text{;}} None means that the tolerance was not reached before stopping, and does not by itself prove divergence.

The best of these step sizes is 0.25, where the two factors 1−2η=0.51 - 2\eta = 0.5 and 1−6η=−0.51 - 6\eta = -0.5 are equally small. At η=0.33\eta = 0.33 the factor 1−6η=−0.981 - 6\eta = -0.98 is close to −1,-1\mathclose{\text{,}} and the zigzag takes a thousand steps to die down; at 0.34, beyond 13,\tfrac13\mathclose{\text{,}} it grows, and gradient descent diverges, as the formula proves. The steep direction limits the step size, while the gentle direction would like long steps. When the curvature is very different in different directions, even the best fixed step size can give slow gradient descent; Module 18 studies this problem, called ill-conditioning.

In many machine-learning models, x\vb{x} is the list of parameters, such as weights and biases, often millions of them, and ff is the loss, a measure of the model’s error on its training data. These models often train by gradient descent or one of its variants: stochastic gradient descent estimates the gradient at each step from a randomly chosen example or batch of the training data, and methods such as momentum and Adam use gradients of earlier steps when forming the next update. Every such step needs a gradient, one partial derivative per parameter, and the next section shows how to compute it efficiently. The series AI: From Machine Learning to Large Language Models puts these methods to work.

8

Backpropagation

The loss of a neural network is computed by a long chain of simple operations: multiplications by weights, sums, and simple functions of one variable. Section 5.8 showed how a program can differentiate such a computation with dual numbers, carrying derivatives forwards, one input at a time. With that implementation, a million parameters take a million runs. For a computation whose operations are differentiable at their inputs, backpropagation finds the derivative of the loss with respect to every parameter in one backward pass, at a cost of a small multiple of computing the loss itself. It is the chain rule of Section 17.5, organised on a graph.

Definition 17.13Computational graph

A computational graph of a computation is a directed graph with no cycles: it has a node for each input and for each intermediate result, and one arrow for each use of a node as an input to another node. The nodes that a node points to are its children, and the nodes it is computed from are its parents. For differentiable operations, each arrow carries a local derivative: the partial derivative of the child’s operation with respect to that input argument, holding the other arguments fixed. If a node supplies two arguments, as in e⋅e,e\cdot e\mathclose{\text{,}} there are two arrows, each carrying e.e\mathclose{\text{.}} If the computation ends with the number L,L\mathclose{\text{,}} the adjoint of a node vv is vˉ=∂L/∂v,\bar v = \partial L/\partial v\mathclose{\text{,}} read “v bar”.

The graph is evaluated in two passes.

  1. The forward pass computes the value of every node, from the inputs to the output, and keeps the values.
  2. The backward pass computes the adjoints, from the output back to the inputs. It starts with Lˉ=1,\bar L = 1\mathclose{\text{,}} and gives every other node vv the sum over its arrows to children c,c\mathclose{\text{,}} counting repeated input uses separately:
vˉ=∑v→c cˉ ∂c∂v,\bar v = \sum_{v\to c}\,\bar c\,\frac{\partial c}{\partial v},

where each ∂c/∂v\partial c/\partial v is the local derivative on that arrow.

Why is this right? LL depends on vv only through the children of v,v\mathclose{\text{,}} so the general chain rule of Section 17.5, with the children as the intermediate variables, gives exactly this sum. Unwound, it is the key idea of Section 17.5: ∂L/∂v\partial L/\partial v is the sum, over all paths from vv to L,L\mathclose{\text{,}} of the products of the local derivatives along the path. The backward pass adds up these products economically. Each adjoint cˉ\bar c is computed once and then serves every path through c,c\mathclose{\text{,}} so each arrow is used once, and the backward pass costs a small multiple of the forward pass, however many inputs there are.

The computational graph of the loss L(w, b) = (1 - w - b)^2 + (3 - 2w - b)^2 of Example 17.16, at w = b = 0. Each arrow carries its local derivative. The forward pass gives the values (blue); the backward pass, from bar L = 1 back to the inputs, gives the adjoints (orange), and bar w = -14 and bar b = -8 are the two partial derivatives of L.
Figure 17.5

The computational graph of the loss L(w,b)=(1−w−b)2+(3−2w−b)2L(w, b) = (1 - w - b)^2 + (3 - 2w - b)^2 of Example 17.16, at w=b=0.w = b = 0\mathclose{\text{.}} Each arrow carries its local derivative. The forward pass gives the values (blue); the backward pass, from Lˉ=1\bar L = 1 back to the inputs, gives the adjoints (orange), and wˉ=−14\bar w = -14 and bˉ=−8\bar b = -8 are the two partial derivatives of L.L\mathclose{\text{.}}

Example 17.16A forward and a backward pass✓ Checked

A model predicts the value wx+bwx + b from an input x,x\mathclose{\text{,}} with two parameters ww and b.b\mathclose{\text{.}} On the two data points (x,t)=(1,1)(x, t) = (1, 1) and (2,3),(2, 3)\mathclose{\text{,}} where tt is the true value, its errors (true value minus prediction) are e1=1−w⋅1−be_1 = 1 - w \cdot 1 - b and e2=3−w⋅2−b,e_2 = 3 - w \cdot 2 - b\mathclose{\text{,}} and its loss is L=e12+e22.L = e_1^2 + e_2^2\mathclose{\text{.}} Starting from w=b=0,w = b = 0\mathclose{\text{,}} find ∂L/∂w\partial L/\partial w and ∂L/∂b\partial L/\partial b by a forward and a backward pass (Figure 17.5), and take one step of gradient descent with η=0.05.\eta = 0.05\mathclose{\text{.}}

Forward pass. e1=1,e_1 = 1\mathclose{\text{,}} e2=3e_2 = 3 and L=1+9=10.L = 1 + 9 = 10\mathclose{\text{.}}

Backward pass. Start with Lˉ=1.\bar L = 1\mathclose{\text{.}} The local derivatives of L=e12+e22L = e_1^2 + e_2^2 are 2e12e_1 and 2e2,2e_2\mathclose{\text{,}} so eˉ1=Lˉ⋅2e1=2\bar e_1 = \bar L \cdot 2e_1 = 2 and eˉ2=Lˉ⋅2e2=6.\bar e_2 = \bar L \cdot 2e_2 = 6\mathclose{\text{.}} The node ww has two children, e1e_1 and e2,e_2\mathclose{\text{,}} with local derivatives −1-1 and −2,-2\mathclose{\text{,}} the negatives of the inputs xx of the two points; bb has the same children, with local derivatives −1-1 and −1:-1\mathclose{\text{:}}

wˉ=eˉ1⋅(−1)+eˉ2⋅(−2)=−2−12=−14,bˉ=eˉ1⋅(−1)+eˉ2⋅(−1)=−2−6=−8.\begin{aligned} \bar w &= \bar e_1 \cdot (-1) + \bar e_2 \cdot (-2) = -2 - 12 = -14, \\ \bar b &= \bar e_1 \cdot (-1) + \bar e_2 \cdot (-1) = -2 - 6 = -8. \end{aligned}
Node Forward pass Backward pass
w,w\mathclose{\text{,}} bb 0,0\mathclose{\text{,}} 00 wˉ=−14,\bar w = -14\mathclose{\text{,}} bˉ=−8\bar b = -8
e1=1−w−be_1 = 1 - w - b 11 eˉ1=Lˉ⋅2e1=2\bar e_1 = \bar L \cdot 2e_1 = 2
e2=3−2w−be_2 = 3 - 2w - b 33 eˉ2=Lˉ⋅2e2=6\bar e_2 = \bar L \cdot 2e_2 = 6
L=e12+e22L = e_1^2 + e_2^2 1010 Lˉ=1\bar L = 1

So ∇L(0,0)=⟨−14,−8⟩.\nabla L(0, 0) = \langle -14, -8\rangle\mathclose{\text{.}} Check by differentiating L(w,b)=(1−w−b)2+(3−2w−b)2L(w, b) = (1 - w - b)^2 + (3 - 2w - b)^2 directly: Lw=−2(1−w−b)−4(3−2w−b)L_w = -2(1 - w - b) - 4(3 - 2w - b) and Lb=−2(1−w−b)−2(3−2w−b),L_b = -2(1 - w - b) - 2(3 - 2w - b)\mathclose{\text{,}} which are −2−12=−14-2 - 12 = -14 and −2−6=−8-2 - 6 = -8 at (0,0).(0, 0)\mathclose{\text{.}}

One step of gradient descent gives ⟨w,b⟩=⟨0,0⟩−0.05 ⟨−14,−8⟩=⟨0.7,0.4⟩,\langle w, b\rangle = \langle 0, 0\rangle - 0.05\,\langle -14, -8\rangle = \langle 0.7, 0.4\rangle\mathclose{\text{,}} where e1=−0.1,e_1 = -0.1\mathclose{\text{,}} e2=1.2e_2 = 1.2 and L=0.01+1.44=1.45,L = 0.01 + 1.44 = 1.45\mathclose{\text{,}} down from 10. Further steps approach w=2,w = 2\mathclose{\text{,}} b=−1,b = -1\mathclose{\text{,}} the line t=2x−1t = 2x - 1 through both points, where L=0;L = 0\mathclose{\text{;}} Module 18 finds such best-fitting lines directly, by least squares.

Watch out

Every child of a node contributes to its adjoint. Here ww influences LL through both data points; keeping only the path through e1e_1 would give wˉ=−2\bar w = -2 instead of −14.-14\mathclose{\text{.}} A program therefore accumulates adjoints: each starts at 0, and each child adds its share.

Compute itBackpropagation in Python

A few lines of Python record the graph while a computation runs, and then run the backward pass. Each Var holds a value, its parents with the local derivatives, and its adjoint, called grad:

Python
class Var:
    """A node of a computational graph."""
    def __init__(self, value, parents=()):
        self.value, self.parents, self.grad = value, parents, 0.0
    def __add__(self, other):
        other = other if isinstance(other, Var) else Var(other)
        return Var(self.value + other.value, [(self, 1.0), (other, 1.0)])
    def __mul__(self, other):
        other = other if isinstance(other, Var) else Var(other)
        a, b = self.value, other.value
        return Var(a*b, [(self, b), (other, a)])
    def __sub__(self, other):
        return self + (-1.0)*other
    def __rsub__(self, other):
        return (-1.0)*self + other
    __radd__, __rmul__ = __add__, __mul__

The backward pass lists the nodes so that each comes after the nodes it was computed from, resets their adjoints to 0, then walks the list backwards; each node passes its adjoint times the local derivative to each parent, which adds up what it receives. Resetting lets us run the backward pass on the same graph again:

Python
def backward(out):
    order, seen = [], set()
    def visit(v):
        if id(v) not in seen:
            seen.add(id(v))
            for p, _ in v.parents:
                visit(p)
            order.append(v)
    visit(out)
    for v in order:
        v.grad = 0.0
    out.grad = 1.0
    for v in reversed(order):
        for p, local in v.parents:
            p.grad += v.grad*local

Example 17.16, with the loss computed by an ordinary Python function:

Python
data = [(1, 1), (2, 3)]                 # the points (x, t)

def loss(w, b):
    L = 0
    for x, t in data:
        e = t - (w*x + b)               # true value minus prediction
        L = L + e*e
    return L

w, b = Var(0.0), Var(0.0)
L = loss(w, b)
backward(L)
print(L.value, w.grad, b.grad)
Output
10.0 -14.0 -8.0

The product e*e lists e twice as a parent, with the local derivative ee each time, so e receives 2e2e times the adjoint of the product: the product rule, done by the graph. SymPy, given the formula, agrees:

Python
import sympy as sp
ws, bs = sp.symbols('w b')
Ls = sum((t - (ws*x + bs))**2 for x, t in data)
print(sp.expand(Ls), '|', [sp.diff(Ls, v).subs({ws: 0, bs: 0}) for v in (ws, bs)])
Output
2*b**2 + 6*b*w - 8*b + 5*w**2 - 14*w + 10 | [-14, -8]

SymPy expands the loss to L=5w2+6wb+2b2−14w−8b+10,L = 5w^2 + 6wb + 2b^2 - 14w - 8b + 10\mathclose{\text{,}} with the terms in its own order, and its partial derivatives at (0,0)(0, 0) are those of the backward pass.

Training is a loop of forward pass, backward pass and gradient descent step:

Python
w, b = Var(0.0), Var(0.0)
for step in range(501):
    L = loss(w, b)
    if step in (0, 1, 2, 10, 100, 500):
        Lv, wv, bv = L.value, w.value, b.value
        print(f"step {step:3d}: L = {Lv:.3g}, w = {wv:.4f}, b = {bv:.4f}")
    if step < 500:
        backward(L)
        w, b = Var(w.value - 0.05*w.grad), Var(b.value - 0.05*b.grad)
Output
step   0: L = 10, w = 0.0000, b = 0.0000
step   1: L = 1.45, w = 0.7000, b = 0.4000
step   2: L = 0.59, w = 0.9300, b = 0.5100
step  10: L = 0.393, w = 1.1367, b = 0.3969
step 100: L = 0.0279, w = 1.7700, b = -0.6279
step 500: L = 2.19e-07, w = 1.9994, b = -0.9990

Each printed step counts completed updates: step 0 is the starting point, and the second line is the step of Example 17.16. The loss falls fast at first and then slowly: after 100 steps it is still about 0.0279, and only after some hundreds of steps do ww and bb settle near 2 and −1.-1\mathclose{\text{.}} The valley of this loss is long and narrow, the situation that Module 18 explains.

Neural networks use the same forward and backward organisation, with arrays of numbers in place of single numbers, nonlinear functions between the layers, and potentially millions of operations; the parameter updates may use variants of gradient descent. The series AI: From Machine Learning to Large Language Models works through backpropagation in neural networks in its Module 2, and Module 18 of Mathematical Foundations writes the same chain rule with matrices.

9

What you learned

  • A function of two or three variables has a domain in the plane or in space. Surface plots show graphs z=f(x,y);z = f(x, y)\mathclose{\text{;}} contour maps show level sets f(x,y)=k,f(x, y) = k\mathclose{\text{,}} usually curves, though some levels can be points or larger sets. With equally spaced levels, crowded contours indicate steep ground. In three variables, level sets f(x,y,z)=kf(x, y, z) = k are often surfaces.
  • lim⁡(x,y)→(a,b)f(x,y)=L\lim_{(x,y)\to(a,b)} f(x, y) = L needs the values to approach LL along every path in the domain. Two paths with different limits prove that no limit exists; agreement along every line does not establish a limit; a squeeze ∣f−L∣≤g→0\abs{f - L} \le g \to 0 proves that the limit exists.
  • The partial derivatives fx=∂f/∂xf_x = \partial f/\partial x and fyf_y are found by holding the other variable fixed; they are the slopes of slices of the surface. Clairaut’s theorem gives fxy=fyxf_{xy} = f_{yx} when both mixed partial derivatives are continuous on a neighbourhood of the point.
  • For a differentiable function, the tangent plane z=f(a,b)+fx(a,b)(x−a)+fy(a,b)(y−b)z = f(a, b) + f_x(a, b)(x - a) + f_y(a, b)(y - b) gives the linear approximation. Differentiability means that the error divided by the distance tends to 0; continuous partial derivatives guarantee it, partial derivatives alone do not. The total differential dz=fx dx+fy dydz = f_x\,dx + f_y\,dy estimates the change in zz and gives a first-order estimate of propagated measurement errors.
  • For differentiable functions, the chain rule adds one product for each path in the tree diagram, as in dzdt=∂z∂xdxdt+∂z∂ydydt.\dfrac{dz}{dt} = \dfrac{\partial z}{\partial x}\dfrac{dx}{dt} + \dfrac{\partial z}{\partial y}\dfrac{dy}{dt}\mathclose{\text{.}} With continuous partial derivatives near a point on F=0F = 0 and Fy≠0F_y \ne 0 there, implicit differentiation gives dy/dx=−Fx/Fydy/dx = -F_x/F_y for the local graph.
  • For differentiable ff and a unit vector u,\vb{u}\mathclose{\text{,}} the gradient ∇f=⟨fx,fy⟩\nabla f = \langle f_x, f_y\rangle gives Duf=∇f⋅u.D_{\vb{u}} f = \nabla f\cdot\vb{u}\mathclose{\text{.}} A nonzero gradient points in the direction of steepest ascent, with rate ∥∇f∥;\norm{\nabla f}\mathclose{\text{;}} if it is zero, every directional derivative is zero. With continuous partial derivatives near the point and a nonzero gradient, the level set is locally a curve (in two variables) or a surface (in three), with that gradient as its normal.
  • Gradient descent xk+1=xk−η∇f(xk)\vb{x}_{k+1} = \vb{x}_k - \eta\nabla f(\vb{x}_k) lowers a differentiable function when the gradient is nonzero and the positive step size is sufficiently small. Larger steps can zigzag or diverge. Backpropagation finds every input partial derivative of a loss in one backward pass over a differentiable computational graph, adding over the children of each node: the chain rule, organised for many inputs.
10

Exercises

Exercise 17.1★Domain, range and level curves

Let f(x,y)=16−x2−4y2.f(x, y) = \sqrt{16 - x^2 - 4y^2}\mathclose{\text{.}}

  • (a) Find and describe the domain and the range of f.f\mathclose{\text{.}}
  • (b) Describe the level sets f(x,y)=kf(x, y) = k for k=0,1,2,3,4.k = 0, 1, 2, 3, 4\mathclose{\text{.}} Where are the curves closest together, and what does that say about the surface?
Show solution✓ Checked

(a) The square root needs 16−x2−4y2≥0,16 - x^2 - 4y^2 \ge 0\mathclose{\text{,}} that is, x2+4y2≤16,x^2 + 4y^2 \le 16\mathclose{\text{,}} or x216+y24≤1:\dfrac{x^2}{16} + \dfrac{y^2}{4} \le 1\mathclose{\text{:}} the ellipse with semi-axes 4 along the xx-axis and 2 along the yy-axis, together with its inside. On the domain, 16−x2−4y216 - x^2 - 4y^2 lies between 0 and 16, so ff takes values in [0,4];[0, 4]\mathclose{\text{;}} along the xx-axis, f(x,0)=16−x2f(x, 0) = \sqrt{16 - x^2} takes every value from 0 to 4 as xx goes from 4 down to 0. The range is [0,4].[0, 4]\mathclose{\text{.}}

(b) For 0≤k≤4,0 \le k \le 4\mathclose{\text{,}} f(x,y)=kf(x, y) = k means x2+4y2=16−k2x^2 + 4y^2 = 16 - k^2 (square both sides, which are non-negative). For k<4k < 4 this is an ellipse centred at the origin with semi-axes 16−k2\sqrt{16 - k^2} and 1216−k2,\tfrac12\sqrt{16 - k^2}\mathclose{\text{,}} always of the same shape. For k=0k = 0 it is the edge of the domain. It crosses the positive xx-axis at 4, 15≈3.87,\sqrt{15} \approx 3.87\mathclose{\text{,}} 12≈3.46\sqrt{12} \approx 3.46 and 7≈2.65\sqrt7 \approx 2.65 for k=0,1,2,3;k = 0, 1, 2, 3\mathclose{\text{;}} for k=4k = 4 the level set is the single point (0,0),(0, 0)\mathclose{\text{,}} the top. The gaps grow, from about 0.13 to 0.41, 0.82 and 2.65: the level curves are closest together near the edge, where the surface, the top half of an ellipsoid, is steepest.

Exercise 17.2★Partial derivatives

Find all the first partial derivatives:

  • (a) f(x,y)=x4y−3x2y3+7,f(x, y) = x^4y - 3x^2y^3 + 7\mathclose{\text{,}} and their values at (1,−1)(1, -1)
  • (b) g(x,y)=ln⁡(x2+y2)g(x, y) = \ln(x^2 + y^2)
  • (c) h(x,y,z)=xy2zh(x, y, z) = \dfrac{xy^2}{z}
Show solution✓ Checked

(a) Holding yy fixed, fx=4x3y−6xy3;f_x = 4x^3y - 6xy^3\mathclose{\text{;}} holding xx fixed, fy=x4−9x2y2.f_y = x^4 - 9x^2y^2\mathclose{\text{.}} At (1,−1):(1, -1)\mathclose{\text{:}} fx=−4+6=2f_x = -4 + 6 = 2 and fy=1−9=−8.f_y = 1 - 9 = -8\mathclose{\text{.}}

(b) By the chain rule, with the inner function x2+y2x^2 + y^2 and the derivative 1/u1/u of ln⁡u:\ln u\mathclose{\text{:}} gx=2xx2+y2g_x = \dfrac{2x}{x^2 + y^2} and gy=2yx2+y2,g_y = \dfrac{2y}{x^2 + y^2}\mathclose{\text{,}} for (x,y)≠(0,0).(x, y) \ne (0, 0)\mathclose{\text{.}}

(c) For z≠0:z \ne 0\mathclose{\text{:}} hx=y2zh_x = \dfrac{y^2}{z} and hy=2xyz,h_y = \dfrac{2xy}{z}\mathclose{\text{,}} since 1z\dfrac{1}{z} is a constant factor when zz is held fixed; and hz=−xy2z2,h_z = -\dfrac{xy^2}{z^2}\mathclose{\text{,}} the constant xy2xy^2 times the derivative of 1z.\dfrac1z\mathclose{\text{.}} The quotient rule would give the same answers with more work.

Exercise 17.3★Two limits
  • (a) Show that lim⁡(x,y)→(0,0)x2−y2x2+y2\lim_{(x, y)\to(0, 0)} \dfrac{x^2 - y^2}{x^2 + y^2} does not exist.
  • (b) Find lim⁡(x,y)→(0,0)x2+y2x2+y2+1−1.\lim_{(x, y)\to(0, 0)} \dfrac{x^2 + y^2}{\sqrt{x^2 + y^2 + 1} - 1}\mathclose{\text{.}}
Show solution✓ Checked

(a) Along the xx-axis (y=0,y = 0\mathclose{\text{,}} x≠0)x \ne 0\mathclose{\text{)}} the function is x2x2=1;\dfrac{x^2}{x^2} = 1\mathclose{\text{;}} along the yy-axis it is −y2y2=−1.\dfrac{-y^2}{y^2} = -1\mathclose{\text{.}} Two paths give two different limits, so by Theorem 17.1 the limit does not exist. (Along y=mxy = mx it is 1−m21+m2,\dfrac{1 - m^2}{1 + m^2}\mathclose{\text{,}} which depends on m.)m\mathclose{\text{.)}}

(b) Direct substitution gives 00.\tfrac00\mathclose{\text{.}} The function depends on xx and yy only through s=x2+y2,s = x^2 + y^2\mathclose{\text{,}} so rationalise as in Section 2.5: for s>0,s > 0\mathclose{\text{,}}

ss+1−1=s(s+1+1)(s+1)−1=s+1+1.\begin{aligned} \frac{s}{\sqrt{s + 1} - 1} &= \frac{s\big(\sqrt{s + 1} + 1\big)}{(s + 1) - 1} \\ &= \sqrt{s + 1} + 1. \end{aligned}

As (x,y)→(0,0),(x, y) \to (0, 0)\mathclose{\text{,}} s→0,s \to 0\mathclose{\text{,}} and x2+y2+1+1\sqrt{x^2 + y^2 + 1} + 1 is continuous with the value 2 at the origin. The limit is 2.

Exercise 17.4★A gradient and its directions

Let f(x,y)=x2y−y3.f(x, y) = x^2y - y^3\mathclose{\text{.}}

  • (a) Find ∇f(2,1).\nabla f(2, 1)\mathclose{\text{.}}
  • (b) Find the directional derivative of ff at (2,1)(2, 1) in the direction of ⟨1,−1⟩.\langle 1, -1\rangle\mathclose{\text{.}}
  • (c) In which direction does ff increase fastest at (2,1),(2, 1)\mathclose{\text{,}} and at what rate? In which directions is the rate of change 0?
Show solution✓ Checked

(a) fx=2xyf_x = 2xy and fy=x2−3y2,f_y = x^2 - 3y^2\mathclose{\text{,}} so ∇f(2,1)=⟨4,4−3⟩=⟨4,1⟩.\nabla f(2, 1) = \langle 4, 4 - 3\rangle = \langle 4, 1\rangle\mathclose{\text{.}}

(b) ⟨1,−1⟩\langle 1, -1\rangle has length 2,\sqrt2\mathclose{\text{,}} so u=⟨1,−1⟩/2,\vb{u} = \langle 1, -1\rangle/\sqrt2\mathclose{\text{,}} and by Theorem 17.9

Duf(2,1)=4⋅1+1⋅(−1)2=32≈2.121.D_{\vb{u}} f(2, 1) = \frac{4 \cdot 1 + 1 \cdot (-1)}{\sqrt2} = \frac{3}{\sqrt2} \approx 2.121.

Using ⟨1,−1⟩\langle 1, -1\rangle itself would give 3, which is wrong: it is not a unit vector.

(c) Fastest in the direction of ∇f(2,1),\nabla f(2, 1)\mathclose{\text{,}} that is, u=⟨4,1⟩/17,\vb{u} = \langle 4, 1\rangle/\sqrt{17}\mathclose{\text{,}} at the rate ∥⟨4,1⟩∥=17≈4.123\norm{\langle 4, 1\rangle} = \sqrt{17} \approx 4.123 (Theorem 17.10). The rate is 0 in the two directions perpendicular to the gradient, ±⟨1,−4⟩/17,\pm\langle 1, -4\rangle/\sqrt{17}\mathclose{\text{,}} tangent to the level curve through (2,1):(2, 1)\mathclose{\text{:}} indeed ⟨4,1⟩⋅⟨1,−4⟩=4−4=0.\langle 4, 1\rangle\cdot\langle 1, -4\rangle = 4 - 4 = 0\mathclose{\text{.}}

Exercise 17.5★★A limit by squeezing

Show that lim⁡(x,y)→(0,0)x3+y3x2+y2=0.\lim_{(x, y)\to(0, 0)} \dfrac{x^3 + y^3}{x^2 + y^2} = 0\mathclose{\text{.}}

Show solution✓ Checked

Let (x,y)≠(0,0),(x, y) \ne (0, 0)\mathclose{\text{,}} and let ρ=x2+y2\rho = \sqrt{x^2 + y^2} be its distance from the origin. Since ∣x∣≤ρ,\abs{x} \le \rho\mathclose{\text{,}} ∣x3∣=∣x∣ x2≤ρ x2;\abs{x^3} = \abs{x}\,x^2 \le \rho\,x^2\mathclose{\text{;}} in the same way ∣y3∣≤ρ y2.\abs{y^3} \le \rho\,y^2\mathclose{\text{.}} So

∣x3+y3x2+y2∣≤∣x3∣+∣y3∣x2+y2≤ρ (x2+y2)x2+y2=ρ.\begin{aligned} \abs{\frac{x^3 + y^3}{x^2 + y^2}} &\le \frac{\abs{x^3} + \abs{y^3}}{x^2 + y^2} \\ &\le \frac{\rho\,(x^2 + y^2)}{x^2 + y^2} = \rho. \end{aligned}

As (x,y)→(0,0),(x, y) \to (0, 0)\mathclose{\text{,}} ρ→0,\rho \to 0\mathclose{\text{,}} so by the squeeze theorem (Theorem 17.2, with g=ρg = \rho and L=0)L = 0\mathclose{\text{)}} the limit is 0. Checking paths would only have suggested the answer: along y=mxy = mx the function is (1+m3)x1+m2,\dfrac{(1 + m^3)x}{1 + m^2}\mathclose{\text{,}} which tends to 0, but the pitfall after Example 17.3 shows that lines alone prove nothing.

Exercise 17.6★★A tangent plane and an estimate

Let f(x,y)=xexy.f(x, y) = xe^{xy}\mathclose{\text{.}}

  • (a) Find the tangent plane to the surface z=f(x,y)z = f(x, y) at (1,0,1).(1, 0, 1)\mathclose{\text{.}}
  • (b) Use the linear approximation to estimate f(1.1,−0.1),f(1.1, -0.1)\mathclose{\text{,}} and compare with the value from a calculator.
Show solution✓ Checked

(a) By the product and chain rules, fx=exy+xyexy=(1+xy)exyf_x = e^{xy} + xye^{xy} = (1 + xy)e^{xy} and fy=x⋅xexy=x2exy,f_y = x \cdot xe^{xy} = x^2e^{xy}\mathclose{\text{,}} both continuous everywhere. At (1,0):(1, 0)\mathclose{\text{:}} f(1,0)=1,f(1, 0) = 1\mathclose{\text{,}} fx(1,0)=1f_x(1, 0) = 1 and fy(1,0)=1.f_y(1, 0) = 1\mathclose{\text{.}} The tangent plane is z=1+(x−1)+(y−0),z = 1 + (x - 1) + (y - 0)\mathclose{\text{,}} that is, z=x+y.z = x + y\mathclose{\text{.}}

(b) f(1.1,−0.1)≈1.1+(−0.1)=1.f(1.1, -0.1) \approx 1.1 + (-0.1) = 1\mathclose{\text{.}} A calculator gives 1.1e−0.11≈0.98542,1.1e^{-0.11} \approx 0.98542\mathclose{\text{,}} so the signed error, exact value minus approximation, is 1.1e−0.11−1≈−0.015:1.1e^{-0.11} - 1 \approx -0.015\mathclose{\text{:}} the estimate is too high. The distance from (1,0)(1, 0) is 0.12+0.12≈0.14.\sqrt{0.1^2 + 0.1^2} \approx 0.14\mathclose{\text{.}} Distance alone does not say how accurate a linear approximation will be; here the comparison with the calculated value shows its accuracy.

Exercise 17.7★★A chain rule with three routes

Let w=x2+yz,w = x^2 + yz\mathclose{\text{,}} where x=t2,x = t^2\mathclose{\text{,}} y=cos⁡ty = \cos t and z=sin⁡t.z = \sin t\mathclose{\text{.}}

  • (a) Draw the tree diagram, and use it to find dw/dtdw/dt as a function of t.t\mathclose{\text{.}}
  • (b) Check by substituting first.
  • (c) Find dw/dtdw/dt at t=0t = 0 and at t=π/4.t = \pi/4\mathclose{\text{.}}
Show solution✓ Checked

(a) The tree has ww at the top, three branches down to x,x\mathclose{\text{,}} yy and z,z\mathclose{\text{,}} labelled wx=2x,w_x = 2x\mathclose{\text{,}} wy=zw_y = z and wz=y,w_z = y\mathclose{\text{,}} and from each of these a branch down to t,t\mathclose{\text{,}} labelled dx/dt=2t,dx/dt = 2t\mathclose{\text{,}} dy/dt=−sin⁡tdy/dt = -\sin t and dz/dt=cos⁡t.dz/dt = \cos t\mathclose{\text{.}} Three paths give three products:

dwdt=2x⋅2t+z⋅(−sin⁡t)+ycos⁡t=4t3−sin⁡2t+cos⁡2t=4t3+cos⁡2t,\begin{aligned} \frac{dw}{dt} &= 2x\cdot 2t + z\cdot(-\sin t) + y\cos t \\ &= 4t^3 - \sin^2 t + \cos^2 t = 4t^3 + \cos 2t, \end{aligned}

using x=t2,x = t^2\mathclose{\text{,}} y=cos⁡t,y = \cos t\mathclose{\text{,}} z=sin⁡tz = \sin t and cos⁡2t−sin⁡2t=cos⁡2t\cos^2 t - \sin^2 t = \cos 2t (the addition formula of Module 1 with both angles t).t\mathclose{\text{).}}

(b) w=t4+cos⁡tsin⁡t=t4+12sin⁡2t,w = t^4 + \cos t\sin t = t^4 + \tfrac12\sin 2t\mathclose{\text{,}} so dwdt=4t3+cos⁡2t,\dfrac{dw}{dt} = 4t^3 + \cos 2t\mathclose{\text{,}} as in (a).

(c) At t=0:t = 0\mathclose{\text{:}} dwdt=0+1=1.\dfrac{dw}{dt} = 0 + 1 = 1\mathclose{\text{.}} At t=π/4:t = \pi/4\mathclose{\text{:}} 4(π4)3+cos⁡π2=π316≈1.938.4\Big(\dfrac{\pi}{4}\Big)^3 + \cos\dfrac{\pi}{2} = \dfrac{\pi^3}{16} \approx 1.938\mathclose{\text{.}}

Exercise 17.8★★A level surface

The point (1,2,3)(1, 2, 3) lies on the surface xyz=6.xyz = 6\mathclose{\text{.}}

  • (a) Find the tangent plane to the surface there.
  • (b) Near (1,2,3)(1, 2, 3) the surface is the graph of a function z(x,y).z(x, y)\mathclose{\text{.}} Find ∂z/∂x\partial z/\partial x and ∂z/∂y\partial z/\partial y at (1,2)(1, 2) by implicit differentiation.
  • (c) Check (b) in two ways: with the tangent plane of (a), and by solving for z.z\mathclose{\text{.}}
Show solution✓ Checked

(a) With F(x,y,z)=xyz,F(x, y, z) = xyz\mathclose{\text{,}} ∇F=⟨yz,xz,xy⟩,\nabla F = \langle yz, xz, xy\rangle\mathclose{\text{,}} so ∇F(1,2,3)=⟨6,3,2⟩.\nabla F(1, 2, 3) = \langle 6, 3, 2\rangle\mathclose{\text{.}} The tangent plane is

6(x−1)+3(y−2)+2(z−3)=0,that is,6x+3y+2z=18.\begin{aligned} 6(x - 1) + 3(y - 2) + 2(z - 3) &= 0, \\ \text{that is,}\quad 6x + 3y + 2z &= 18. \end{aligned}

(b) Fz(1,2,3)=2≠0,F_z(1, 2, 3) = 2 \ne 0\mathclose{\text{,}} so ∂z∂x=−FxFz=−62=−3\dfrac{\partial z}{\partial x} = -\dfrac{F_x}{F_z} = -\dfrac62 = -3 and ∂z∂y=−FyFz=−32.\dfrac{\partial z}{\partial y} = -\dfrac{F_y}{F_z} = -\dfrac32\mathclose{\text{.}}

(c) Solved for z,z\mathclose{\text{,}} the tangent plane is z=9−3x−32y,z = 9 - 3x - \tfrac32 y\mathclose{\text{,}} whose slopes are −3-3 and −32.-\tfrac32\mathclose{\text{.}} And z=6xy,z = \dfrac{6}{xy}\mathclose{\text{,}} so at (1,2),(1, 2)\mathclose{\text{,}} zx=−6x2y=−62=−3z_x = -\dfrac{6}{x^2y} = -\dfrac62 = -3 and zy=−6xy2=−64=−32.z_y = -\dfrac{6}{xy^2} = -\dfrac64 = -\dfrac32\mathclose{\text{.}}

Exercise 17.9★★Laplace’s equation

Show that u(x,y)=ln⁡(x2+y2)u(x, y) = \ln(x^2 + y^2) satisfies Laplace’s equation uxx+uyy=0u_{xx} + u_{yy} = 0 for (x,y)≠(0,0),(x, y) \ne (0, 0)\mathclose{\text{,}} and check that uxy=uyx.u_{xy} = u_{yx}\mathclose{\text{.}}

Show solution✓ Checked

From Exercise 17.2(b), ux=2xx2+y2u_x = \dfrac{2x}{x^2 + y^2} and uy=2yx2+y2.u_y = \dfrac{2y}{x^2 + y^2}\mathclose{\text{.}} By the quotient rule, holding yy fixed,

uxx=2(x2+y2)−2x⋅2x(x2+y2)2=2(y2−x2)(x2+y2)2,\begin{aligned} u_{xx} &= \frac{2(x^2 + y^2) - 2x\cdot 2x}{(x^2 + y^2)^2} \\ &= \frac{2(y^2 - x^2)}{(x^2 + y^2)^2}, \end{aligned}

and in the same way, holding xx fixed, uyy=2(x2−y2)(x2+y2)2.u_{yy} = \dfrac{2(x^2 - y^2)}{(x^2 + y^2)^2}\mathclose{\text{.}} The two cancel: uxx+uyy=0.u_{xx} + u_{yy} = 0\mathclose{\text{.}}

For the mixed partial derivatives, the numerator 2x2x of uxu_x is a constant when xx is held fixed, so

uxy=2x⋅−2y(x2+y2)2=−4xy(x2+y2)2,u_{xy} = 2x\cdot\frac{-2y}{(x^2 + y^2)^2} = -\frac{4xy}{(x^2 + y^2)^2},

and in the same way uyx=2y⋅−2x(x2+y2)2=−4xy(x2+y2)2.u_{yx} = 2y\cdot\dfrac{-2x}{(x^2 + y^2)^2} = -\dfrac{4xy}{(x^2 + y^2)^2}\mathclose{\text{.}} They are equal, as Clairaut’s theorem predicts: both are continuous away from the origin.

Exercise 17.10★★★When Clairaut’s theorem does not apply

Let f(x,y)=xy(x2−y2)x2+y2f(x, y) = \dfrac{xy(x^2 - y^2)}{x^2 + y^2} for (x,y)≠(0,0),(x, y) \ne (0, 0)\mathclose{\text{,}} and f(0,0)=0.f(0, 0) = 0\mathclose{\text{.}}

  • (a) Show that fx(0,y)=−yf_x(0, y) = -y for every y,y\mathclose{\text{,}} and that fy(x,0)=xf_y(x, 0) = x for every x.x\mathclose{\text{.}}
  • (b) Deduce that fxy(0,0)=−1f_{xy}(0, 0) = -1 and fyx(0,0)=1.f_{yx}(0, 0) = 1\mathclose{\text{.}}
  • (c) Which hypothesis of Clairaut’s theorem fails?
Show solution✓ Checked

(a) Fix y≠0.y \ne 0\mathclose{\text{.}} Since f(0,y)=0,f(0, y) = 0\mathclose{\text{,}} the definition gives

fx(0,y)=lim⁡h→0f(h,y)−0h=lim⁡h→0y(h2−y2)h2+y2=y(−y2)y2=−y,\begin{aligned} f_x(0, y) &= \lim_{h\to0}\frac{f(h, y) - 0}{h} = \lim_{h\to0}\frac{y(h^2 - y^2)}{h^2 + y^2} \\ &= \frac{y(-y^2)}{y^2} = -y, \end{aligned}

by direct substitution, since the denominator tends to y2≠0.y^2 \ne 0\mathclose{\text{.}} For y=0:y = 0\mathclose{\text{:}} f(h,0)=0f(h, 0) = 0 for every h,h\mathclose{\text{,}} so fx(0,0)=0=−0.f_x(0, 0) = 0 = -0\mathclose{\text{.}} So fx(0,y)=−yf_x(0, y) = -y for every y.y\mathclose{\text{.}} In the same way, for x≠0,x \ne 0\mathclose{\text{,}} since f(x,0)=0,f(x, 0) = 0\mathclose{\text{,}}

fy(x,0)=lim⁡h→0f(x,h)h=lim⁡h→0x(x2−h2)x2+h2=x,\begin{aligned} f_y(x, 0) &= \lim_{h\to0}\frac{f(x, h)}{h} \\ &= \lim_{h\to0}\frac{x(x^2 - h^2)}{x^2 + h^2} = x, \end{aligned}

and fy(0,0)=0f_y(0, 0) = 0 because f(0,h)=0.f(0, h) = 0\mathclose{\text{.}} So fy(x,0)=xf_y(x, 0) = x for every x.x\mathclose{\text{.}}

(b) fxy(0,0)f_{xy}(0, 0) is the derivative of y↦fx(0,y)=−yy \mapsto f_x(0, y) = -y at y=0,y = 0\mathclose{\text{,}} which is −1.-1\mathclose{\text{.}} fyx(0,0)f_{yx}(0, 0) is the derivative of x↦fy(x,0)=xx \mapsto f_y(x, 0) = x at x=0,x = 0\mathclose{\text{,}} which is 1.1\mathclose{\text{.}}

(c) Clairaut’s theorem needs fxyf_{xy} and fyxf_{yx} to be continuous on a disc around the origin. They cannot both be, or the theorem would make them equal there. Indeed, for (x,y)≠(0,0)(x, y) \ne (0, 0) the rules give

fxy=x6+9x4y2−9x2y4−y6(x2+y2)3,f_{xy} = \frac{x^6 + 9x^4y^2 - 9x^2y^4 - y^6}{(x^2 + y^2)^3},

which is 1 on the xx-axis and −1-1 on the yy-axis away from the origin, so it has no limit there. The function itself is continuous: since ∣x2−y2∣≤x2+y2,\abs{x^2 - y^2} \le x^2 + y^2\mathclose{\text{,}} it is squeezed by ∣f∣≤∣xy∣→0\abs{f} \le \abs{xy} \to 0 at the origin. It has both first partial derivatives everywhere; the continuity of the mixed partial derivatives is the hypothesis that fails.

Exercise 17.11★★★Backpropagation through a shared weight

A recurrent network applies the same step twice, with the same parameters ww and b:b\mathclose{\text{:}} from an input xx it computes h1=wx+b,h_1 = wx + b\mathclose{\text{,}} then h2=wh1+b,h_2 = wh_1 + b\mathclose{\text{,}} and its loss is L=(h2−t)2L = (h_2 - t)^2 for a target t.t\mathclose{\text{.}}

  • (a) Draw the computational graph, with its local derivatives. Which nodes have two children?
  • (b) With x=1,x = 1\mathclose{\text{,}} t=5,t = 5\mathclose{\text{,}} w=2w = 2 and b=1,b = 1\mathclose{\text{,}} do a forward and a backward pass to find ∂L/∂w\partial L/\partial w and ∂L/∂b.\partial L/\partial b\mathclose{\text{.}}
  • (c) Check by writing LL as a function of ww and bb and differentiating.
  • (d) Take one step of gradient descent with η=0.01.\eta = 0.01\mathclose{\text{.}} Does the loss decrease?
Show solution✓ Checked

(a) The nodes are w,w\mathclose{\text{,}} b,b\mathclose{\text{,}} h1=wx+b,h_1 = wx + b\mathclose{\text{,}} h2=wh1+bh_2 = wh_1 + b and L=(h2−t)2;L = (h_2 - t)^2\mathclose{\text{;}} the input xx and the target tt are constants. The arrows run w→h1w \to h_1 and b→h1;b \to h_1\mathclose{\text{;}} w→h2,w \to h_2\mathclose{\text{,}} b→h2b \to h_2 and h1→h2;h_1 \to h_2\mathclose{\text{;}} and h2→L.h_2 \to L\mathclose{\text{.}} The parameters ww and bb each have two children, h1h_1 and h2,h_2\mathclose{\text{,}} because they are used at both steps. The local derivatives are ∂h1/∂w=x,\partial h_1/\partial w = x\mathclose{\text{,}} ∂h1/∂b=1,\partial h_1/\partial b = 1\mathclose{\text{,}} ∂h2/∂w=h1,\partial h_2/\partial w = h_1\mathclose{\text{,}} ∂h2/∂b=1,\partial h_2/\partial b = 1\mathclose{\text{,}} ∂h2/∂h1=w\partial h_2/\partial h_1 = w and ∂L/∂h2=2(h2−t).\partial L/\partial h_2 = 2(h_2 - t)\mathclose{\text{.}}

(b) Forward: h1=2⋅1+1=3,h_1 = 2 \cdot 1 + 1 = 3\mathclose{\text{,}} h2=2⋅3+1=7h_2 = 2 \cdot 3 + 1 = 7 and L=(7−5)2=4.L = (7 - 5)^2 = 4\mathclose{\text{.}} Backward: Lˉ=1;\bar L = 1\mathclose{\text{;}} hˉ2=Lˉ⋅2(h2−t)=4;\bar h_2 = \bar L \cdot 2(h_2 - t) = 4\mathclose{\text{;}} hˉ1=hˉ2⋅w=8.\bar h_1 = \bar h_2 \cdot w = 8\mathclose{\text{.}} Each parameter adds the contributions of its two children:

wˉ=hˉ2⋅h1+hˉ1⋅x=4⋅3+8⋅1=20,bˉ=hˉ2⋅1+hˉ1⋅1=4+8=12.\begin{aligned} \bar w &= \bar h_2 \cdot h_1 + \bar h_1 \cdot x = 4 \cdot 3 + 8 \cdot 1 = 20, \\ \bar b &= \bar h_2 \cdot 1 + \bar h_1 \cdot 1 = 4 + 8 = 12. \end{aligned}

So ∂L/∂w=20\partial L/\partial w = 20 and ∂L/∂b=12.\partial L/\partial b = 12\mathclose{\text{.}}

(c) h2=w(wx+b)+b=w2x+wb+b,h_2 = w(wx + b) + b = w^2x + wb + b\mathclose{\text{,}} so L=(w2x+wb+b−t)2,L = (w^2x + wb + b - t)^2\mathclose{\text{,}} and by the chain rule

Lw=2(h2−t)(2wx+b)=2⋅2⋅5=20,Lb=2(h2−t)(w+1)=2⋅2⋅3=12.\begin{aligned} L_w &= 2(h_2 - t)(2wx + b) = 2 \cdot 2 \cdot 5 = 20, \\ L_b &= 2(h_2 - t)(w + 1) = 2 \cdot 2 \cdot 3 = 12. \end{aligned}

(d) ⟨w,b⟩=⟨2,1⟩−0.01 ⟨20,12⟩=⟨1.8,0.88⟩.\langle w, b\rangle = \langle 2, 1\rangle - 0.01\,\langle 20, 12\rangle = \langle 1.8, 0.88\rangle\mathclose{\text{.}} Then h1=1.8+0.88=2.68,h_1 = 1.8 + 0.88 = 2.68\mathclose{\text{,}} h2=1.8⋅2.68+0.88=5.704,h_2 = 1.8 \cdot 2.68 + 0.88 = 5.704\mathclose{\text{,}} and L=0.7042≈0.496:L = 0.704^2 \approx 0.496\mathclose{\text{:}} the loss has dropped from 4.

11

Check yourself

1
The level sets of f(x,y)=x2+4y2,f(x, y) = x^2 + 4y^2\mathclose{\text{,}} for values in its range, are
2
For f(x,y)=x2y3,f(x, y) = x^2y^3\mathclose{\text{,}} fxf_x is
3
Along the line y=2x,y = 2x\mathclose{\text{,}} with x≠0,x \ne 0\mathclose{\text{,}} the function xyx2+y2\dfrac{xy}{x^2 + y^2} equals
4
The tangent plane to z=x2+y2z = x^2 + y^2 at (1,2,5)(1, 2, 5) is
5
ff is differentiable at a point where ∇f=⟨3,−4⟩.\nabla f = \langle 3, -4\rangle\mathclose{\text{.}} Which statement is true?
6
Clairaut’s theorem says that fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b) if
7
One step of gradient descent on f(x,y)=x2+y2f(x, y) = x^2 + y^2 from (1,2)(1, 2) with η=0.25\eta = 0.25 leads to
8
In a backward pass, a node vv whose value is used by two later nodes c1c_1 and c2c_2 gets the adjoint
Finished this module?