Back to the on-screen lesson ·

Directional derivatives and the gradient

The rate of change of a function in any direction as a dot product with the gradient, and the three things the gradient then tells you at once: which way is steepest, how steep it is, and which way is level.

Paper packet. Every task here also exists on screen, where it is checked automatically; answers written on paper are not assessed by Nydus. When you are back at a device, enter your answers there.

1. What you will learn

By the end of this lesson you will be able to compute the gradient of a function of two or three variables, use it to find the rate of change in any given direction after normalising that direction, name the direction of steepest increase and the rate along it, and use the fact that the gradient is perpendicular to a level curve or level surface to write down a tangent plane.

2. What you already have

Partial derivatives, which give the rate of change along the two coordinate axes, and the dot product, which turns two vectors into a length times a cosine. This lesson is those two facts multiplied together: the rate of change in any direction turns out to be a dot product of the partials with that direction, and everything else follows from reading that dot product carefully.

3. The words this lesson will use

The directional derivative $D_{\mathbf{u}}f$ is the rate of change of $f$ in the direction of a unit vector $\mathbf{u}$. The gradient $\nabla f$ is the vector of partial derivatives, $\langle f_x, f_y \rangle$ in two variables and $\langle f_x, f_y, f_z \rangle$ in three. A level curve is a set where $f$ is constant — a contour on a map — and a level surface is the same idea one dimension up. The symbol $\nabla$ is read del or nabla.

4. One dot product answers every direction at once

Fix a point and a unit vector $\mathbf{u} = \langle u_1, u_2 \rangle$. The rate of change of $f$ as you set off in that direction is

$$D_{\mathbf{u}}f = \lim_{h \to 0} \frac{f(a + hu_1,\, b + hu_2) - f(a, b)}{h} = f_x(a,b)\,u_1 + f_y(a,b)\,u_2.$$

The right-hand side is a dot product. Collecting the partials into one vector, the gradient

$$\nabla f = \langle f_x,\, f_y \rangle, \qquad D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u}.$$

Taking $\mathbf{u} = \mathbf{i}$ recovers $f_x$ and taking $\mathbf{u} = \mathbf{j}$ recovers $f_y$, so the two partials were never special: they are two of infinitely many directional derivatives, and the gradient holds all of them.

The three readings of the gradient. Write $D_{\mathbf{u}}f = |\nabla f|\,|\mathbf{u}|\cos\theta = |\nabla f|\cos\theta$. Then:

The third is the geometric one: the gradient is perpendicular to the level curve through the point, because moving along a level curve changes nothing.

Level surfaces and tangent planes. In three variables the same argument gives that $\nabla F$ is perpendicular to the level surface $F(x, y, z) = k$. So the tangent plane to that surface at $P = (a, b, c)$ has $\nabla F(P)$ as its normal:

$$F_x(P)(x - a) + F_y(P)(y - b) + F_z(P)(z - c) = 0.$$

This is the general form of the tangent plane from the last lesson, and it works on surfaces like $x^2 + y^2 + z^2 = 9$ that no single $z = f(x, y)$ describes.

Another way: picture

Lay a contour map flat. At any point the gradient is an arrow drawn on the map — not on the hill — pointing straight across the contour lines towards higher ground, and long where the contours are crowded together. Walking along a contour is walking at right angles to it, which is why a path that stays level always crosses the gradient arrow squarely.

Another way: steps

To find a rate of change in a stated direction:

  1. Compute $f_x$ and $f_y$, then substitute the point: that is $\nabla f$.
  2. Take the direction you were given and divide it by its own length, unless you were told it is already a unit vector.
  3. Dot the two together.
  4. For the steepest direction, skip step 2 entirely: the answer is $\nabla f$ itself, and the rate is $|\nabla f|$.
  5. For a direction of no change, take anything perpendicular to $\nabla f$.

5. Why the gradient is perpendicular to the level curve

Suppose a curve $\mathbf{r}(t)$ stays on the level curve $f = k$, so that $f(\mathbf{r}(t)) = k$ for every $t$. Differentiate both sides. The left-hand side is handled by the chain rule of lesson 17, which gives $\nabla f \cdot \mathbf{r}'(t)$; the right-hand side is constant, so its derivative is zero. Hence

$$\nabla f \cdot \mathbf{r}'(t) = 0.$$

But $\mathbf{r}'(t)$ is tangent to the level curve. So the gradient is perpendicular to every tangent of every curve lying in the level set — which is what perpendicular to the level curve means.

Two things are worth noticing. First, the argument never used two variables: run it with $\mathbf{r}(t)$ in space and $F$ a function of three variables and it says the gradient is normal to the level surface, which is where the tangent-plane formula above comes from. Second, it explains why the gradient grows where contours crowd: a short step across a narrow gap between contours changes $f$ by the same amount as a long step across a wide one, so the rate — and the arrow — is larger.

6. Where this goes wrong

Forgetting to normalise the direction. $D_{\mathbf{u}}f$ is defined for a unit vector. Dotting the gradient with $\langle 3, 4 \rangle$ instead of $\langle 3/5, 4/5 \rangle$ gives five times the truth, and nothing in the arithmetic complains.

Thinking the gradient points along the surface. It lives in the domain — the $xy$ plane for a function of two variables — and gives a compass bearing, not an uphill direction in space. The vector that points up the hill has a third component; the gradient does not.

Reading $|\nabla f|$ as a value of $f$. It is a rate: units of $f$ per unit of distance.

Using the formula at a point where the partials do not exist or $f$ is not differentiable. The identity $D_{\mathbf{u}}f = \nabla f \cdot \mathbf{u}$ is a theorem with a hypothesis, and at a corner of a surface it can fail while both partials exist perfectly well.

7. The gradient is not the direction the surface slopes in

It is a vector in the domain: two components for a function of two variables, three for a function of three. It says which way to walk on the map, and its length says how fast the value then changes. The uphill direction in three-dimensional space is a different vector with a vertical component, and the two are easy to conflate because both are called steepest ascent.

The same confusion, one dimension up, causes real trouble: for $F(x, y, z)$ the gradient $\nabla F$ is a vector in space and it is normal to the level surface, not tangent to it. Learners who have absorbed the gradient points uphill often expect it to lie along the surface. It does not — it is the one direction that leaves the surface as fast as possible, and that is precisely why it serves as the normal in the tangent plane formula.

8. A rate in a given direction

  1. For $f(x, y) = x^2y$ at $(3, 2)$: $f_x = 2xy = 12$ and $f_y = x^2 = 9$, so $\nabla f = \langle 12, 9 \rangle$.

    The gradient is the partials evaluated at the point.

  2. In the direction of $\langle 4, -3 \rangle$, whose length is $5$, the unit vector is $\langle 4/5, -3/5 \rangle$.

    Divide the given direction by its length.

  3. So $D_{\mathbf{u}}f = 12 \cdot \tfrac45 + 9 \cdot \left(-\tfrac35\right) = \tfrac{48}{5} - \tfrac{27}{5} = \tfrac{21}{5}$, and the steepest rate available at that point is $|\nabla f| = 15$.

    This direction climbs, but at well under the best rate on offer.

9. A tangent plane from a level surface

  1. The sphere $x^2 + y^2 + z^2 = 14$ is a level surface of $F(x, y, z) = x^2 + y^2 + z^2$, and $(1, 2, 3)$ lies on it.

    No formula $z = f(x, y)$ is needed.

  2. $\nabla F = \langle 2x, 2y, 2z \rangle$, which at the point is $\langle 2, 4, 6 \rangle$.

    The gradient is normal to the level surface.

  3. So the tangent plane is $2(x - 1) + 4(y - 2) + 6(z - 3) = 0$, or $x + 2y + 3z = 14$. The normal came out parallel to the position vector of the point, which is the sphere telling you something true about itself.

    A normal and a point are all a plane ever needs.

10. Your turn: the steepest climb on a hill

  1. A hill has height $h(x, y) = 100 - 2x^2 - 3y^2$. At $(2, 1)$, $h_x = -4x = -8$ and $h_y = -6y = -6$.

    Compute the two partials and substitute the point.

  2. So $\nabla h = \langle -8, -6 \rangle$, of length $10$. The walker climbs fastest heading in the direction $\langle -8, -6 \rangle$, that is towards the summit at the origin.

  3. Your turn: work this step out. Its working is at the end of the packet.

    And the steepest rate is $10$ metres of height per metre travelled on the map. That is a very steep hill — worth noticing, because the number is a rate rather than a height, and a reader who mistakes it for one has the walker $10$ metres up rather than on a one-in-ten-thousand slope.

11. Guided practice

Write $\nabla f$ at $(4, 3)$ as a row, for $f(x, y) = x^2 + 2xy + 5y^2$.

This task has no paper form; do it on a device.

12. Guided practice

At a point the gradient of $f$ has length $5$. Match each question to its answer.

Along the gradientAt the rate $5$At right angles to the gradientStraight against the gradient
Which way does $f$ increase fastest?
How fast does it increase that way?
Which way does $f$ not change at all?
Which way does $f$ decrease fastest?

13. Practice

For $f(x, y) = 15x + 25y$, find the rate of change of $f$ in the direction of $\langle 3, 4 \rangle$.

Answer:

14. Practice

At a point $|\nabla f| = 16$, and a unit vector $\mathbf{u}$ makes an angle of $60^\circ$ with $\nabla f$. What is $D_{\mathbf{u}}f$ there?

Answer:

15. Practice

Write $\nabla f$ at $(1, 3)$ as a row, for $f(x, y) = 3x^2 + 4xy + 5y^2$.

This task has no paper form; do it on a device.

16. Somewhere new

A walker stands on a hillside where the gradient of the height function has length $8$ metres per metre. They want to walk without gaining or losing height. Which way should they set off?

17. Lesson test

Lesson test: one question per skill, one attempt each, no hints. Your answers are checked when you submit.

18. Test question

At a point the gradient of $f$ has length $9$. Match each question to its answer.

Along the gradientAt the rate $9$At right angles to the gradientStraight against the gradient
Which way does $f$ increase fastest?
How fast does it increase that way?
Which way does $f$ not change at all?
Which way does $f$ decrease fastest?

19. What you can do now

You can turn a function and a direction into a rate of change, and you can say what the gradient's direction, its length and its perpendicular all mean on a contour map. Next: the points where the gradient is zero, and how to tell a summit from a pass.

Working for the steps left to you

10. Your turn: the steepest climb on a hill, step 3