Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 39 · The Gradient and Directional Derivatives

Directional Derivatives

Find the rate of change of f in any direction with D_u f = ∇f · u, and learn why the gradient gives the direction and size of the steepest ascent.

Partial derivatives give rates of change along the x and y axes. But you can walk in any direction. The directional derivative gives the rate of change of f as you move in a chosen direction. With the gradient it takes one dot product to compute.

Definition

Let u = ⟨a, b⟩ be a unit vector (length 1). The directional derivative of f at (x₀, y₀) in direction u is

Text
D_u f(x₀, y₀) = lim (h→0) [f(x₀ + h a, y₀ + h b) - f(x₀, y₀)] / h

It is the slope of the graph along the vertical slice in the direction u. Note D_i f = f_x and D_j f = f_y: partial derivatives are special cases.

The formula

If f is differentiable, then

Text
D_u f = ∇f · u = f_x a + f_y b

Why? Along the line x = x₀ + h a, y = y₀ + h b, the chain rule gives d/dh f = f_x · a + f_y · b.

Worked example 1: f(x, y) = x² y at (2, 1) in the direction of v = ⟨3, 4⟩. First make a unit vector: |v| = 5, u = ⟨3/5, 4/5⟩. The gradient is ∇f = ⟨2xy, x²⟩ = ⟨4, 4⟩ at (2, 1). So D_u f = 4(3/5) + 4(4/5) = 28/5 = 5.6.

Worked example 2: f(x, y, z) = xyz at (1, 2, 3) toward the origin. The direction from the point to the origin is ⟨-1, -2, -3⟩, length √14, so u = ⟨-1, -2, -3⟩/√14. ∇f = ⟨yz, xz, xy⟩ = ⟨6, 3, 2⟩. D_u f = (-6 - 6 - 6)/√14 = -18/√14 ≈ -4.81. Walking toward the origin decreases xyz.

Python Directional derivative: formula vs finite difference

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Direction angle form

In two dimensions, if u = ⟨cos θ, sin θ⟩ then D_u f = f_x cos θ + f_y sin θ. Since ∇f · u = |∇f| cos φ where φ is the angle between ∇f and u, we get

Text
D_u f = |∇f| cos φ

This tells us everything:

  • Maximum when φ = 0 (u along the gradient): D_u f = |∇f|.
  • Minimum when φ = π (u opposite the gradient): D_u f = -|∇f|.
  • Zero when φ = π/2 (u perpendicular to the gradient, i.e. along the level curve): no change.

Theorem. The maximum value of D_u f is |∇f|, attained when u points in the direction of ∇f (provided ∇f ≠ 0).

Worked example: the temperature on a metal plate is T(x, y) = 100 - x² - 2y² degrees Celsius. At (1, 2), ∇T = ⟨-2x, -4y⟩ = ⟨-2, -8⟩. The fastest increase of temperature is toward ⟨-2, -8⟩/√68, at rate √68 ≈ 8.25 °C per unit distance. The fastest decrease is the opposite direction. If you walk along ⟨8, -2⟩/√68, which is perpendicular to the gradient, the temperature does not change (first order).

Python Sweep all directions at a point

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The curve is a cosine wave whose peak height is |∇f| and whose peak location is the gradient's direction.

Directional derivative

Pick a unit vector u
D_u f = ∇f · u
Max = |∇f| When u follows the gradient
1 / 2

Always normalize the direction vector. If you use ⟨3, 4⟩ instead of ⟨3/5, 4/5⟩ the answer is 5 times too large.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. For f(x, y) = x² + y² at (1, 1), D_u f in direction u = ⟨1/√2, 1/√2⟩ is

    ∇f = ⟨2, 2⟩, so ∇f · u = 2/√2 + 2/√2 = 4/√2 = 2√2.
  2. 2. The maximum rate of change of f at a point is

    D_u f = |∇f| cos φ is largest, equal to |∇f|, when φ = 0.
  3. 3. In which direction is D_u f = 0 (when ∇f ≠ 0)?

    cos 90° = 0: moving along the level curve does not change f to first order.
  4. 4. Before using D_u f = ∇f · u, the vector u must be

    The formula assumes |u| = 1; otherwise the result is scaled by |u|.

Summary

  • D_u f = ∇f · u for a unit vector u gives the slope of f in that direction.
  • D_u f = |∇f| cos φ: maximum |∇f| along the gradient, minimum -|∇f| against it, zero perpendicular.
  • Always normalize the direction vector first.

Next: Gradients, Level Sets and Tangent Planes