What the gradient vector is
For a function f(x, y), the gradient is written grad f or ∇f. It is the vector (∂f/∂x, ∂f/∂y). A partial derivative is the rate of change of f when one variable moves and the others are held fixed.
For three variables the gradient has three components, and in general it has one component per input. At each point in the domain, the gradient is a single vector, so it forms a vector field.
Why it points uphill
The directional derivative of f in the direction of a unit vector u is D_u f = ∇f · u. This holds when f is differentiable at the point. The dot product equals |∇f| cos θ, where θ is the angle between ∇f and u.
The value cos θ is largest, equal to 1, when θ = 0. So the steepest increase is along ∇f, and the rate there is |∇f|. The steepest decrease is along -∇f, and the rate is -|∇f|. Along directions perpendicular to ∇f, the rate is zero.
Worked example with f(x, y) = x² + y²
Here ∂f/∂x = 2x and ∂f/∂y = 2y, so ∇f = (2x, 2y). At the point (1, 2), ∇f = (2, 4). Its length is the square root of 2² + 4² = 4 + 16 = 20, which is about 4.47.
Take the unit direction u = (1, 0). Then D_u f = (2, 4) · (1, 0) = 2·1 + 4·0 = 2. This is smaller than 4.47, as expected, because u is not along the gradient.
The level curve through (1, 2) is x² + y² = 5, a circle. The tangent to this circle at (1, 2) has direction (2, -1). Check: (2, 4) · (2, -1) = 4 - 4 = 0. The gradient is perpendicular to the level curve.
Common misconceptions
The gradient is a vector in the input space, not a number and not a point on the graph. It lives in the plane of x and y, not in the third dimension of the surface.
The gradient does not point toward the global maximum. It gives only the local direction of fastest increase. Also, the gradient is perpendicular to level curves only where it is nonzero.
Where the gradient shows up
Optimization uses the gradient because critical points occur where ∇f = 0 for a differentiable function. Gradient descent algorithms repeatedly step along -∇f to lower a function's value.
In physics, a force can be written as the negative gradient of a potential energy function. In geometry, the gradient gives the normal vector to a level curve or level surface, which is used to build tangent lines and tangent planes.
Key terms
- Gradient
- The vector of all first partial derivatives of a function, written ∇f.
- Partial derivative
- The derivative of a multivariable function with respect to one variable, with the others held fixed.
- Directional derivative
- The rate of change of a function at a point in a chosen unit-vector direction, equal to ∇f · u.
- Level curve
- The set of points where a two-variable function takes one constant value.
- Unit vector
- A vector of length 1, used to specify a direction.
- Critical point
- A point where the gradient is zero or does not exist.
