# Math Insight

### Directional derivative and gradient examples

#### Example 1

Let $f(x,y) = x^2y.$ (a) Find $\nabla f(3,2)$. (b) Find the derivative of $f$ in the direction of (1,2) at the point (3,2).

Solution: (a) The gradient is just the vector of partial derivatives. The partial derivatives of $f$ at the point $(x,y)=(3,2)$ are: \begin{align*} \pdiff{f}{x}(x,y) & = 2xy & \pdiff{f}{y}(x,y) & = x^2\\ \pdiff{f}{x}(3,2) & = 12 & \pdiff{f}{y}(3,2) & = 9 \end{align*} Therefore, the gradient is \begin{align*} \nabla f (3,2) = 12 \vc{i} + 9 \vc{j} = (12,9). \end{align*}

(b) Let $\vc{u}=u_1\vc{i} + u_2 \vc{j}$ be a unit vector. The directional derivative at (3,2) in the direction of $\vc{u}$ is \begin{align} D_{\vc{u}}f(3,2) &= \nabla f(3,2) \cdot \vc{u}\notag\\ &= (12 \vc{i} + 9 \vc{j}) \cdot (u_1\vc{i} + u_2 \vc{j})\notag\\ &= 12 u_1 + 9 u_2. \label{Dub} \end{align}

To find the directional derivative in the direction of the vector (1,2), we need to find a unit vector in the direction of the vector (1,2). We simply divide by the magnitude of $(1,2)$. \begin{align*} \vc{u} = \frac{(1,2)}{\| (1,2) \|} = \frac{(1,2)}{\sqrt{1^2+2^2}} = \frac{(1,2)}{\sqrt{5}} = (1/\sqrt{5},2/\sqrt{5}). \end{align*} Plugging this expression for $\vc{u} = (u_1, u_2)$ into equation \eqref{Dub} for the directional derivative, and we find that the directional derivative at the point $(3,2)$ in the direction of $(1,2)$ is \begin{align*} D_{\vc{u}}f(3,2) &= 12 u_1 + 9 u_2\\ &= \frac{12}{\sqrt{5}} + \frac{18}{\sqrt{5}} = \frac{30}{\sqrt{5}}. \end{align*}

#### Example 2

For the $f$ of Example 1, find the directional derivative of $f$ at the point (3,2) in the direction of $(2,1)$.

Solution: The unit vector in the direction of $(2,1)$ is \begin{align*} \vc{u} = \frac{(2,1)}{\sqrt{5}} = (2/\sqrt{5},1/\sqrt{5}). \end{align*} Since we are still at the point (3,2), equation \eqref{Dub} is still valid. We plug in our new $\vc{u}$ to obtain \begin{align*} D_{\vc{u}}f(3,2) &= 12 u_1 + 9 u_2\\ &= \frac{24}{\sqrt{5}} + \frac{9}{\sqrt{5}} = \frac{33}{\sqrt{5}} \end{align*}

#### Example 3

For the $f$ of Example 1 at the point (3,2), (a) in which direction is the directional derivative maximal, (b) what is the directional derivative in that direction?

Solution: (a) The gradient points in the direction of the maximal directional derivative. The directional derivative is maximal in the direction of (12,9). (A unit vector in that direction is $\vc{u} = (12,9)/\sqrt{12^2+9^2} = (4/5, 3/5)$.)

(b) The magnitude of the gradient is this maximal directional derivative, which is $\|(12,9)\| = \sqrt{12^2+9^2} = 15$. Hence the directional derivative at the point (3,2) in the direction of (12,9) is 15.

We could double-check by calculating the result using equation \eqref{Dub} and the unit vector $\vc{u} = (4/5,3/5)$. Then we find that \begin{align*} D_{\vc{u}}f(3,2) &= 12 u_1 + 9 u_2\\ &= \frac{48}{5} + \frac{27}{5} = \frac{75}{5}=15, \end{align*} which agrees with our result.

#### Example 4

For the $f$ of Example 1 at the point (3,2), (a) what is the directional derivative in the direction (-3,4) (which is perpendicular to $\nabla f(3,2)$), and (b) what is the directional derivative in the direction (-4,-3) (which is opposite of the direction of $\nabla f(3,2)$)?

Solution: (a) The directional derivative must be zero. (b) The directional derivative must be $-\| \nabla f(3,2)\|$, which is $-15$. (You can verify these by calculating the results directly using equation \eqref{Dub}.)

#### Example 5

Let $f(x,y,z) = xye^{x^2+z^2-5}$. Calculate the gradient of $f$ at the point $(1,3,-2)$ and calculate the directional derivative $D_{\vc{u}}f$ at the point $(1,3,-2)$ in the direction of the vector $\vc{v}=(3,-1,4)$.

Solution: The gradient vector in three-dimensions is similar to the two-dimesional case. To calculate the gradient of $f$ at the point $(1,3,-2)$ we just need to calculate the three partial derivatives of $f$. \begin{align*} \nabla f(x,y,z) &= \left(\pdiff{f}{x},\pdiff{f}{y},\pdiff{f}{z}\right) = \bigl((y+2x^2y)e^{x^2+z^2-5}, xe^{x^2+z^2-5}, 2xyze^{x^2+z^2-5}\bigr)\\ \nabla f(1,3,-2) &= \bigl(3+2(1)^23e^{0}, 1e^{0},2(1)(3)(-2)e^{0}\bigr) = (9,1,-12) \end{align*}

Just as for the above two-dimensional examples, the directional derivative is $D_{\vc{u}}f(x,y,z)=\nabla f(x,y,z) \cdot \vc{u}$ where $\vc{u}$ is a unit vector. To calculate $\vc{u}$ in the direction of $\vc{v}$, we just need to divide by its magnitude. Since $\|\vc{v}\| = \sqrt{3^2+(-1)^2+4^2} = \sqrt{26}$, \begin{align*} \vc{u}=\frac{\vc{v}}{\sqrt{26}} = \left(\frac{3}{\sqrt{26}}, \frac{-1}{\sqrt{26}}, \frac{4}{\sqrt{26}}\right) \end{align*} and \begin{align*} D_{\vc{u}}f(1,3,-2) &= \nabla f(1,3,-2) \cdot \vc{u}\\ &=(9,1,-12) \cdot \left(\frac{3}{\sqrt{26}}, \frac{-1}{\sqrt{26}}, \frac{4}{\sqrt{26}}\right)\\ &= \frac{9\cdot 3- 1-12\cdot 4}{\sqrt{26}}=\frac{-22}{\sqrt{26}}. \end{align*}