In vector calculus, the gradient of a scalar-valued differentiable function f of several variables is the vector field (or vector-valued function) {\displaystyle \nabla f}\nabla f whose value at a point {\displaystyle p}p is the “direction and rate of fastest increase”. If the gradient of a function is non-zero at a point p, the direction of the gradient is the direction in which the function increases most quickly from p, and the magnitude of the gradient is the rate of increase in that direction, the greatest absolute directional derivative.[1] Further, a point where the gradient is the zero vector is known as a stationary point. The gradient thus plays a fundamental role in optimization theory, where it is used to maximize a function by gradient ascent. In coordinate-free terms, the gradient of a function {\displaystyle f({\bf {{r})}}}{\displaystyle f({\bf {{r})}}} may be defined by:
{\displaystyle df=\nabla f\cdot d{\bf {r}}}{\displaystyle df=\nabla f\cdot d{\bf {r}}}
where df is the total infinitesimal change in f for an infinitesimal displacement {\displaystyle d{\bf {r}}}{\displaystyle d{\bf {r}}}, and is seen to be maximal when {\displaystyle d{\bf {r}}}{\displaystyle d{\bf {r}}} is in the direction of the gradient {\displaystyle \nabla f}\nabla f. The nabla symbol {\displaystyle \nabla }\nabla , written as an upside-down triangle and pronounced “del”, denotes the vector differential operator.
When a coordinate system is used in which the basis vectors are not functions of position, the gradient is given by the vector[a] whose components are the partial derivatives of {\displaystyle f}f at {\displaystyle p}p.[2] That is, for {\displaystyle f\colon \mathbb {R} ^{n}\to \mathbb {R} }{\displaystyle f\colon \mathbb {R} ^{n}\to \mathbb {R} }, its gradient {\displaystyle \nabla f\colon \mathbb {R} ^{n}\to \mathbb {R} ^{n}}{\displaystyle \nabla f\colon \mathbb {R} ^{n}\to \mathbb {R} ^{n}} is defined at the point {\displaystyle p=(x_{1},\ldots ,x_{n})}{\displaystyle p=(x_{1},\ldots ,x_{n})} in n-dimensional space as the vector[b]
{\displaystyle \nabla f§={\begin{bmatrix}{\frac {\partial f}{\partial x_{1}}}§\\vdots \{\frac {\partial f}{\partial x_{n}}}§\end{bmatrix}}.}{\displaystyle \nabla f§={\begin{bmatrix}{\frac {\partial f}{\partial x_{1}}}§\\vdots \{\frac {\partial f}{\partial x_{n}}}§\end{bmatrix}}.}
The gradient is dual to the total derivative {\displaystyle df}df: the value of the gradient at a point is a tangent vector – a vector at each point; while the value of the derivative at a point is a cotangent vector – a linear functional on vectors.[c] They are related in that the dot product of the gradient of f at a point p with another tangent vector v equals the directional derivative of f at p of the function along v; that is, {\textstyle \nabla f§\cdot \mathbf {v} ={\frac {\partial f}{\partial \mathbf {v} }}§=df_{p}(\mathbf {v} )}{\textstyle \nabla f§\cdot \mathbf {v} ={\frac {\partial f}{\partial \mathbf {v} }}§=df_{p}(\mathbf {v} )}. The gradient admits multiple generalizations to more general functions on manifolds; see § Generalizations.
The gradient, represented by the blue arrows, denotes the direction of greatest change of a scalar function. The values of the function are represented in greyscale and increase in value from white (low) to dark (high).
Consider a room where the temperature is given by a scalar field, T, so at each point (x, y, z) the temperature is T(x, y, z), independent of time. At each point in the room, the gradient of T at that point will show the direction in which the temperature rises most quickly, moving away from (x, y, z). The magnitude of the gradient will determine how fast the temperature rises in that direction.
Consider a surface whose height above sea level at point (x, y) is H(x, y). The gradient of H at a point is a plane vector pointing in the direction of the steepest slope or grade at that point. The steepness of the slope at that point is given by the magnitude of the gradient vector.
The gradient can also be used to measure how a scalar field changes in other directions, rather than just the direction of greatest change, by taking a dot product. Suppose that the steepest slope on a hill is 40%. A road going directly uphill has slope 40%, but a road going around the hill at an angle will have a shallower slope. For example, if the road is at a 60° angle from the uphill direction (when both directions are projected onto the horizontal plane), then the slope along the road will be the dot product between the gradient vector and a unit vector along the road, namely 40% times the cosine of 60°, or 20%.
More generally, if the hill height function H is differentiable, then the gradient of H dotted with a unit vector gives the slope of the hill in the direction of the vector, the directional derivative of H along the unit vector.
Gradient of the 2D function f(x, y) = xe−(x2 + y2) is plotted as blue arrows over the pseudocolor plot of the function.