So far, we have discussed partial derivatives as a way to measure the rate of change of a surface \(z = f(x,y)\). However, partial derivatives only measure change in the simplest possible ways: parallel to the \(x\)-axis and parallel to the \(y\)-axis.
If we are standing on the side of a mountain, we typically aren’t restricted to walking due east or due north—we walk in many directions! As such, we need a mathematical tool to calculate the slope of the surface along any arbitrary trajectory. This is called the directional derivative.
Before we define it, let’s briefly recall how we specify directions (that is, the data for vectors without concern for their length). We will use unit vectors—those are vectors with a length of exactly \(1\).
If we have a non-zero vector \(\vec{v}\), we can normalize by dividing by its magnitude. In other words, the vector \(\vec{u} \coloneqq \frac{\vec{v}}{\Norm{\vec{v}}}\) points in the same direction as \(\vec{v}\) and will always have length \(1\).
The Gradient
To keep track of our standard partial derivatives, we will package them into a convenient vector gadget called the gradient.
The Gradient
If \(f(x,y)\) is a differentiable function, the gradient of \(f\), denoted \(\Gradient f\), is the vector-valued function composed of its partial derivatives: \[
\Gradient f(x,y) \coloneqq \Vector{f_x(x,y), f_y(x,y)}.
\] More generally, if we have a function of many variables \(f(x_1,\dots,x_n)\), then we define \[
\Gradient f(x_1, \dots, x_n) \coloneqq \left\langle \frac{\partial f}{\partial {x_1}}, \dots, \frac{\partial f}{\partial {x_n}} \right\rangle.
\]
Note that the gradient exists if and only if the function is differentiable! As we will see very shortly, \(\Gradient{f}\) is the key to unlocking derivatives in any direction.
18.2 Directional Derivatives
We define the directional derivative using a limit, just as we did for standard derivatives in single-variable calculus. Instead of varying the input purely in \(x\) or \(y\), we define it along a unit vector \(\vec{u}\).
The directional derivative of \(f\) at \((x_0,y_0)\) in the direction of the unit vector \(\vec{u} = \Vector{a,b}\) is \[
D_{\vec{u}} f(x_0,y_0) = \lim_{h \to 0} \frac{f(x_0 + ha, y_0 + hb) - f(x_0, y_0)}{h}
\] provided this limit exists. Equivalently, if we write the point \((x_0, y_0)\) as a vector \(P = \Vector{x_0, y_0}\), we can define the directional derivative in terms of the parametric line through \(P\) along \(\vec{u}\): \[
D_{\vec{u}} f(P) = \lim_{h \to 0} \frac{f(P + h\vec{u}) - f(P)}{h}
\]
First we demonstrate an example where we compute a directional derivative directly from this definition—a better method will be demonstrated shortly.
Example 18.1 (Computing via the Limit) Let \(f(x,y) = x^2 - y^2\). We want to find the directional derivative at the point \((2,1)\) in the direction of the unit vector \(\vec{u} = \Vector{-\frac{3}{5}, \frac{4}{5}}\).
Using the limit definition, let’s evaluate the function at our shifted inputs: \[
\begin{aligned}
f\left(2 - \tfrac{3}{5}h, 1 + \tfrac{4}{5}h\right) &= \left(2 - \tfrac{3}{5}h\right)^2 - \left(1 + \tfrac{4}{5}h\right)^2 \\
&= \left(4 - \tfrac{12}{5}h + \tfrac{9}{25}h^2\right) - \left(1 + \tfrac{8}{5}h + \tfrac{16}{25}h^2\right) \\
&= 3 - 4h - \tfrac{7}{25}h^2.
\end{aligned}
\] The value at our starting point is \(f(2,1) = 2^2 - 1^2 = 3\). Plugging these into the difference quotient gives: \[
\begin{aligned}
D_{\vec{u}} f(2,1) &= \lim_{h \to 0} \frac{\left(3 - 4h - \tfrac{7}{25}h^2\right) - 3}{h} \\
&= \lim_{h \to 0} \frac{-4h - \tfrac{7}{25}h^2}{h} \\
&= \lim_{h \to 0} -\left( 4 + \tfrac{7}{25}h \right) = -4.
\end{aligned}
\] Hence, we expect that a small step in the \(\vec{u}\) direction would yield a proportionate change in \(z\) value scaled by \(-4\).
Here is a view of our point and direction vector on a contour map of the surface:
We can see that the small step moves us towards brighter colors (higher values, in this color scheme), and so the fact that the derivative is positive makes visual sense. Here is a plot of the graph \(z = x^2 - y^2\), showing the line tangent to the surface along our specific directional vector:
Evaluating limits every time we want a directional derivative is tedious! Fortunately, if the function is differentiable, the directional derivative is just a simple dot product involving the gradient of our function.
If \(f = f(x,y)\) is a differentiable function, then \(f\) has a directional derivative in the direction of any unit vector \(\vec{u} = \Vector{a,b}\) and \[
D_{\vec{u}} f = \Gradient{f} \cdot \vec{u}.
\]
This formulation of the directional derivative is very handy! Firstly, we can see how it generalizes the partial derivatives. If we want to walk purely in the \(x\) direction, the associated unit vector is \(\vec{u} = \Vector{1, 0}\). We have: \[
D_{\Vector{1,0}} f = \Gradient{f} \cdot \Vector{1,0} = \Vector{f_x, f_y} \cdot \Vector{1,0} = f_x.
\] Unsurprisingly, moving purely in the \(x\)-direction yields the partial derivative with respect to \(x\). Similarly, \(D_{\Vector{0,1}} f = f_y\).
Example 18.2 We can swiftly recalculate Example 18.1. For \(f(x,y) = x^2 - y^2\), the gradient is \(\Gradient{f} = \Vector{2x, -2y}\). At the point \((2,1)\), the gradient vector is \(\Gradient{f}(2,1) = \Vector{4, -2}\). Taking the dot product with \(\vec{u} = \Vector{-\frac{3}{5}, \frac{4}{5}}\) gives: \[
D_{\vec{u}} f(2,1) = \Vector{4, -2} \cdot \Vector{-\tfrac{3}{5}, \tfrac{4}{5}} = - \frac{12}{5} - \frac{8}{5} = -4.
\]
Maximizing the Directional Derivative
Because the directional derivative is calculated via a dot product, we can use the geometric definition of the dot product to learn something important about the gradient. Recall that \(\vec{v} \cdot \vec{w} = \Norm{\vec{v}} \Norm{\vec{w}} \cos \theta\), where \(\theta\) is the angle measured between \(\vec{v}\) and \(\vec{w}\).
In our case, when \(\vec{u}\) is a unit vector, we have: \[
D_{\vec{u}} f = \Gradient{f} \cdot \vec{u} = \Norm{\Gradient{f}} \cos \theta,
\] where \(\theta\) measures the angle between the gradient vector and our chosen direction \(\vec{u}\). The value of \(\cos \theta\) is maximized when \(\theta = 0\) (where \(\cos \theta = 1\)). This occurs when our direction vector \(\vec{u}\) points in the exact same direction as the gradient \(\Gradient{f}\). Consequently:
The gradient vector always points in the direction of steepest ascent, and the maximum possible rate of change at that point is simply the magnitude of the gradient, \(\Norm{\Gradient{f}}\).
Example 18.3 (Visualizing the Gradient Field) Let’s return to the surface from Example 14.3, cut out as the graph of \(f(x,y) = x^4 + y^4 - 4xy\). We can plot the contour map alongside a “vector field” of the gradient vectors to see how the gradient relates to the shape of the surface.
Notice that at every point, the gradient arrows point directly “uphill” towards higher contour values. In fact, there is much more structure to explore here, as we will see in the weeks to come.
Now, some of these vectors are hard to make out, so a common tactic is to divide out by the norm of the gradient, ensuring that all the vectors have length 1: \[
\frac{\Gradient{f}}{\Norm{\Gradient{f}}} = \left\langle \frac{f_x}{\sqrt{(f_x)^2+(f_y)^2}}, \frac{f_y}{\sqrt{(f_x)^2+(f_y)^2}} \right\rangle.
\]