Directional Derivatives and the Direction of Steepest Ascent

Published on 2026-11-04·v1.0

Learning Objectives

  • Define the directional derivative DufD_{\mathbf u} f as a limit along a unit vector, and say why the vector must have length one.
  • Prove that Duf=∇f⋅uD_{\mathbf u} f = \nabla f \cdot \mathbf u for a differentiable ff, and name what goes wrong when ff is not differentiable.
  • Derive from Duf=∥∇f∥cos⁡θD_{\mathbf u} f = \lVert\nabla f\rVert \cos\theta the directions of steepest ascent, steepest descent and zero change, including the case ∇f=0\nabla f = 0.
  • Show that the gradient is perpendicular to the level curve through a point, and use it to write the tangent line.
  • State the limits of "follow the negative gradient": it is a local statement, and it depends on how length is measured.

Context & Motivation

The lesson gradients-extending-derivatives-to-several-variables introduces ∇f\nabla f as the vector of partial derivatives and asserts two things about it: that it points in the direction of fastest increase, with its length as the rate, and that ∇f=0\nabla f = 0 marks flat points. It states them without proof, because that lesson deliberately avoids limits. This lesson earns the first claim. It also answers three questions that the informal version leaves open: what exactly is the rate of change in a direction that is not a coordinate axis, why the best direction is the gradient and not something else, and when the whole story stops being true.

None of this is only geometry. Gradient descent, the workhorse of model training, moves along −∇f-\nabla f, and the way it zigzags in narrow valleys, or overshoots with a large step, can be read directly from the facts proved below. The prerequisite is partial-derivatives-and-the-multivariable-chain-rule: the proof of the main formula is one application of its chain rule, and its warning about differentiability is exactly what limits the result.

Core Theory

The directional derivative

A partial derivative measures change along a coordinate axis. To measure it along any direction, take a unit vector u=(u1,u2)\mathbf u = (u_1, u_2) with u12+u22=1u_1^2 + u_2^2 = 1 and define

Duf(a)=lim⁡h→0f(a+hu)−f(a)h.D_{\mathbf u} f(\mathbf a) = \lim_{h \to 0} \frac{f(\mathbf a + h\mathbf u) - f(\mathbf a)}{h}.

Equivalently, Duf(a)=g′(0)D_{\mathbf u} f(\mathbf a) = g'(0) for the one-variable function g(t)=f(a+tu)g(t) = f(\mathbf a + t\mathbf u), the height profile of ff along the straight line through a\mathbf a in direction u\mathbf u. The partials are the special cases u=(1,0)\mathbf u = (1, 0) and u=(0,1)\mathbf u = (0, 1). The unit length matters because tt then measures distance walked: for a vector v\mathbf v of length 55, the profile f(a+tv)f(\mathbf a + t\mathbf v) runs five times faster and the "derivative" would be inflated by five.

The formula

Theorem. If ff is differentiable at a\mathbf a, then Duf(a)D_{\mathbf u} f(\mathbf a) exists for every unit vector u\mathbf u and

Duf(a)=∇f(a)⋅u=fx(a) u1+fy(a) u2.D_{\mathbf u} f(\mathbf a) = \nabla f(\mathbf a) \cdot \mathbf u = f_x(\mathbf a)\,u_1 + f_y(\mathbf a)\,u_2.

Proof. Let x(t)=a1+tu1x(t) = a_1 + t u_1 and y(t)=a2+tu2y(t) = a_2 + t u_2, which are differentiable with x′=u1x' = u_1 and y′=u2y' = u_2. The chain rule from the previous lesson, which needs ff differentiable, gives g′(0)=fxu1+fyu2g'(0) = f_x u_1 + f_y u_2. □\square

The formula also has a computational reading. To get the rate along one chosen direction you do not need the whole gradient: forward-mode automatic differentiation, seeded with u\mathbf u, returns DufD_{\mathbf u} f in a single pass at a cost comparable to evaluating ff once, while forming all of ∇f\nabla f that way would take one pass per coordinate.

Differentiability is a real hypothesis. Example 5 exhibits a continuous function whose directional derivatives all exist and which still violates the formula.

Steepest ascent, with proof

Let θ\theta be the angle between ∇f(a)\nabla f(\mathbf a) and u\mathbf u. Since ∥u∥=1\lVert \mathbf u \rVert = 1,

Duf(a)=∥∇f(a)∥cos⁡θ.D_{\mathbf u} f(\mathbf a) = \lVert \nabla f(\mathbf a) \rVert \cos\theta.

If ∇f(a)≠0\nabla f(\mathbf a) \ne 0, this is largest when cos⁡θ=1\cos\theta = 1, so the maximum rate is ∥∇f∥\lVert\nabla f\rVert in the direction ∇f/∥∇f∥\nabla f / \lVert\nabla f\rVert. It is smallest, −∥∇f∥-\lVert\nabla f\rVert, in the opposite direction. It is zero for the two directions at right angles to ∇f\nabla f. If ∇f(a)=0\nabla f(\mathbf a) = 0, every directional derivative is 00 and there is no preferred direction at first order.

This is the statement that the informal lesson asserts. The proof uses nothing beyond the formula and ∣cos⁡θ∣≤1\lvert\cos\theta\rvert \le 1.

The gradient is perpendicular to level curves

Suppose ff is C1C^1 and ∇f(a)≠0\nabla f(\mathbf a) \ne 0 (the same argument works for three variables, where the level set is a surface and the gradient is normal to its tangent plane). Then near a\mathbf a the level set f=cf = c through a\mathbf a is a smooth curve, a consequence of the implicit function theorem. Parametrize it as r(t)\mathbf r(t) with r(0)=a\mathbf r(0) = \mathbf a and r′(0)≠0\mathbf r'(0) \ne 0. Since f(r(t))=cf(\mathbf r(t)) = c is constant, differentiating with the chain rule gives

∇f(a)⋅r′(0)=0.\nabla f(\mathbf a) \cdot \mathbf r'(0) = 0.

So ∇f(a)\nabla f(\mathbf a) is perpendicular to the tangent of the level curve, and the tangent line is ∇f(a)⋅(x−a)=0\nabla f(\mathbf a) \cdot (\mathbf x - \mathbf a) = 0. This matches the contour picture: moving along a contour keeps the height, and the steepest way off it is straight across. It also explains why crowded contours mean a large ∥∇f∥\lVert\nabla f\rVert. The hypothesis ∇f≠0\nabla f \ne 0 matters: for f=x2−y2f = x^2 - y^2 at the origin, ∇f=0\nabla f = 0 and the level c=0c = 0 is two crossing lines, with no single tangent.

Worked Examples

Example 1: rates in several directions

Take f(x,y)=x2+4y2f(x, y) = x^2 + 4y^2 at a=(2,1)\mathbf a = (2, 1), where ∇f=(2x,8y)=(4,8)\nabla f = (2x, 8y) = (4, 8) and ∥∇f∥=45≈8.944\lVert\nabla f\rVert = 4\sqrt5 \approx 8.944.

  • Direction u=(3/5,4/5)\mathbf u = (3/5, 4/5): Duf=125+325=8.8D_{\mathbf u} f = \tfrac{12}{5} + \tfrac{32}{5} = 8.8.
  • Steepest ascent, u=(1,2)/5\mathbf u = (1, 2)/\sqrt5: rate 45≈8.9444\sqrt5 \approx 8.944, slightly above 8.88.8 as it must be.
  • Tangent direction u=(2,−1)/5\mathbf u = (2, -1)/\sqrt5: Duf=(8−8)/5=0D_{\mathbf u} f = (8 - 8)/\sqrt5 = 0.

The tangent line to the level curve x2+4y2=8x^2 + 4y^2 = 8 is 4(x−2)+8(y−1)=04(x - 2) + 8(y - 1) = 0, that is x+2y=4x + 2y = 4, with slope −1/2-1/2, the same slope that the implicit-slope formula of the previous lesson gave. Centered finite differences of ff along these directions return 8.88.8, 8.9448.944 and 00. The vector v=(3,4)\mathbf v = (3, 4) without normalizing would give 4444, five times too large.

Example 2: a decreasing direction

Let f(x,y)=xeyf(x, y) = x e^{y} at (1,0)(1, 0), so ∇f=(ey,xey)=(1,1)\nabla f = (e^y, x e^y) = (1, 1). Along u=(3,−4)/5\mathbf u = (3, -4)/5, Duf=(3−4)/5=−0.2D_{\mathbf u} f = (3 - 4)/5 = -0.2: the function decreases. The steepest direction is (1,1)/2(1, 1)/\sqrt2 with rate 2\sqrt2, and the steepest descent direction is (−1,−1)/2(-1, -1)/\sqrt2.

Example 3: gradient descent does not aim at the minimizer

For f=x2+4y2f = x^2 + 4y^2 the minimum is at the origin. From (2,1)(2, 1), the direction to the minimizer is (−2,−1)(-2, -1) and the steepest descent direction is −∇f=(−4,−8)-\nabla f = (-4, -8). The cosine between them is 8+880 5=0.8\dfrac{8 + 8}{\sqrt{80}\,\sqrt5} = 0.8, an angle of about 37°37°. The reason is the geometry above: the gradient is perpendicular to the elliptical contour, and the normal to an ellipse passes through its center only on the axes.

The step size matters too, because the gradient describes an infinitesimal move. Update p←p−η∇f(p)\mathbf p \leftarrow \mathbf p - \eta \nabla f(\mathbf p) from (2,1)(2, 1):

text
eta = 0.05 f: 8, 4.68, 3.14, 2.31, 1.79, 1.42 (decreasing) eta = 0.20 f: 8, 2.88, 1.04, 0.37, 0.13, 0.05 (decreasing faster) eta = 0.30 f: 8, 8.48, 15.47, 30.13, 59.03, 115.70 (increasing)

For this ff the yy-coordinate is multiplied by 1−8η1 - 8\eta at each step, so any η>1/4\eta > 1/4 makes it grow. A single step of 0.30.3 already moves from (2,1)(2, 1) to (0.8,−1.4)(0.8, -1.4), where f=8.48>8f = 8.48 > 8, even though every step started in a direction of decrease.

Example 4: a level surface in three variables

For f(x,y,z)=x2+y2+z2f(x, y, z) = x^2 + y^2 + z^2, the level f=14f = 14 is a sphere through (1,2,3)(1, 2, 3). There ∇f=(2,4,6)\nabla f = (2, 4, 6), so the tangent plane is 2(x−1)+4(y−2)+6(z−3)=02(x - 1) + 4(y - 2) + 6(z - 3) = 0, which simplifies to x+2y+3z=14x + 2y + 3z = 14. The gradient (2,4,6)(2, 4, 6) is parallel to the radius from the origin, as the normal of a sphere should be, and 1+4+9=141 + 4 + 9 = 14 confirms the plane passes through the point.

Example 5: where the formula fails

Let q(x,y)=x2yx2+y2q(x, y) = \dfrac{x^2 y}{x^2 + y^2} with q(0,0)=0q(0, 0) = 0, the function that functions-of-several-variables-and-level-curves showed to be continuous at the origin. For a unit vector u\mathbf u, q(hu)=h u12u2q(h\mathbf u) = h\,u_1^2 u_2, so

Duq(0,0)=u12u2.D_{\mathbf u} q(0, 0) = u_1^2 u_2.

Every directional derivative exists. But both partials at the origin are 00 (take u=(1,0)\mathbf u = (1, 0) and (0,1)(0, 1)), so the formula would predict Duq=0D_{\mathbf u} q = 0 for all u\mathbf u. For u=(1,1)/2\mathbf u = (1, 1)/\sqrt2 the true value is 1/(22)≈0.3541/(2\sqrt2) \approx 0.354. The largest rate is 23/9≈0.3852\sqrt3/9 \approx 0.385 at u=(2/3,1/3)\mathbf u = (\sqrt{2/3}, \sqrt{1/3}), a direction the "gradient" (0,0)(0, 0) knows nothing about. The map u↦u12u2\mathbf u \mapsto u_1^2 u_2 is not linear in u\mathbf u, which is the signature of a function that is not differentiable. A simpler case is the cone f=x2+y2f = \sqrt{x^2 + y^2}: at the vertex the profile along any line is g(t)=∣t∣g(t) = \lvert t\rvert, so the two-sided limit defining DufD_{\mathbf u} f does not exist (the one-sided rate is 11 in every direction), and no gradient exists.

Common Misconceptions & Pitfalls

  • "Any direction vector will do." The formula needs ∥u∥=1\lVert\mathbf u\rVert = 1. For another vector v\mathbf v, normalize first, or you get ∥v∥\lVert\mathbf v\rVert times the true rate.
  • "If all directional derivatives exist, the gradient formula holds." Example 5 is a continuous function where it does not. Existence of the limits in every direction is weaker than differentiability.
  • "Duf=0D_{\mathbf u} f = 0 means ∇f=0\nabla f = 0." It also happens for every direction perpendicular to the gradient, which are exactly the tangents to the level curve.
  • "The gradient points at the maximum or minimum." It gives the best local direction. Example 3 shows it deviating by about 37°37° from the direction of the minimizer.
  • "Steepest does not depend on the coordinates." It is steepest per unit of Euclidean length in the coordinates you chose. Substituting v=2yv = 2y turns x2+4y2x^2 + 4y^2 into x2+v2x^2 + v^2, whose gradient at (2,2)(2, 2) is (4,4)(4, 4). In the original variables this is the displacement (dx,dy)=(4,2)(dx, dy) = (4, 2), not the direction (4,8)(4, 8) of ∇f\nabla f. Rescaling variables changes the direction, which is why feature scaling changes how gradient methods behave.
  • "The gradient lives on the surface." It is a vector in the plane of the inputs, not a tangent vector of the graph.

Summary

The directional derivative DufD_{\mathbf u} f is the slope of ff along the line through a point in the unit direction u\mathbf u. For a differentiable ff it equals ∇f⋅u=∥∇f∥cos⁡θ\nabla f \cdot \mathbf u = \lVert\nabla f\rVert\cos\theta, which proves that the gradient gives the direction of fastest increase with rate ∥∇f∥\lVert\nabla f\rVert, that −∇f-\nabla f gives the fastest decrease, and that directions perpendicular to ∇f\nabla f keep ff constant to first order, so ∇f\nabla f is normal to the level curve. The proof is the chain rule, and the hypotheses are real: without differentiability, directional derivatives can exist and violate the formula, and with ∇f=0\nabla f = 0 there is no direction to choose. As a method, steepest descent is local and coordinate dependent, and it does not aim at the minimizer. This is the tool the next lesson, critical-points-and-the-second-derivative-test, uses to ask what happens where the gradient vanishes.

Documentation Links