Gradient (source code)

= Gradient
{title2=$\nabla f$}
{wiki}

In <Cartesian coordinates> on <Euclidean space>, the gradient of a scalar-valued <differentiable function> is the <vector> of its first <partial derivatives>. It converts a <scalar field>, such as <temperature> or a height, into a <vector field> describing its local change.

For a <unit vector> $u$, the <directional derivative> is $D_uf=u\cdot\nabla f$. The <Cauchy-Schwarz inequality> gives $|D_uf|\leq|\nabla f|$. At a point where $\nabla f\ne0$, the greatest increase per unit distance occurs along $u=\nabla f/|\nabla f|$, while the opposite direction gives the greatest decrease. These are first-order statements at the current point; they do not predict how the <function> behaves far along a straight path.

For $f(x,y)=x^2+2y^2$ at $(1,1)$, $\nabla f=(2,4)$. Moving in the $x$ direction gives rate $2$ and moving in the $y$ direction gives rate $4$, but the steepest direction is $(1,2)/\sqrt5$, with
$$
D_uf=\boxed{2\sqrt5}.
$$
The direction $(-2,1)/\sqrt5$ has rate zero and is tangent to the <level curve> through that point. More generally, differentiating $f(\gamma(t))=\text{constant}$ along a regular <level curve> gives $\nabla f\cdot\gamma'=0$, so the <gradient> is its <normal vector>.

\Image[/gradient-directional-derivative.png]
{title=A gradient is normal to level curves and determines the directional derivative for every unit direction}

This is useful when navigating a measured <scalar field> or applying <gradient descent>: one collection of <partial derivatives> predicts every infinitesimal directional change. The derivative assumes a <differentiable function>, not merely the existence of all directional derivatives. <Calculus Volume 3 by Gilbert Strang and others/4.6 Directional Derivatives and the Gradient>[Calculus Volume 3 by Gilbert Strang and others; OpenStax: Directional derivatives and the gradient]{ref}.