Gradient



In vector calculus, the gradient of a scalar-valued differentiable function $$f$$ of several variables is the vector field (or vector-valued function) $$\nabla f$$ whose value at a point $$p$$ gives the direction and the rate of fastest increase. The gradient transforms like a vector under change of basis of the space of variables of $$f$$. 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. 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 minimize a function by gradient descent. In coordinate-free terms, the gradient of a function $$f(\mathbf{r})$$ may be defined by:

$$df=\nabla f \cdot d\mathbf{r}$$

where $$df$$ is the total infinitesimal change in $$f$$ for an infinitesimal displacement $$d\mathbf{r}$$, and is seen to be maximal when $$d\mathbf{r}$$ is in the direction of the gradient $$\nabla f$$. The nabla symbol $$\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 whose components are the partial derivatives of $$f$$ at $$p$$. That is, for $$f \colon \R^n \to \R$$, its gradient $$\nabla f \colon \R^n \to \R^n$$ is defined at the point $$p = (x_1,\ldots,x_n)$$ in n-dimensional space as the vector

$$\nabla f(p) = \begin{bmatrix} \frac{\partial f}{\partial x_1}(p) \\ \vdots \\ \frac{\partial f}{\partial x_n}(p) \end{bmatrix}.$$

Note that the above definition for gradient is only defined for the function $$f$$, if it is differentiable at $$p$$. There can be functions for which partial derivatives exist in every direction but fail to be differentiable. Furthermore, this definition as the vector of partial derivatives is only valid when the basis of the coordinate system is orthonormal. For any other basis, the Metric tensor at that point needs to be taken into account.

For example, the function $$f(x,y)=\frac {x^2 y}{x^2+y^2}$$ unless at origin where $$f(0,0)=0$$, is not differentiable at the origin as it does not have a well defined tangent plane despite having well defined partial derivatives in every direction at the origin. In this particular example, under rotation of x-y coordinate system, the above formula for gradient fails to transform like a vector (gradient becomes dependent on choice of basis for coordinate system) and also fails to point towards the 'steepest ascent' in some orientations. For differentiable functions where the formula for gradient holds, it can be shown to always transform as a vector under transformation of the basis so as to always point towards the fastest increase.

The gradient is dual to the total derivative $$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. They are related in that the dot product of the gradient of $$f$$ at a point $$p$$ with another tangent vector $$\mathbf{v}$$ equals the directional derivative of $$f$$ at $$p$$ of the function along $$\mathbf{v}$$; that is, $\nabla f(p) \cdot \mathbf v = \frac{\partial f}{\partial\mathbf{v}}(p) = df_{p}(\mathbf{v}) $. The gradient admits multiple generalizations to more general functions on manifolds; see.

Motivation


Consider a room where the temperature is given by a scalar field, $f(x, y) = xe^{−(x^{2} + y^{2})}$, so at each point $T$ the temperature is $(x, y, z)$, independent of time. At each point in the room, the gradient of $T(x, y, z)$ at that point will show the direction in which the temperature rises most quickly, moving away from $T$. 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, z)$ is $(x, y)$. The gradient of $H(x, y)$ 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, as the dot product measures how much the unit vector along the road aligns with the steepest slope, which is 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.

Notation
The gradient of a function $$f$$ at point $$a$$ is usually written as $$\nabla f (a)$$. It may also be denoted by any of the following:


 * $$\vec{\nabla} f (a)$$ : to emphasize the vector nature of the result.
 * $$\operatorname{grad} f$$
 * $$\partial_i f$$ and $$f_{i}$$ : Written with Einstein notation, where repeated indices ($H$) are summed over.

Definition


The gradient (or gradient vector field) of a scalar function $i$ is denoted $f(x,y) = −(cos^{2}x + cos^{2}y)^{2}$ or $f(x_{1}, x_{2}, x_{3}, …, x_{n})$ where $∇f$ (nabla) denotes the vector differential operator, del. The notation $∇f$ is also commonly used to represent the gradient. The gradient of $∇$ is defined as the unique vector field whose dot product with any vector $grad f$ at each point $f$ is the directional derivative of $v$ along $x$. That is,

$$\big(\nabla f(x)\big)\cdot \mathbf{v} = D_{\mathbf v}f(x)$$

where the right-hand side is the directional derivative and there are many ways to represent it. Formally, the derivative is dual to the gradient; see relationship with derivative.

When a function also depends on a parameter such as time, the gradient often refers simply to the vector of its spatial derivatives only (see Spatial gradient).

The magnitude and direction of the gradient vector are independent of the particular coordinate representation.

Cartesian coordinates
In the three-dimensional Cartesian coordinate system with a Euclidean metric, the gradient, if it exists, is given by

$$\nabla f = \frac{\partial f}{\partial x} \mathbf{i} + \frac{\partial f}{\partial y} \mathbf{j} + \frac{\partial f}{\partial z} \mathbf{k},$$

where $f$, $v$, $i$ are the standard unit vectors in the directions of the $j$, $k$ and $x$ coordinates, respectively. For example, the gradient of the function $$f(x,y,z)= 2x+3y^2-\sin(z)$$ is $$\nabla f(x, y, z) = 2\mathbf{i}+ 6y\mathbf{j} -\cos(z)\mathbf{k}.$$ or $$\nabla f(x, y, z) = \begin{bmatrix} 2 \\ 6y \\ -\cos z \end{bmatrix}. $$

In some applications it is customary to represent the gradient as a row vector or column vector of its components in a rectangular coordinate system; this article follows the convention of the gradient being a column vector, while the derivative is a row vector.

Cylindrical and spherical coordinates
In cylindrical coordinates with a Euclidean metric, the gradient is given by:

$$\nabla f(\rho, \varphi, z) = \frac{\partial f}{\partial \rho}\mathbf{e}_\rho + \frac{1}{\rho}\frac{\partial f}{\partial \varphi}\mathbf{e}_\varphi + \frac{\partial f}{\partial z}\mathbf{e}_z,$$

where $y$ is the axial distance, $z$ is the azimuthal or azimuth angle, $ρ$ is the axial coordinate, and $φ$, $z$ and $e_{ρ}$ are unit vectors pointing along the coordinate directions.

In spherical coordinates, the gradient is given by:

$$\nabla f(r, \theta, \varphi) = \frac{\partial f}{\partial r}\mathbf{e}_r + \frac{1}{r}\frac{\partial f}{\partial \theta}\mathbf{e}_\theta + \frac{1}{r \sin\theta}\frac{\partial f}{\partial \varphi}\mathbf{e}_\varphi,$$

where $e_{φ}$ is the radial distance, $e_{z}$ is the azimuthal angle and $r$ is the polar angle, and $φ$, $θ$ and $e_{r}$ are again local unit vectors pointing in the coordinate directions (that is, the normalized covariant basis).

For the gradient in other orthogonal coordinate systems, see Orthogonal coordinates (Differential operators in three dimensions).

General coordinates
We consider general coordinates, which we write as $e_{θ}$, where $n$ is the number of dimensions of the domain. Here, the upper index refers to the position in the list of the coordinate or component, so $e_{φ}$ refers to the second component—not the quantity $x^{1}, …, x^{i}, …, x^{n}$ squared. The index variable $x^{2}$ refers to an arbitrary element $x$. Using Einstein notation, the gradient can then be written as:

$$\nabla f = \frac{\partial f}{\partial x^{i}}g^{ij} \mathbf{e}_j$$ (Note that its dual is $\mathrm{d}f = \frac{\partial f}{\partial x^{i}}\mathbf{e}^i$ ),

where $$\mathbf{e}_i = \partial \mathbf{x}/\partial x^i$$ and $$\mathbf{e}^i = \mathrm{d}x^i$$ refer to the unnormalized local covariant and contravariant bases respectively, $$g^{ij}$$ is the inverse metric tensor, and the Einstein summation convention implies summation over i and j.

If the coordinates are orthogonal we can easily express the gradient (and the differential) in terms of the normalized bases, which we refer to as $$\hat{\mathbf{e}}_i$$ and  $$\hat{\mathbf{e}}^i$$, using the scale factors (also known as Lamé coefficients)  $$h_i= \lVert \mathbf{e}_i \rVert = \sqrt{g_{i i}} = 1\, / \lVert \mathbf{e}^i \rVert$$ :

$$\nabla f = \frac{\partial f}{\partial x^{i}}g^{ij} \hat{\mathbf{e}}_{j}\sqrt{g_{jj}} = \sum_{i=1}^n \, \frac{\partial f}{\partial x^{i}} \frac{1}{h_i} \mathbf{\hat{e}}_i$$ (and $\mathrm{d}f = \sum_{i=1}^n \, \frac{\partial f}{\partial x^{i}} \frac{1}{h_i} \mathbf{\hat{e}}^i$ ),

where we cannot use Einstein notation, since it is impossible to avoid the repetition of more than two indices. Despite the use of upper and lower indices, $$\mathbf{\hat{e}}_i$$, $$\mathbf{\hat{e}}^i$$, and $$h_i$$ are neither contravariant nor covariant.

The latter expression evaluates to the expressions given above for cylindrical and spherical coordinates.

Relationship with total derivative
The gradient is closely related to the total derivative (total differential) $$df$$: they are transpose (dual) to each other. Using the convention that vectors in $$\R^n$$ are represented by column vectors, and that covectors (linear maps $$\R^n \to \R$$) are represented by row vectors, the gradient $$\nabla f$$ and the derivative $$df$$ are expressed as a column and row vector, respectively, with the same components, but transpose of each other:

$$\nabla f(p) = \begin{bmatrix}\frac{\partial f}{\partial x_1}(p) \\ \vdots \\ \frac{\partial f}{\partial x_n}(p) \end{bmatrix} ;$$ $$df_p = \begin{bmatrix}\frac{\partial f}{\partial x_1}(p) & \cdots & \frac{\partial f}{\partial x_n}(p) \end{bmatrix} .$$

While these both have the same components, they differ in what kind of mathematical object they represent: at each point, the derivative is a cotangent vector, a linear form (or covector) which expresses how much the (scalar) output changes for a given infinitesimal change in (vector) input, while at each point, the gradient is a tangent vector, which represents an infinitesimal change in (vector) input. In symbols, the gradient is an element of the tangent space at a point, $$\nabla f(p) \in T_p \R^n$$, while the derivative is a map from the tangent space to the real numbers, $$df_p \colon T_p \R^n \to \R$$. The tangent spaces at each point of $$\R^n$$ can be "naturally" identified with the vector space $$\R^n$$ itself, and similarly the cotangent space at each point can be naturally identified with the dual vector space $$(\R^n)^*$$ of covectors; thus the value of the gradient at a point can be thought of a vector in the original $$\R^n$$, not just as a tangent vector.

Computationally, given a tangent vector, the vector can be multiplied by the derivative (as matrices), which is equal to taking the dot product with the gradient: $$ (df_p)(v) = \begin{bmatrix}\frac{\partial f}{\partial x_1}(p) & \cdots & \frac{\partial f}{\partial x_n}(p) \end{bmatrix} \begin{bmatrix}v_1 \\ \vdots \\ v_n\end{bmatrix} = \sum_{i=1}^n \frac{\partial f}{\partial x_i}(p) v_i = \begin{bmatrix}\frac{\partial f}{\partial x_1}(p) \\ \vdots \\ \frac{\partial f}{\partial x_n}(p) \end{bmatrix} \cdot \begin{bmatrix}v_1 \\ \vdots \\ v_n\end{bmatrix} = \nabla f(p) \cdot v$$

Differential or (exterior) derivative
The best linear approximation to a differentiable function $$f : \R^n \to \R$$ at a point $$x$$ in $$\R^n$$ is a linear map from $$\R^n$$ to $$\R$$ which is often denoted by $$df_x$$ or $$Df(x)$$ and called the differential or total derivative of $$f$$ at $$x$$. The function $$df$$, which maps $$x$$ to $$df_x$$, is called the total differential or exterior derivative of $$f$$ and is an example of a differential 1-form.

Much as the derivative of a function of a single variable represents the slope of the tangent to the graph of the function, the directional derivative of a function in several variables represents the slope of the tangent hyperplane in the direction of the vector.

The gradient is related to the differential by the formula $$(\nabla f)_x\cdot v = df_x(v)$$ for any $$v\in\R^n$$, where $$\cdot$$ is the dot product: taking the dot product of a vector with the gradient is the same as taking the directional derivative along the vector.

If $$\R^n$$ is viewed as the space of (dimension $$n$$) column vectors (of real numbers), then one can regard $$df$$ as the row vector with components $$\left( \frac{\partial f}{\partial x_1}, \dots, \frac{\partial f}{\partial x_n}\right),$$ so that $$df_x(v)$$ is given by matrix multiplication. Assuming the standard Euclidean metric on $$\R^n$$, the gradient is then the corresponding column vector, that is, $$(\nabla f)_i = df^\mathsf{T}_i.$$

Linear approximation to a function
The best linear approximation to a function can be expressed in terms of the gradient, rather than the derivative. The gradient of a function $$f$$ from the Euclidean space $$\R^n$$ to $$\R$$ at any particular point $$x_0$$ in $$\R^n$$ characterizes the best linear approximation to $$f$$ at $$x_0$$. The approximation is as follows:

$$f(x) \approx f(x_0) + (\nabla f)_{x_0}\cdot(x-x_0)$$

for $$x$$ close to $$x_0$$, where $$(\nabla f)_{x_0}$$ is the gradient of $$f$$ computed at $$x_0$$, and the dot denotes the dot product on $$\R^n$$. This equation is equivalent to the first two terms in the multivariable Taylor series expansion of $$f$$ at $$x_0$$.

Relationship with Fréchet derivative
Let $i$ be an open set in $x^{i}$. If the function $U$ is differentiable, then the differential of $R^{n}$ is the Fréchet derivative of $f : U → R$. Thus $f$ is a function from $f$ to the space $∇f$ such that $$\lim_{h\to 0} \frac{|f(x+h)-f(x) -\nabla f(x)\cdot h|}{\|h\|} = 0,$$ where · is the dot product.

As a consequence, the usual properties of the derivative hold for the gradient, though the gradient is not a derivative itself, but rather dual to the derivative:


 * Linearity
 * The gradient is linear in the sense that if $U$ and $R^{n}$ are two real-valued functions differentiable at the point $f$, and $α$ and $β$ are two constants, then $g$ is differentiable at $a ∈ R^{n}$, and moreover $$\nabla\left(\alpha f+\beta g\right)(a) = \alpha \nabla f(a) + \beta\nabla g (a).$$


 * Product rule
 * If $αf + βg$ and $a$ are real-valued functions differentiable at a point $f$, then the product rule asserts that the product $g$ is differentiable at $a ∈ R^{n}$, and $$\nabla (fg)(a) = f(a)\nabla g(a) + g(a)\nabla f(a).$$


 * Chain rule
 * Suppose that $fg$ is a real-valued function defined on a subset $a$ of $f : A → R$, and that $A$ is differentiable at a point $R^{n}$. There are two forms of the chain rule applying to the gradient. First, suppose that the function $f$ is a parametric curve; that is, a function $a$ maps a subset $g$ into $g : I → R^{n}$. If $I ⊂ R$ is differentiable at a point $R^{n}$ such that $g$, then $$(f\circ g)'(c) = \nabla f(a)\cdot g'(c),$$ where ∘ is the composition operator: $c ∈ I$.

More generally, if instead $g(c) = a$, then the following holds: $$\nabla (f\circ g)(c) = \big(Dg(c)\big)^\mathsf{T} \big(\nabla f(a)\big),$$ where $(f ∘ g)(x) = f(g(x))$T denotes the transpose Jacobian matrix.

For the second form of the chain rule, suppose that $I ⊂ R^{k}$ is a real valued function on a subset $(Dg)$ of $h : I → R$, and that $I$ is differentiable at the point $R$. Then $$\nabla (h\circ f)(a) = h'\big(f(a)\big)\nabla f(a).$$

Level sets
A level surface, or isosurface, is the set of all points where some function has a given value.

If $h$ is differentiable, then the dot product $f(a) ∈ I$ of the gradient at a point $f$ with a vector $(∇f&thinsp;)_{x} ⋅ v$ gives the directional derivative of $x$ at $v$ in the direction $f$. It follows that in this case the gradient of $x$ is orthogonal to the level sets of $v$. For example, a level surface in three-dimensional space is defined by an equation of the form $f$. The gradient of $f$ is then normal to the surface.

More generally, any embedded hypersurface in a Riemannian manifold can be cut out by an equation of the form $F(x, y, z) = c$ such that $F$ is nowhere zero. The gradient of $F(P) = 0$ is then normal to the hypersurface.

Similarly, an affine algebraic hypersurface may be defined by an equation $dF$, where $F$ is a polynomial. The gradient of $F(x_{1}, ..., x_{n}) = 0$ is zero at a singular point of the hypersurface (this is the definition of a singular point). At a non-singular point, it is a nonzero normal vector.

Conservative vector fields and the gradient theorem
The gradient of a function is called a gradient field. A (continuous) gradient field is always a conservative vector field: its line integral along any path depends only on the endpoints of the path, and can be evaluated by the gradient theorem (the fundamental theorem of calculus for line integrals). Conversely, a (continuous) conservative vector field is always the gradient of a function.

Gradient is direction of steepest ascent
The gradient of a function $$f \colon \R^n \to \R$$ at point $F$ is also the direction of its steepest ascent, i.e. it maximizes its directional derivative:

Let $$ v \in \R^n$$ be an arbitrary unit vector. With the directional derivative defined as

$$\nabla_v f (x) = \lim_{h \rightarrow 0} \frac{f(x + vh) - f(x)}{h},$$

we get, by substituting the function $$f(x + vh)$$ with its Taylor series,

$$\nabla_v f (x) = \lim_{h \rightarrow 0} \frac{(f(x) + \nabla f \cdot vh + R) - f(x)}{h},$$

where $$R$$ denotes higher order terms in $$vh$$.

Dividing by $$h$$, and taking the limit yields a term which is bounded from above by the Cauchy-Schwarz inequality

$$|\nabla_v f (x)| = |\nabla f \cdot v| \le |\nabla f| |v| = |\nabla f|.$$

Choosing $$v^* = \nabla f/|\nabla f|$$ maximizes the directional derivative, and equals the upper bound

$$|\nabla_{v^*} f (x)| = |(\nabla f)^2/|\nabla f|| = |\nabla f|.$$

Jacobian
The Jacobian matrix is the generalization of the gradient for vector-valued functions of several variables and differentiable maps between Euclidean spaces or, more generally, manifolds. A further generalization for a function between Banach spaces is the Fréchet derivative.

Suppose $F$ is a function such that each of its first-order partial derivatives exist on $x$. Then the Jacobian matrix of $f : R^{n} → R^{m}$ is defined to be an $ℝ^{n}$ matrix, denoted by $$\mathbf{J}_\mathbb{f}(\mathbb{x})$$ or simply $$\mathbf{J}$$. The $f$th entry is $\mathbf J_{ij} = {\partial f_i} / {\partial x_j}$. Explicitly $$\mathbf J = \begin{bmatrix} \dfrac{\partial \mathbf{f}}{\partial x_1} & \cdots & \dfrac{\partial \mathbf{f}}{\partial x_n} \end{bmatrix} = \begin{bmatrix} \nabla^\mathsf{T} f_1 \\ \vdots \\ \nabla^\mathsf{T} f_m \end{bmatrix} = \begin{bmatrix} \dfrac{\partial f_1}{\partial x_1} & \cdots & \dfrac{\partial f_1}{\partial x_n}\\ \vdots & \ddots & \vdots\\ \dfrac{\partial f_m}{\partial x_1} & \cdots & \dfrac{\partial f_m}{\partial x_n} \end{bmatrix}.$$

Gradient of a vector field
Since the total derivative of a vector field is a linear mapping from vectors to vectors, it is a tensor quantity.

In rectangular coordinates, the gradient of a vector field $m×n$ is defined by:

$$\nabla \mathbf{f}=g^{jk}\frac{\partial f^i}{\partial x^j} \mathbf{e}_i \otimes \mathbf{e}_k,$$

(where the Einstein summation notation is used and the tensor product of the vectors $(i,j)$ and $f = (&thinsp;f, f, f)$ is a dyadic tensor of type (2,0)). Overall, this expression equals the transpose of the Jacobian matrix:

$$\frac{\partial f^i}{\partial x^j} = \frac{\partial (f^1,f^2,f^3)}{\partial (x^1,x^2,x^3)}.$$

In curvilinear coordinates, or more generally on a curved manifold, the gradient involves Christoffel symbols:

$$\nabla \mathbf{f}=g^{jk}\left(\frac{\partial f^i}{\partial x^j}+{\Gamma^i}_{jl}f^l\right) \mathbf{e}_i \otimes \mathbf{e}_k,$$

where $e_{i}$ are the components of the inverse metric tensor and the $e_{k}$ are the coordinate basis vectors.

Expressed more invariantly, the gradient of a vector field $g$ can be defined by the Levi-Civita connection and metric tensor:

$$\nabla^a f^b = g^{ac} \nabla_c f^b ,$$

where $e_{i}$ is the connection.

Riemannian manifolds
For any smooth function $f$ on a Riemannian manifold $f$, the gradient of $∇_{c}$ is the vector field $(M, g)$ such that for any vector field $f$, $$g(\nabla f, X) = \partial_X f,$$ that is, $$g_x\big((\nabla f)_x, X_x \big) = (\partial_X f) (x),$$ where $∇f$ denotes the inner product of tangent vectors at $X$ defined by the metric $g_{x}$ and $x$ is the function that takes any point $g$ to the directional derivative of $∂_{X}&thinsp;f$ in the direction $x ∈ M$, evaluated at $f$. In other words, in a coordinate chart $X$ from an open subset of $x$ to an open subset of $φ$, $M$ is given by: $$\sum_{j=1}^n X^{j} \big(\varphi(x)\big) \frac{\partial}{\partial x_{j}}(f \circ \varphi^{-1}) \Bigg|_{\varphi(x)},$$ where $R^{n}$ denotes the $(∂_{X}&thinsp;f&thinsp;)(x)$th component of $X$ in this coordinate chart.

So, the local form of the gradient takes the form:

$$\nabla f = g^{ik} \frac{\partial f}{\partial x^k} {\textbf e}_i .$$

Generalizing the case $j$, the gradient of a function is related to its exterior derivative, since $$(\partial_X f) (x) = (df)_x(X_x) .$$ More precisely, the gradient $X$ is the vector field associated to the differential 1-form $M = R^{n}$ using the musical isomorphism $$\sharp=\sharp^g\colon T^*M\to TM$$ (called "sharp") defined by the metric $∇f$. The relation between the exterior derivative and the gradient of a function on $df$ is a special case of this in which the metric is the flat metric given by the dot product.