Gradient in this visualization
The gradient of a function , written or , is the vector of its partial derivatives, . Where is differentiable and , it points in the direction in which increases fastest, and its length is that fastest rate. This page shows it on six surfaces together with the directional derivative, the rate of change of in a chosen direction.
The glass surface is the graph of ; its contour map lies on the floor. The blue point P sits on the surface above . The red arrow u is a horizontal unit vector at the angle , measured counterclockwise from the positive -axis. Over a horizontal step of one unit along u, the tangent plane rises by the yellow segment: the directional derivative
The directional derivative is also written , with the direction as the unit vector ; here is measured counterclockwise from the positive -axis, so and . The blue ring is the unit circle around P lifted onto the tangent plane. Its highest point lies in the direction of the gradient, above P, because
where is the angle between u and . The slope is largest along the gradient, zero along the contour through P, and most negative against the gradient.
Things to notice
- The gradient is perpendicular to the contour through P. Contours drawn at equal steps of crowd together where is large.
- As u turns once around, the map point traces a circle whose diameter runs from to . Where , the circle shrinks to the point itself.
- The steepest way up need not point at the summit: on a stretched hill the two directions differ.
- The partial derivatives are directional derivatives: gives , and gives .
- Where (a critical point), every direction has slope 0 and there is no steepest direction. A saddle is such a point that is neither a local maximum nor a local minimum.
- The yellow rise belongs to the tangent plane: it is a linear approximation. Over a short horizontal step along u, the surface itself rises by , and the smaller , the better the match.
Where it is used
- Gradient descent, the basic method for training machine-learning models, lowers a function by repeated small steps against the gradient, . Where , a small enough step goes downhill, but the method can settle in a local minimum, or crawl near a saddle, instead of reaching the lowest point.
- Because the gradient is perpendicular to level curves, it gives their normal direction. Where a smooth has a maximum or minimum on a curve (with ), the two gradients are parallel, : the idea behind Lagrange multipliers.
- In physics, a conservative force is minus the gradient of potential energy, : it pushes toward lower energy, in the direction in which the energy drops fastest.
Controls
- Drag P on the surface or its foot on the map, or drag the tip of the red arrow. Key points and key directions (, , , ) jump to exact values; at a key critical point is exactly 0.
- Sweep turns u once around and stops on the steepest direction. Top view looks straight down, where angles on the map are true. Presentation mode opens a full-screen view for projectors (Space sweeps, ← → turn u, H hides the answers).
Related
- E10Contour mapPlanned
- E12Partial derivative
- E13Tangent plane
- E16Second partial derivative testPlanned
- E17Lagrange multiplierPlanned
Further reading: Wikipedia: Gradient; OpenStax, Calculus Volume 3, 4.6 Directional Derivatives and the Gradient.