← Back to calculus 3

Directional Derivatives and the Gradient

Directional Derivatives and the Gradient

Partial derivatives measure rates of change along the coordinate axes. But a hiker on a mountain may walk in any direction — not just north–south or east–west. The directional derivative answers: how fast does ff change if we move in an arbitrary direction u\mathbf{u}?


1. The question

Let f(x,y)f(x,y) be a function and let u=a,b\mathbf{u} = \langle a, b \rangle be a unit vector (a2+b2=1a^2 + b^2 = 1). Starting at a point (x,y)(x,y), we move a small distance hh in direction u\mathbf{u} to reach (x+ha,y+hb)(x+ha,\, y+hb).

The average rate of change of ff over that step is

f(x+ha,y+hb)f(x,y)h.\frac{f(x+ha,\, y+hb) - f(x,y)}{h}.

What happens as h0h \to 0?


2. Definition via the limit

The directional derivative of ff at (x,y)(x,y) in the direction of the unit vector u=a,b\mathbf{u} = \langle a,b \rangle is

Duf(x,y)=limh0f(x+ha,y+hb)f(x,y)h,\boxed{D_{\mathbf{u}} f(x,y) = \lim_{h \to 0} \frac{f(x+ha,\, y+hb) - f(x,y)}{h},}

provided the limit exists.

Special cases. When u=i=1,0\mathbf{u} = \mathbf{i} = \langle 1,0 \rangle this is exactly fxf_x; when u=j=0,1\mathbf{u} = \mathbf{j} = \langle 0,1 \rangle it is fyf_y. The partial derivatives are directional derivatives along the coordinate axes.

Note. The vector u\mathbf{u} must be a unit vector. If you are given a direction vector v\mathbf{v} that is not unit-length, normalize it first: u=v/v\mathbf{u} = \mathbf{v}/|\mathbf{v}|.


3. Geometric interpretation

Geometrically, DufD_{\mathbf{u}} f is the slope of the surface z=f(x,y)z = f(x,y) as seen by someone walking in direction u\mathbf{u}.

Use the interactive graph below to explore. The left panel shows a unit circle — click or drag to choose a direction u\mathbf{u}. The right panel shows the saddle surface z=x2y2z = x^2 - y^2 with the tangent plane at the base point (1,0,1)(1,0,1) and the red slice curve (the cross-section of the surface cut by a vertical plane through the base point in direction u\mathbf{u}). The green dashed line is tangent to that slice; its slope equals DufD_{\mathbf{u}} f.

Directional derivative on z = x² − y²

Choose direction u

xy
u = (0.87, 0.50)
D_u f = 1.732
∇f = (2.0, 0.0) — gradient (dashed)

Click or drag on the circle to change direction. Red = slice curve, green dashed = tangent line, orange = tangent plane. Green dot on circle = gradient direction.

Notice how the slope of the tangent line changes as you rotate u\mathbf{u}: positive when climbing, negative when descending, zero when moving along a level direction.


4. Computing the directional derivative

Theorem. If ff is differentiable at (x,y)(x,y) and u=a,b\mathbf{u} = \langle a,b \rangle is a unit vector, then

Duf(x,y)=afx(x,y)+bfy(x,y).\boxed{D_{\mathbf{u}} f(x,y) = a\, f_x(x,y) + b\, f_y(x,y).}

Define the single-variable function

g(t)=f(x+ta,  y+tb).g(t) = f(x + ta,\; y + tb).

Then Duf(x,y)=g(0)D_{\mathbf{u}} f(x,y) = g'(0) by definition. By the chain rule,

g(t)=fx(x+ta,y+tb)a  +  fy(x+ta,y+tb)b.g'(t) = f_x(x+ta,\, y+tb)\cdot a \;+\; f_y(x+ta,\, y+tb)\cdot b.

Setting t=0t = 0 gives

Duf(x,y)=afx(x,y)+bfy(x,y).D_{\mathbf{u}} f(x,y) = a\, f_x(x,y) + b\, f_y(x,y). \qquad \square

Example. Let f(x,y)=x2+3xyf(x,y) = x^2 + 3xy and u=12,12\mathbf{u} = \langle \frac{1}{\sqrt{2}}, \frac{1}{\sqrt{2}} \rangle. At the point (2,1)(2,1):

fx=2x+3y=7,fy=3x=6.f_x = 2x + 3y = 7, \qquad f_y = 3x = 6.

Therefore

Duf(2,1)=127+126=1329.19.D_{\mathbf{u}} f(2,1) = \tfrac{1}{\sqrt{2}} \cdot 7 + \tfrac{1}{\sqrt{2}} \cdot 6 = \frac{13}{\sqrt{2}} \approx 9.19.


5. The gradient vector

The formula Duf=afx+bfyD_{\mathbf{u}} f = af_x + bf_y is a dot product. Define the gradient vector

f(x,y)=fx(x,y),  fy(x,y).\nabla f(x,y) = \langle f_x(x,y),\; f_y(x,y) \rangle.

Then the directional derivative formula becomes simply

Duf=fu.\boxed{D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u}.}

For a function of three variables, f(x,y,z)=fx,fy,fz\nabla f(x,y,z) = \langle f_x, f_y, f_z \rangle, and Duf=fuD_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} with u\mathbf{u} a unit vector in R3\mathbb{R}^3.


6. The gradient direction maximizes the rate of change

By the Cauchy–Schwarz inequality,

Duf=fufu=f,D_{\mathbf{u}} f = \nabla f \cdot \mathbf{u} \leq |\nabla f|\,|\mathbf{u}| = |\nabla f|,

with equality exactly when u\mathbf{u} points in the same direction as f\nabla f.

Direction u\mathbf{u}Value of DufD_{\mathbf{u}} f
ff\dfrac{\nabla f}{\lvert\nabla f\rvert}f\lvert\nabla f\rvert — maximum rate of increase
ff-\dfrac{\nabla f}{\lvert\nabla f\rvert}f-\lvert\nabla f\rvert — maximum rate of decrease
Any uf\mathbf{u} \perp \nabla f00 — no change

The gradient points in the direction of steepest ascent, and f|\nabla f| is the steepness.


7. Gradient direction — interactive illustration

The graph below uses z=x2+y2z = x^2 + y^2 at the base point (1,1,2)(1,1,2), where f=2,2\nabla f = \langle 2,2 \rangle. Drag the direction selector and watch Duf=2cosθ+2sinθD_{\mathbf{u}} f = 2\cos\theta + 2\sin\theta update live. Click "Jump to gradient direction" to confirm that θ=45°\theta = 45° achieves the maximum 222.832\sqrt{2} \approx 2.83.

Gradient direction maximizes D_u f on z = x² + y²

Choose direction u

xy
u = (0.87, 0.50)
D_u f = 2.732
∇f = (2.0, 2.0) — gradient (dashed)

Click or drag on the circle to change direction. Red = slice curve, green dashed = tangent line, orange = tangent plane. Green dot on circle = gradient direction.


8. Level sets and the gradient

A level surface of F(x,y,z)F(x,y,z) is the set of all points satisfying F(x,y,z)=kF(x,y,z) = k for some constant kk. For a function f(x,y)f(x,y) the level surfaces are the familiar level curves f(x,y)=cf(x,y) = c.

The key geometric fact is:

F is perpendicular to the level surface F=k.\boxed{\nabla F \text{ is perpendicular to the level surface } F = k.}

The graph below shows the paraboloid z=x2+y2z = x^2 + y^2 together with a family of level curves. The gradient at any point on a level curve points outward — perpendicular to the curve.

Level curves of z = x² + y²

c = 3.00

The blue surface is z = x² + y². The colored circles are a family of five level curves, and the matching circles below are their projections onto the xy-plane.

Let r(t)=(x(t),y(t),z(t))\mathbf{r}(t) = (x(t), y(t), z(t)) be any smooth curve that lies on the level surface F=kF = k. Then

F(r(t))=kfor all t.F(\mathbf{r}(t)) = k \quad \text{for all } t.

Differentiating both sides with respect to tt using the chain rule:

F(r(t))r(t)=dkdt=0.\nabla F(\mathbf{r}(t)) \cdot \mathbf{r}'(t) = \frac{dk}{dt} = 0.

So F\nabla F is perpendicular to r(t)\mathbf{r}'(t) — the tangent vector of every curve on the surface. The tangent vectors of all such curves span the tangent plane, so F\nabla F is a normal vector to the surface. \square

Consequence. The tangent plane to F(x,y,z)=kF(x,y,z) = k at (x0,y0,z0)(x_0,y_0,z_0) is

Fx(x0,y0,z0)(xx0)+Fy(x0,y0,z0)(yy0)+Fz(x0,y0,z0)(zz0)=0.F_x(x_0,y_0,z_0)(x-x_0) + F_y(x_0,y_0,z_0)(y-y_0) + F_z(x_0,y_0,z_0)(z-z_0) = 0.


9. Exercises

Let f(x,y)=x2+xyf(x,y) = x^2 + xy and v=3,4\mathbf{v} = \langle 3, 4 \rangle. Find Duf(1,2)D_{\mathbf{u}} f(1,2) where u=v/v\mathbf{u} = \mathbf{v}/|\mathbf{v}|.

Solution.

First normalize: v=5|\mathbf{v}| = 5, so u=35,45\mathbf{u} = \langle \tfrac{3}{5}, \tfrac{4}{5} \rangle.

Partial derivatives at (1,2)(1,2):

fx=2x+y=4,fy=x=1.f_x = 2x + y = 4, \qquad f_y = x = 1.

Therefore

Duf(1,2)=354+451=125+45=165.D_{\mathbf{u}} f(1,2) = \tfrac{3}{5}\cdot 4 + \tfrac{4}{5}\cdot 1 = \tfrac{12}{5} + \tfrac{4}{5} = \frac{16}{5}.

Let f(x,y)=xeyf(x,y) = xe^y. Compute f(x,y)\nabla f(x,y) and evaluate at (2,0)(2,0). Find the direction of steepest ascent and the maximum rate of increase at that point.

Solution.

fx=ey,fy=xey,f(x,y)=ey,  xey.f_x = e^y, \qquad f_y = xe^y, \qquad \nabla f(x,y) = \langle e^y,\; xe^y \rangle.

At (2,0)(2,0): f(2,0)=1,2\nabla f(2,0) = \langle 1, 2 \rangle.

Direction of steepest ascent: u=1,2/5\mathbf{u} = \langle 1,2 \rangle/\sqrt{5}.

Maximum rate: f(2,0)=5|\nabla f(2,0)| = \sqrt{5}.

Find the direction of steepest ascent of f(x,y)=x2y2f(x,y) = x^2 - y^2 at the point (1,1)(1,1).

Solution.

f(x,y)=2x,  2y,f(1,1)=2,2.\nabla f(x,y) = \langle 2x,\; -2y \rangle, \qquad \nabla f(1,1) = \langle 2, -2 \rangle.

Direction of steepest ascent:

u=2,222=12,  12.\mathbf{u} = \frac{\langle 2,-2 \rangle}{2\sqrt{2}} = \left\langle \frac{1}{\sqrt{2}},\; -\frac{1}{\sqrt{2}} \right\rangle.

Maximum rate of increase: f(1,1)=22|\nabla f(1,1)| = 2\sqrt{2}.

Find the tangent plane to the ellipsoid x2+2y2+3z2=6x^2 + 2y^2 + 3z^2 = 6 at the point (1,1,1)(1, 1, 1).

Solution.

Let F(x,y,z)=x2+2y2+3z2F(x,y,z) = x^2 + 2y^2 + 3z^2. Then

F=2x,  4y,  6z,F(1,1,1)=2,4,6.\nabla F = \langle 2x,\; 4y,\; 6z \rangle, \qquad \nabla F(1,1,1) = \langle 2, 4, 6 \rangle.

The tangent plane is

2(x1)+4(y1)+6(z1)=0    x+2y+3z=6.2(x-1) + 4(y-1) + 6(z-1) = 0 \implies x + 2y + 3z = 6.