Directional Derivatives and the Direction of Steepest Ascent
Learning Objectives
- Define the directional derivative as a limit along a unit vector, and say why the vector must have length one.
- Prove that for a differentiable , and name what goes wrong when is not differentiable.
- Derive from the directions of steepest ascent, steepest descent and zero change, including the case .
- 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 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 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 , 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 with and define
Equivalently, for the one-variable function , the height profile of along the straight line through in direction . The partials are the special cases and . The unit length matters because then measures distance walked: for a vector of length , the profile runs five times faster and the "derivative" would be inflated by five.
The formula
Theorem. If is differentiable at , then exists for every unit vector and
Proof. Let and , which are differentiable with and . The chain rule from the previous lesson, which needs differentiable, gives .
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 , returns in a single pass at a cost comparable to evaluating once, while forming all of 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 be the angle between and . Since ,
If , this is largest when , so the maximum rate is in the direction . It is smallest, , in the opposite direction. It is zero for the two directions at right angles to . If , every directional derivative is 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 .
The gradient is perpendicular to level curves
Suppose is and (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 the level set through is a smooth curve, a consequence of the implicit function theorem. Parametrize it as with and . Since is constant, differentiating with the chain rule gives
So is perpendicular to the tangent of the level curve, and the tangent line is . 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 . The hypothesis matters: for at the origin, and the level is two crossing lines, with no single tangent.
Worked Examples
Example 1: rates in several directions
Take at , where and .
- Direction : .
- Steepest ascent, : rate , slightly above as it must be.
- Tangent direction : .
The tangent line to the level curve is , that is , with slope , the same slope that the implicit-slope formula of the previous lesson gave. Centered finite differences of along these directions return , and . The vector without normalizing would give , five times too large.
Example 2: a decreasing direction
Let at , so . Along , : the function decreases. The steepest direction is with rate , and the steepest descent direction is .
Example 3: gradient descent does not aim at the minimizer
For the minimum is at the origin. From , the direction to the minimizer is and the steepest descent direction is . The cosine between them is , an angle of about . 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 from :
texteta = 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 the -coordinate is multiplied by at each step, so any makes it grow. A single step of already moves from to , where , even though every step started in a direction of decrease.
Example 4: a level surface in three variables
For , the level is a sphere through . There , so the tangent plane is , which simplifies to . The gradient is parallel to the radius from the origin, as the normal of a sphere should be, and confirms the plane passes through the point.
Example 5: where the formula fails
Let with , the function that functions-of-several-variables-and-level-curves showed to be continuous at the origin. For a unit vector , , so
Every directional derivative exists. But both partials at the origin are (take and ), so the formula would predict for all . For the true value is . The largest rate is at , a direction the "gradient" knows nothing about. The map is not linear in , which is the signature of a function that is not differentiable. A simpler case is the cone : at the vertex the profile along any line is , so the two-sided limit defining does not exist (the one-sided rate is in every direction), and no gradient exists.
Common Misconceptions & Pitfalls
- "Any direction vector will do." The formula needs . For another vector , normalize first, or you get 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.
- " means ." 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 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 turns into , whose gradient at is . In the original variables this is the displacement , not the direction of . 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 is the slope of along the line through a point in the unit direction . For a differentiable it equals , which proves that the gradient gives the direction of fastest increase with rate , that gives the fastest decrease, and that directions perpendicular to keep constant to first order, so 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 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.