xaktly | Vector calculus

The gradient


The Gradient


The gradient is the direction of steepest increase in a function. To illustrate, take the function $f(x,y) = 9-x^2-y^2$, plotted below.

The plot shows the function, a downward-opening paraboloid. Below it is its contour plot, a projection of the level curves on the $xy$ plane.

Let's look at any level curve on this surface, a place where $f(x,y) = C$, where $C$ is a constant. Now let's parameterize the level curve and write each independent variable as a function of the parameter $t$:

$$\vec r(t) = x(t) \hat i + y(t) \hat j = C$$

Now if we take the derivative of each side with respect to $t$, we get

$$ \begin{align} \frac{d}{dt} f(x(t), y(t)) &= \frac{d}{dt}C \\[5pt] \frac{d}{dt} f(x(t), y(t)) &= 0 \end{align}$$

Using the chain rule, we can write that as

$$\frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y} \frac{dy}{dt} = 0$$

Then we can make an interesting rearrangement by invoking the dot product to rewrite that equation as

$$\left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right) \cdot \left( \frac{dx}{dt}, \frac{dy}{dt} \right) = 0 \tag{1}$$


We can define the vector on the left side of (1) as $\nabla f$, commonly pronounced "del f", the gradient of function $f(x,y)$.

$$\nabla f = \left( \frac{\partial f}{\partial x}, \frac{\partial f}{\partial y} \right)$$

And the vector on the right is just

$$\frac{d \vec r}{dt} = \left( \frac{dx}{dt}, \frac{dy}{dt} \right)$$

So we can rewrite expression (1) as

$$\nabla f \cdot \frac{d \vec r}{dt} = 0$$

If $\vec r(t)$ is one of our level curves, then its derivative, $\frac{d \vec r}{dt}$, is tangent to that curve at any given value of $t$. Because the dot product of $\nabla f$ and $r'(t)$ is zero, $\nabla f$ must be normal to the level curve.

Here is a plot of just the contours of our function. The derivative along any level curve is tangent to the curve, and by definition, the gradient vector is always normal to that. In fact, the gradient always points in the direction of steepest increase of the slope of the function.

We can also think of the gradient as pointing in the direction of shortest distance to the next level curve.

The Gradient vector

For a function of $n$ independent variables, $f(x_1, x_2, \dots , x_n)$, the gradient vector of $f$ is

$$\nabla f = \left( \frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \dots, \frac{\partial f}{\partial x_n} \right)$$


Gradient: direction of steepest ascent


The gradient of a vector function is a vector at a point which gives the direction and the rate of greatest increase of the function.

The vectors $(3,3)$ and $(4,4)$ are gradient vectors. They show the direction of steepest increase of this 3D function at those points.

The gradient of a function like $f(x, y, z)$ is

$$\text{gradient} = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}, \frac{\partial f}{\partial z} \right) \tag{1}$$

We use the symbol $\nabla$, which we often read as "del" to indicate the gradient. So we could rewrite expression (1) above as

$$\nabla f = \left(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y}, \frac{\partial f}{\partial z} \right)$$

A further modification is that we often use the operator notation $\nabla \cdot$, where

$$\nabla \cdot = \left( \frac{\partial}{\partial x}, \frac{\partial}{\partial y}, \frac{\partial}{\partial z} \right)$$

This operator is written as a row vector, and the intention is to take the dot product with another vector of the same dimension. For example, consider the function $f(x, y) = 2xy^2 - 3z$, for which $x = 2t-1$, $y = -e^t$ and $z = \frac{1}{t}$. The gradient is given by

$$ \begin{align} \nabla \cdot f(x,y) &= \nabla \cdot (2t-1, -e^t, t^{-1}) \\[5pt] &= \left( \frac{\partial}{\partial t}, \frac{\partial}{\partial t}, \frac{\partial}{\partial t} \right) \cdot (2t-1, -e^t, t^{-1}) \\[5pt] &= (2, -e^t, -t^{-2}) \end{align}$$

This is the path of steepest ascent on the surface that represents this function.

Example 1

Calculate the gradient of the function $f(x,y)=x^2+y^2$.


The function looks like this:

The gradient is

$$ \begin{align} \nabla f(x,y) &= \bigg\langle \frac{\partial f(x,y)}{\partial x}, \; \frac{\partial f(x,y)}{\partial y} \bigg\rangle \\[5pt] &= \langle 2x, \; 2y\rangle \end{align}$$

We can rationalize this result by thinking about the 1D derivative of $f(x) = x^2$, $f'(x) = 2x$. The slope of the function increases linearly as $x$ increases. The same is true in both dimensions for $f(x,y)$. Here is a contour plot of the function with a couple of gradient vectors illustrated.

Example 2

Calculate the gradient of the function $f(x,y)=-\frac{2}{3}xy^2$.


Here's a plot of the function:

The gradient is

$$ \begin{align} \nabla f(x,y) &= \bigg\langle \frac{\partial f(x,y)}{\partial x}, \; \frac{\partial f(x,y)}{\partial y} \bigg\rangle \\[5pt] &= \bigg\langle -\frac{2}{3}y^2, \; -\frac{4}{3}xy\bigg\rangle \end{align}$$

Here is a contour plot of the function with two of the gradient vectors sketched in.

Gradient vectors are always normal (perpendicular) to level curves in the contour plot.


Example 3

Find and characterize any critical points of the function $f(x,y) = x \, e^{-2x^2-2y^2}$


First calculate the first partial derivatives — this is a tricky function requiring the product and chain rules; be careful. I've skipped some steps for brevity in calculating these partial derivatives.

$$ \begin{align} f_x &= e^{-2x^2-2y^2}[1-4x^2] = 0 \\[5pt] 1 - 4x^2 &= 0 \tag{1} \\[5pt] x &= \pm \frac{1}{2} \\[8pt] f_y &= -4xy \, e^{-2x^2-2y^2} = 0 \\[5pt] y &= 0 \end{align}$$

Notice that in (1), we used the fact that $e^{-2x^2-2y^2}$ is never equal to zero, which makes finding the zeros of the first partials. So our critical points are $\left( \frac{1}{2}, 0 \right), \; \left( -\frac{1}{2}, 0 \right)$.

Now our second derivatives are

$$ \begin{align} f_{xx} &= e^{-2x^2-2y^2}[16x^3 - 12x] \\[5pt] f_{yy} &= e^{-2x^2-2y^2}[-4x+16y^2] \\[5pt] f_{xy} &= -4y \, e^{-2x^2-2y^2}[1-4x^2] \end{align}$$

As a shorcut, we can calculate $e^{-2x^2-2y^2}$ for $x = \pm \frac{1}{2}, \; y = 0$. It's value (regardless of the sign of $x$) is $e^{1/2}$. What will matter most to us is that it's a positive number.

Now we can calculate

$$ \begin{align} f_{xx}\left( \frac{1}{2}, 0 \right) &= \frac{-4}{\sqrt{e}} \\[5pt] f_{xx}\left( -\frac{1}{2}, 0 \right) &= \frac{4}{\sqrt{e}} \\[5pt] f_{yy}\left(\pm \frac{1}{2}, 0 \right) &= \frac{-2}{\sqrt{e}} \\[5pt] f_{xy} \left(\pm \frac{1}{2}, 0 \right) &= 0 \end{align}$$

Now we can caclulate the determinant, $D$

$$D = \text{det} \left( \begin{array}{rr} \frac{-4}{\sqrt{e}} & 0 \\ 0 & \frac{-2}{\sqrt{e}} \end{array} \right) = \frac{8}{e} \gt 0 $$

Finally, we can evaluate each critical point:

$$ \begin{align} \left( \frac{1}{2}, 0 \right): &\phantom{00} D \gt 0 \phantom{00} f_{xx} \lt 0 \rightarrow \text{max} \\[5pt] \left( -\frac{1}{2}, 0 \right): &\phantom{00} D \gt 0 \phantom{00} f_{xx} \gt 0 \rightarrow \text{max} \end{align}$$

Our critical points include a local maximum (which is also the global max in this case) at $(x,y) = \left( \frac{1}{2}, 0 \right)$ and a local minimum (also the global min) at $(x,y) = \left( -\frac{1}{2}, 0 \right)$. These findings are consistent with the 3D plot below:


This function does not have a saddle point.


Practice problems

Find the gradient of the function and evaluate it to a specific vector at the point given.


  1.   $f(x,y) = \frac{10-x^2-y^2}{2}$   at   $(1, 2)$

    Solution

    $$\frac{\partial f}{\partial x} = -x \phantom{000} \frac{\partial f}{\partial y} = -y$$

    $$ \begin{align} \nabla f &= \langle -x, \; -y \rangle \\[5pt] \nabla f_{(1, 2)} &= \langle -1, \; -2 \rangle \end{align}$$


  2.   $f(x,y) = xy-yz+xz$   at   $(1, 2, 3)$

    Solution

    $$\frac{\partial f}{\partial x} = y+z \phantom{000} \frac{\partial f}{\partial y} = x-z$$

    $$\frac{\partial f}{\partial z} = x-y$$

    $$ \begin{align} \nabla f &= \langle y+z, \; x-z, \; x-y \rangle \\[5pt] \nabla f_{(1, 2,3)} &= \langle 2+3, \; 1-3, \; 1-2 \rangle \\[5pt] &= \langle 5, -2, -1 \rangle \end{align}$$

  1.   $f(x,y) = \ln(x^2+y^2+3z^2)$   at   $(1,2,4)$

    Solution

    $$ \begin{align} \frac{\partial f}{\partial x} &= \frac{2x}{x^2+y^2+3z^2} \\[5pt] \frac{\partial f}{\partial y} &= \frac{2y}{x^2+y^2+3z^2} \\[5pt] \frac{\partial f}{\partial z} &= \frac{6z}{x^2+y^2+3z^2} \end{align}$$

    $\leftarrow$ Scroll left-right $\rightarrow$

    $$ \begin{align} \nabla f &= \langle \frac{2x}{x^2+y^2+3z^2}, \; \frac{2y}{x^2+y^2+3z^2}, \; \frac{6z}{x^2+y^2+3z^2} \rangle \\[5pt] \nabla f_{(1, 2,4)} &= \langle 2+3, \; 1-3, \; 1-2 \rangle \\[5pt] &= \langle \frac{2}{53}, \frac{4}{53}, \frac{24}{53} \rangle \end{align}$$


  2.   $f(x,y) = x^2 + xy + y^2$   at   $(-5, 4)$

    Solution

    $$\frac{\partial f}{\partial x} = 2x+y \phantom{000} \frac{\partial f}{\partial y} = x+2y$$

    $$ \begin{align} \nabla f &= \langle 2x+y, \; x+2y \rangle \\[5pt] \nabla f_{(-5,4)} &= \langle -10+4, \; -5+8 \rangle \\[5pt] &= \langle -6, \; 3 \rangle \end{align}$$


Partial derivatives

Rates of change of a function along one coordinate direction

Directional derivatives

How to find the slope of a multidimensional function in any direction

Creative Commons License   optimized for firefox
xaktly.com by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. ©2024,2026, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to jeff.cruzan@verizon.net.