Directional Derivatives and the Gradient
The gradient of f(x, y) is the vector ∇f = ⟨fx, fy⟩. The directional derivative in the direction of a unit vector u is Duf = ∇f · u, the rate f changes as you move that way. The gradient points in the direction of steepest increase, and its length is that greatest rate.
Before this lesson: Partial Derivatives, Multivariable Chain Rule, Dot Product and Vectors in 3D
Slope in any direction
Picture standing on a hillside where your height is f(x, y). The slope you feel depends on which way you walk. The partial derivative f_x is the slope walking east, and f_y is the slope walking north. The directional derivative gives the slope for any other direction.
If you walk from (a, b) along a unit vector u = ⟨u₁, u₂⟩, your position is (a + tu₁, b + tu₂). By the multivariable chain rule, the rate of change of f is f_x u_1 + f_y u_2, which is the dot product of ⟨fx, fy⟩ with u. That vector of partial derivatives is the gradient.
Gradient and directional derivative formulas
\nabla f = \langle f_x, f_y \rangle, \qquad D_{\mathbf{u}} f(a, b) = \nabla f(a, b) \cdot \mathbf{u} = f_x u_1 + f_y u_2- u must be a unit vector. If a direction is given as a vector v, use \mathbf{u} = \dfrac{\mathbf{v}}{|\mathbf{v}|}. If it is given as an angle θ from the positive x-axis, use u = ⟨cos θ, sin θ⟩.
- Steepest increase: f increases fastest in the direction of ∇f, at the rate |∇f|.
- Steepest decrease: f decreases fastest in the direction of −∇f, at the rate −|∇f|.
- No change: D_{\mathbf{u}} f = 0 when u is perpendicular to ∇f, which is along the level curve.
- Why: D_{\mathbf{u}} f = |\nabla f| \cos\theta, where θ is the angle between ∇f and u. This is largest when θ = 0.
- Three variables: ∇f = ⟨fx, fy, fz⟩, and the same rules hold. The gradient is perpendicular to level curves and level surfaces.
Directional derivative examples
Example 1: Direction given by a vector
Find the directional derivative of f(x, y) = x² + 3xy at (1, 2) in the direction of v = ⟨3, 4⟩.
\nabla f = \langle 2x + 3y, \ 3x \rangle
Find the partial derivatives.
\nabla f(1, 2) = \langle 2 + 6, \ 3 \rangle = \langle 8, 3 \rangle
Evaluate at (1, 2).
|\mathbf{v}| = \sqrt{3^2 + 4^2} = 5Find the length of v.
\mathbf{u} = \left\langle \dfrac{3}{5}, \dfrac{4}{5} \right\rangleDivide v by its length to get a unit vector.
D_{\mathbf{u}} f = 8\left(\dfrac{3}{5}\right) + 3\left(\dfrac{4}{5}\right)Take the dot product ∇f · u.
= \dfrac{24}{5} + \dfrac{12}{5}Multiply.
= \dfrac{36}{5} = 7.2Add.
Answer: D_{\mathbf{u}} f(1, 2) = 7.2. Moving from (1, 2) toward ⟨3, 4⟩, f increases about 7.2 units per unit of distance.
Example 2: Direction given by an angle
Find the directional derivative of f(x, y) = xy² at (2, 1) in the direction θ = π/6.
\nabla f = \langle y^2, \ 2xy \rangle
Find the partial derivatives.
\nabla f(2, 1) = \langle 1, 4 \rangle
Evaluate at (2, 1).
\mathbf{u} = \left\langle \cos\dfrac{\pi}{6}, \sin\dfrac{\pi}{6} \right\rangle = \left\langle \dfrac{\sqrt{3}}{2}, \dfrac{1}{2} \right\rangleUnit vector from the angle (see unit circle).
D_{\mathbf{u}} f = 1\left(\dfrac{\sqrt{3}}{2}\right) + 4\left(\dfrac{1}{2}\right)Dot product.
= \dfrac{\sqrt{3}}{2} + 2Multiply.
\approx 2.866
Use √3 ≈ 1.732.
Answer: D_{\mathbf{u}} f(2, 1) = \dfrac{\sqrt{3}}{2} + 2 \approx 2.866.
Example 3: Steepest ascent on a hill
The height of a hill is f(x, y) = 4 − x² − 2y². At (1, 1), find the direction of steepest ascent, the greatest rate of increase, and the directions in which the height does not change.
\nabla f = \langle -2x, \ -4y \rangle
Find the partial derivatives.
\nabla f(1, 1) = \langle -2, -4 \rangle
Evaluate at (1, 1). This is the direction of steepest ascent.
|\nabla f| = \sqrt{(-2)^2 + (-4)^2}The greatest rate is the length of the gradient.
= \sqrt{20}Square and add.
= 2\sqrt{5} \approx 4.47Simplify the root (see simplifying square roots).
\langle -2, -4 \rangle \cdot \langle 2, -1 \rangle = -4 + 4 = 0
⟨2, −1⟩ is perpendicular to the gradient.
\mathbf{u} = \pm\left\langle \dfrac{2}{\sqrt{5}}, -\dfrac{1}{\sqrt{5}} \right\rangleDivide by |⟨2, −1⟩| = √5 for unit vectors.
Answer: climb fastest in the direction ⟨−2, −4⟩ (toward the top at the origin), at a rate of 2√5 ≈ 4.47. The height stays the same in the directions ±⟨2, −1⟩/√5, along the level curve.
Example 4: Three variables
Find the rate of change of f(x, y, z) = xyz + z² at (1, 2, 1) in the direction of the point (3, 4, 2).
\nabla f = \langle yz, \ xz, \ xy + 2z \rangle
Find the three partial derivatives.
\nabla f(1, 2, 1) = \langle 2, 1, 4 \rangle
Evaluate at (1, 2, 1).
\mathbf{v} = \langle 3 - 1, \ 4 - 2, \ 2 - 1 \rangle = \langle 2, 2, 1 \rangleThe direction from (1, 2, 1) to (3, 4, 2).
|\mathbf{v}| = \sqrt{4 + 4 + 1} = 3Find the length.
\mathbf{u} = \left\langle \dfrac{2}{3}, \dfrac{2}{3}, \dfrac{1}{3} \right\rangleUnit vector.
D_{\mathbf{u}} f = 2\left(\dfrac{2}{3}\right) + 1\left(\dfrac{2}{3}\right) + 4\left(\dfrac{1}{3}\right)Dot product.
= \dfrac{4}{3} + \dfrac{2}{3} + \dfrac{4}{3}Multiply.
= \dfrac{10}{3}Add.
Answer: D_{\mathbf{u}} f = \dfrac{10}{3} \approx 3.33.
Example 5: Hiking on a mountain (word problem)
The height of a mountain is h(x, y) = 1200 − 0.001x² − 0.002y² meters, where x is meters east and y is meters north of a marker. A hiker stands at (300, 100). Which way is the steepest climb, and how steep is it? What happens if the hiker walks northeast?
\nabla h = \langle -0.002x, \ -0.004y \rangle
Find the partial derivatives.
\nabla h(300, 100) = \langle -0.6, -0.4 \rangle
Evaluate at (300, 100).
|\nabla h| = \sqrt{0.36 + 0.16} = \sqrt{0.52}Length of the gradient.
\approx 0.721
Take the square root.
\mathbf{u} = \left\langle \dfrac{1}{\sqrt{2}}, \dfrac{1}{\sqrt{2}} \right\rangleNortheast is the unit vector at 45°.
D_{\mathbf{u}} h = \dfrac{-0.6}{\sqrt{2}} + \dfrac{-0.4}{\sqrt{2}}Dot product.
= \dfrac{-1}{\sqrt{2}} \approx -0.707Add and divide.
Answer: the steepest climb is in the direction ⟨−0.6, −0.4⟩, mostly west and a little south, rising about 0.721 m per meter walked. Walking northeast, the hiker goes downhill at about 0.707 m per meter.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Not using a unit vector | In Example 1, ⟨8, 3⟩ · ⟨3, 4⟩ = 36 | Divide v by |v| = 5 first; the answer is 36/5 = 7.2. |
| Leaving the gradient unevaluated | Duf = (2x + 3y)(3/5) + 3x(4/5) at (1, 2), left as an expression | Evaluate ∇f at the point, so the answer is a number. |
| Giving a vector for the greatest rate | “The greatest rate is ⟨−2, −4⟩” | The rate is the number |∇f| = 2√5; the vector is the direction. |
| Thinking ∇f runs along a level curve | Drawing ∇f tangent to the contour | ∇f crosses level curves at right angles; the tangent direction gives zero change. |
| Swapping sine and cosine | u = ⟨sin θ, cos θ⟩ for θ = π/6 | u = ⟨cos θ, sin θ⟩ when θ is measured from the positive x-axis. |
Related methods
Gradients and tangent planes
For a surface F(x, y, z) = k, the gradient ∇F is perpendicular to the surface. That is why ⟨Fx, Fy, Fz⟩ is the normal vector in the formula for tangent planes.
Rate of change along a path
If a point moves along a curve r(t), the chain rule says \dfrac{d}{dt} f(\mathbf{r}(t)) = \nabla f \cdot \mathbf{r}'(t). When r′(t) is a unit vector, this is exactly the directional derivative.
Gradient and critical points
Where ∇f = 0, no direction goes up or down to first order. These are the critical points used in the next lesson to find maximums and minimums.
Practice problems
- Find the gradient of f(x, y) = x³y − 2y².
- Find the directional derivative of f(x, y) = x²y at (1, 3) in the direction of ⟨1, 1⟩.
- Find the directional derivative of f(x, y) = ln(x² + y²) at (1, 2) in the direction of ⟨−4, 3⟩.
- Find the directional derivative of f(x, y) = sin x cos y at (0, 0) in the direction θ = π/3.
- Find the greatest rate of increase of f(x, y) = xeʸ at (2, 0) and the direction in which it happens.
- In which direction does f(x, y) = x² + y² decrease fastest at (3, 4), and at what rate?
- Find the unit vectors along which f(x, y) = x²y does not change at (1, 2).
- Find the rate of change of f(x, y, z) = x² + y² + z² at (1, 2, 2) in the direction of the origin.
- Show that the gradient of f(x, y) = x² + y² at (3, 4) is perpendicular to the circle x² + y² = 25 there.
- The temperature on a plate is T(x, y) = 60 + 2x − 3y + xy degrees Celsius, with x and y in centimeters. A bug at (1, 2) wants to cool off as fast as possible. Which way should it move, and how fast does the temperature drop?
Show answers
1.
f_x = 3x^2y
Partial with respect to x.
f_y = x^3 - 4y
Partial with respect to y.
Answer: ∇f = ⟨3x²y, x³ − 4y⟩
2.
\nabla f = \langle 2xy, \ x^2 \rangle
Partial derivatives.
\nabla f(1, 3) = \langle 6, 1 \rangle
Evaluate at (1, 3).
\mathbf{u} = \left\langle \dfrac{1}{\sqrt{2}}, \dfrac{1}{\sqrt{2}} \right\rangle|⟨1, 1⟩| = √2.
D_{\mathbf{u}} f = \dfrac{6}{\sqrt{2}} + \dfrac{1}{\sqrt{2}}Dot product.
= \dfrac{7}{\sqrt{2}} \approx 4.95Add and divide.
Answer: 7/√2 ≈ 4.95
3.
\nabla f = \left\langle \dfrac{2x}{x^2 + y^2}, \ \dfrac{2y}{x^2 + y^2} \right\rangleChain rule on ln.
\nabla f(1, 2) = \left\langle \dfrac{2}{5}, \dfrac{4}{5} \right\rangleEvaluate: x² + y² = 5.
\mathbf{u} = \left\langle -\dfrac{4}{5}, \dfrac{3}{5} \right\rangle|⟨−4, 3⟩| = 5.
D_{\mathbf{u}} f = -\dfrac{8}{25} + \dfrac{12}{25}Dot product.
= \dfrac{4}{25} = 0.16Add.
Answer: 4/25 = 0.16
4.
\nabla f = \langle \cos x\cos y, \ -\sin x\sin y \rangle
Partial derivatives.
\nabla f(0, 0) = \langle 1, 0 \rangle
Evaluate at (0, 0).
\mathbf{u} = \left\langle \dfrac{1}{2}, \dfrac{\sqrt{3}}{2} \right\rangleu = ⟨cos(π/3), sin(π/3)⟩.
D_{\mathbf{u}} f = 1\left(\dfrac{1}{2}\right) + 0 = \dfrac{1}{2}Dot product.
Answer: 1/2
5.
\nabla f = \langle e^y, \ xe^y \rangle
Partial derivatives.
\nabla f(2, 0) = \langle 1, 2 \rangle
Evaluate at (2, 0).
|\nabla f| = \sqrt{1 + 4} = \sqrt{5}The greatest rate is the length.
Answer: greatest rate √5 ≈ 2.24, in the direction ⟨1, 2⟩, or the unit vector ⟨1/√5, 2/√5⟩
6.
\nabla f(3, 4) = \langle 6, 8 \rangle
∇f = ⟨2x, 2y⟩ at (3, 4).
|\nabla f| = \sqrt{36 + 64} = 10Length of the gradient.
-\dfrac{\nabla f}{|\nabla f|} = \left\langle -\dfrac{3}{5}, -\dfrac{4}{5} \right\rangleSteepest decrease is opposite the gradient.
Answer: direction ⟨−3/5, −4/5⟩, rate −10
7.
\nabla f(1, 2) = \langle 4, 1 \rangle
∇f = ⟨2xy, x²⟩ at (1, 2).
\langle 4, 1 \rangle \cdot \langle 1, -4 \rangle = 0
⟨1, −4⟩ is perpendicular to the gradient.
\mathbf{u} = \pm\left\langle \dfrac{1}{\sqrt{17}}, -\dfrac{4}{\sqrt{17}} \right\rangleDivide by |⟨1, −4⟩| = √17.
Answer: ±⟨1/√17, −4/√17⟩
8.
\nabla f(1, 2, 2) = \langle 2, 4, 4 \rangle
∇f = ⟨2x, 2y, 2z⟩ at the point.
\mathbf{u} = \left\langle -\dfrac{1}{3}, -\dfrac{2}{3}, -\dfrac{2}{3} \right\rangleToward the origin is −⟨1, 2, 2⟩, with length 3.
D_{\mathbf{u}} f = -\dfrac{2}{3} - \dfrac{8}{3} - \dfrac{8}{3}Dot product.
= -6
Add.
Answer: −6
9.
\nabla f(3, 4) = \langle 6, 8 \rangle
Gradient at (3, 4).
\langle -4, 3 \rangle
A tangent direction to the circle at (3, 4) (it is perpendicular to the radius ⟨3, 4⟩).
\langle 6, 8 \rangle \cdot \langle -4, 3 \rangle = -24 + 24 = 0
The dot product is 0.
Answer: the gradient is perpendicular to the circle at (3, 4).
10.
\nabla T = \langle 2 + y, \ -3 + x \rangle
Partial derivatives.
\nabla T(1, 2) = \langle 4, -2 \rangle
Evaluate at (1, 2).
-\nabla T = \langle -4, 2 \rangle
Cool fastest opposite the gradient.
|\nabla T| = \sqrt{16 + 4} = \sqrt{20} \approx 4.47Rate of the fastest change.
Answer: move in the direction ⟨−4, 2⟩ (unit vector ⟨−2/√5, 1/√5⟩); the temperature drops about 4.47 °C per centimeter.
Directional derivatives and the gradient FAQ
What is a directional derivative?
It is the rate of change of a function of several variables in a chosen direction. For a unit vector u, it equals the dot product ∇f · u.
What is the gradient of a function?
The gradient ∇f is the vector of partial derivatives, ⟨fx, fy⟩ or ⟨fx, fy, fz⟩. It points in the direction of fastest increase.
Why does the gradient point in the direction of steepest ascent?
The directional derivative equals |∇f| cos θ, where θ is the angle between ∇f and u. Cosine is largest when θ = 0, so the best direction is the gradient itself.
Why must the direction be a unit vector?
The directional derivative measures change per unit of distance. A longer vector would scale the answer up, so you divide by its length first.
Summary
- The gradient is ∇f = ⟨fx, fy⟩ (add fz in three variables).
- The directional derivative is Duf = ∇f · u, with u a unit vector.
- f increases fastest along ∇f at rate |∇f| and decreases fastest along −∇f.
- The gradient is perpendicular to level curves and level surfaces; moving along a level curve gives zero change.
- For an angle θ, use u = ⟨cos θ, sin θ⟩; for a vector v, use v/|v|.
Previous lesson: Multivariable Chain Rule
Next lesson: Extrema of Functions of Two Variables
Back to the Calculus 3 Index