The gradient of a scalar function \(f\) is a multidimensional derivative of the function \(f\). In a three-dimensional case, you get the gradient by applying the Nabla operator \(\nabla\) to the scalar function \(f\). You will understand what is meant by this after the lesson.

Necessary ingredient: scalar function

A three-dimensional scalar function \(f\) takes three arguments \(x\), \(y\), and \(z\) and spits out a number (a scalar).

The three variables \(x,y,z\) are usually spatial coordinates in physics. In general, they do not have to be space coordinates, they can also represent other quantities, such as radial distance and two angles: \(r,\theta,\varphi\). We assume here for the explanation of the gradient that \(x,y,z\) represent spatial coordinates.

The function \(f(x,y,z)\) assigns a number to each point \((x,y,z)\) in space. For example, \(f(x,y,z)\) could be a temperature function \(T(x,y,z)\) that assigns a temperature \(T(x,y,z)\) to each position in space.

To better illustrate a scalar function \( f \), we assume that it depends on two spatial coordinates \((x,y)\), that is, it is two-dimensional. Then you can think of \( f(x,y) \) as a curved surface with mountains and valleys (sort of a landscape).

Gradient in one dimension

You are at some location \((x,y)\) on this landscape (function) and want to know what the slope would be if you were walking in, say, the \(x\) direction. The slope in \(x\)-direction is the derivative of the function with respect to \(x\):

Slope of the function in x-direction

Formula anchor$$ \begin{align} \frac{\partial f(x,y)}{\partial x} \end{align} $$

How do we find the slope of the landscape \(f(x,y)\) if we go in the \(y\) direction? We differentiate \(f(x,y)\) with respect to \(y\) and get the slope in \(y\)-direction:

Slope of the function in y-direction

Formula anchor$$ \begin{align} \frac{\partial f(x,y)}{\partial y} \end{align} $$

Depending on the location \((x,y)\) we are at, the slopes 2 and 3 are of course different:

On the mountain, the \(x\) and \(y\) directions tend to be downhill - that is, both slopes are negative and rather large.

In a valley it goes uphill - that is, both slopes are positive and rather large.

And in a plateau, the landscape is flat - that is, the slopes are zero in both directions.

Gradient in two dimensions

What if we want to consider not only the slope in \(x\) direction, but also in \(y\) direction? Then we have to consider two derivatives of the function \(f(x,y)\):

Derivatives of a scalar function with respect to x and y

We can consider the derivatives separately or we can combine them to create a new mathematical object that is indispensable in physics and mathematics, namely the gradient in more than one dimension. In our case here: In two dimensions.

To do this, we write down the two derivatives 9 in a column vector:

To keep 10 a bit more compact, we omit \((x,y)\) dependence, but keep in mind that \(f\) may still depend on \(x\) and \(y\).

By writing the derivative in a column, we thereby obtained a vector function (also called vector field). This vector has a magnitude and a direction. But before we look at which direction the two-dimensional gradient 10 points, let's rewrite it a bit. To do this, we pull the function \(f\) out of the vector:

The "vector" in Eq. 11 with derivatives is a so-called operator. Stand-alone derivatives, of course, make not much sense. An operator takes effect only when it is applied to a function, as in this case to the scalar function \(f\). This operator in Eq. 11 is called the Nabla operator \(\nabla\):

Here we have simply added the \(z\) dependence to the \(f\) function and added the derivative of \(f\) to \(z\) as the third component in the gradient.

Gradient points to the steepest ascent

To understand why the gradient vector \( \nabla f \) points in the direction of the steepest ascent, we exploit the so-called directional derivative. For this we take a unit vector \(\boldsymbol{v}\) pointing in any direction. The only important thing is that it is a unit vector, that is normalized.

Remember that the magnitude \( |\nabla f| \) is a constant that we cannot change. Why not? Because \(f\) is fixed. As I said before, you can think of the \(f\) function as a landscape, with rigid hills and valleys. On this surface there is the unit vector \( \boldsymbol{v} \) whose direction we can change and thus scan the landscape \(f\).

The slope of the shadow of \( \boldsymbol{v} \) on the plane, we get with the help of the following scalar product:

Directional derivative

Formula anchor$$ \begin{align} \nabla{f} ~\cdot~ \boldsymbol{ v } \end{align} $$

The scalar product 19 is the directional derivative of the function \(f\) in the direction of \(\boldsymbol{ v }\).

The result of this scalar product is a pure number, namely the slope in the direction of \(\boldsymbol{ v }\). For example, if you choose \(\boldsymbol{ v }\) as the unit vector in the \(x\) direction: \(\boldsymbol{ v } = \boldsymbol{\hat e}_{\text x}\), then the scalar product 19 gives the slope in \(x\) direction.

The question is, why does 19 indicate the steepest ascent? We can try around and use different unit vectors \(\boldsymbol{ v }\) in the scalar product 19. The steepest ascent has that unit vector \(\boldsymbol{ v }\) which yields the largest scalar product 19.

Instead of laboriously inserting all conceivable unit vectors into 19, there is a more sophisticated way to find out the maximum slope in the direction of \(\boldsymbol{ v }\). To do this, we need to rewrite the scalar product 19. To do this, we use the geometric definition of the scalar product:

Scalar product using an angle

Formula anchor$$ \begin{align} \boldsymbol{a} ~\cdot~ \boldsymbol{b} ~=~ a \, b \, \cos(\theta) \end{align} $$

Thus we can write the directional derivative 19 as follows:

Direction derivation by using an angle

Formula anchor$$ \begin{align} \nabla f ~\cdot~ \boldsymbol{v} ~=~ |\nabla f| \, v \, \cos(\theta) \end{align} $$

Here the non-bold \(v\) is the magnitude of the vector \(\boldsymbol{v}\). Now it is much easier to determine the maximum slope in the direction of \(\boldsymbol{ v }\). We have assumed that the vector \( \boldsymbol{v} \) is normalized. If it is normalized, then it has the magnitude: \( v = 1\). Thus Eq. 21 becomes:

Directional derivative with unit vector

Formula anchor$$ \begin{align} \nabla f ~\cdot~ \boldsymbol{v} ~=~ |\nabla f| \, \cos(\theta) \end{align} $$

So far so good. The only way we can vary the slope is by the angle \(\theta\) enclosed by the vectors \(\nabla f\) and \(\boldsymbol{v}\). The cosine in Eq. 22 has its largest value at \(\theta=0\): \( \cos(0) ~=~ 1 \). So we set \(\theta=0\) to get the largest slope:

Steepest ascent for directional discharge

Formula anchor$$ \begin{align} \nabla f ~\cdot~ \boldsymbol{v} ~=~ |\nabla f| \end{align} $$

By setting \(\theta=0\), we have aligned the vectors \( \nabla \, f \) and \( \boldsymbol{v} \) parallel to each other (see Illustration 5). That means: Now vector \( \boldsymbol{v} \) points in the same direction as vector \( \nabla \, f \). Also, we made the scalar product 21, that is, the slope, as maximum as possible. And as you see in 21: The maximum slope is the magnitude \(|\nabla f|\) of the gradient vector. Consequently, the gradient vector \(\nabla f\) points in the direction of largest ascent!

Calculate directional derivative in 4 steps

If you don't want to calculate the direction of the steepest ascent 23, but the ascent in any direction \(\boldsymbol{v}\), then you have to do the following:

Directional derivative in any direction

Formula anchor$$ \begin{align} \nabla{f} ~\cdot~ \frac{\boldsymbol v}{v} \end{align} $$

Here we no longer assume that the vector \(\boldsymbol{v}\) is normalized. Therefore, we must always normalize it by dividing by the magnitude \(|\boldsymbol{v}| =: v \) of the vector. Follow these 4 steps to calculate the directional derivative in any direction:

Calculate the gradient \( \nabla f \) of a given scalar function \( f \).

Normalize the vector \( \boldsymbol{ v } \) by dividing it by its magnitude: \( \boldsymbol{ v } / v \).

Form the scalar product between the gradient \( \nabla f \) and the normalized vector \(\boldsymbol{v}/v\).

Insert specific values for the variables \( x, y, z \). By doing this you set the specific position \( (x, y, z) \) where you want to calculate the slope in the direction of \( \boldsymbol{v} \).

+ Perfect for high school and undergraduate physics students + Contains over 500 illustrated formulas on just 140 pages + Contains tables with examples and measured constants + Easy for everyone because without vectors and integrals