The directional derivative and the gradient
The directional derivative
Let’s revisit our two-variable mountain range function , where is the height a mountain range at point . Imagine you are standing at some point . The slope of the ground in front of you will depend on the direction you are facing. It might slope steeply up in one direction, be relatively flat in another direction, and slope steeply down in yet another direction.
You already learned about the slope in the positive direction and the slope in the positive direction. These slopes are the partial derivatives with respect to and with respect to . We can compute the slope in any direction with something called the directional derivative.
To take a directional derivative, we first need to specify the direction. We do that by specifying a vector that points in the direction in which we want to compute the slope. (Since we don’t care about the length of , we can assume it is a unit vector with length .) We write the directional derivative of in the direction at the point as . The directional derivative is simply the slope of when standing at the point and facing the direction given by . If and were given in meters, then would be the change in height per meter as you moved in the direction given by when you are at the point .
Note that is a number, not a matrix. In fact, the directional derivative is the same as a partial derivative if points in the positive or positive direction. For example, if , then . Similarly if , then .
In the following CVT, the two-variable mountain range described by is shown as a level curve plot. The point is shown in dark red (which you can move by dragging). Although I didn’t label the level curves with their height, the height at point (i.e., ) is shown on the bottom (cyan) slider labeled by “f”. (You can recognize the two steep mountain peaks by the closely spaced circular level curves.)
The direction vector is shown by the light green vector emanating from . You can change the direction of by changing to anything between 0 and using the top slider. The value of is shown by the middle (light green) slider labeled by “Duf”. Notice that for this first CVT, is set so that when , then points in the positive direction () so that . Similarly, when , then points in the positive direction () so that .
If you make point in a direction parallel to the level curve, what happens to ? (Since the height is constant along a level curve, you should be able to infer what the slope in that direction should be.) What happens to when you turn to point in the opposite direction (i.e., add or subtract from )?
For fun, I’ve duplicated this CVT using a plot of , below. In this view, the steepness may be easier to see. However, this view is a little misleading for two reasons. First, the dark red dot now floats on the surface of the mountain. Hence, the dark red dot is no longer , which for this example is really a point in two dimensions. Second, the light green vector is now a three-dimensional vector that points up or down the mountain. The light green vector is no longer exactly the direction vector , which for this example is really a two-dimensional vector. Nonetheless, this second view further illustrates the concepts of the directional derivative. You can manipulate it in the same way as above.
The gradient
In most cases, there is always one direction where the directional derivative is the largest. This is the “uphill” direction. (In some cases, such as when you are at the top of a mountain peak or at the lowest point in a valley, this might not be true.) Let’s call this direction of maximal slope . Both the direction and the maximal directional derivative are captured by something called the gradient of and denoted by . The gradient is a vector that points in the direction of and whose magnitude is . In math, we can write this as and .
To illustrate, the below CVT shows the gradient as a dark blue vector emanating from the point . (Actually, I made the vector ten times longer than it should be so you can see it better.) The actual length (or magnitude) of the gradient is shown by the dark blue line on the middle (light green) slider.
The CVT also includes the vector in light green, as above, and shows the value of the directional derivative by the light green line on the middle (cyan) slider. As before, you can change , you can change the vector . This time, however, I’ve changed the definition of . Above, was the angle from the positive direction. Now, is the angle between the direction specified by and the direction specified by the gradient. (So, for example, when , points in the same direction as the gradient.)
Notice how the dark blue gradient vector always points up the mountains (in fact, the gradient is always perpendicular to the level curves). When the level curves are close together, the gradient is large. What happens to the gradient at the tops of the mountains?
Note that when (or ), the directional derivative (shown by the light green line on the middle slider) and the magnitude of the gradient (shown by the dark blue line on the middle slider) are identical, i.e., . When , then points in the opposite direction of the gradient, and . For what values of is ?
By moving (the dark red point) around and changing , I hope you can convince yourself that, for a fixed , the maximal value of occurs when and point in the same direction (i.e., when or ), and the minimum value occurs when and point in opposite directions (i.e., when ). Hence always lies between and . It turns out that the relationship between the gradient and the directional derivative can be summarized by the equation
where is the angle between and the gradient. (Recall that is a unit vector, meaning that .)
I also duplicated this CVT using a plot of , below. Although its steepness may be easier to see, recall from the above discussion that the dark red point is no longer really and the light green vector is no longer really . Similarly, since the dark blue vector points up the mountain, it is no longer really the gradient , which, for a function of two variables, is a two-dimensional vector. (I also couldn’t get the length of the dark blue vector to accurately represent the length of the gradient; the true length of the gradient is given by the dark blue line on the bottom (light green) slider.) Despite its shortcomings, I hope this last CVT can help you see how the gradient always points in the direction where the mountain rises most steeply.
Examples are available here.