In the previous section, we found that if a surface is described by \(z=f(x,y)\), the partial derivatives \(\partial z/\partial x\) and \(\partial z/\partial y\) describe the rate of change of z when we travel parallel to the x axis and parallel to the y axis, respectively. The question now is, what if we travel in a different direction, say along an arbitrary vector \(\vec{v}\)? The answer is that we need to use the **directional derivative**. This is nothing more than a weighted average of the partial derivatives, where the weights are the components of the direction vector (for which we'll need to use a unit vector; this is important).

Find the directional derivative of \(f(x,y)=\dfrac{x^2}{4}+\dfrac{y^2}{9}\) at \((2,3,2)\) in the direction of \(\vec{v}=\langle 3,4 \rangle\).

First, find the unit vector in the direction of \(\vec{v}\): \[\hat{v} = \dfrac{\langle 3,4 \rangle}{5} = \left\langle \dfrac{3}{5},\dfrac{4}{5} \right\rangle\]

Next, find the partial derivatives:

\[\begin{align} f_x &= \dfrac{x}{2} \longrightarrow f_x (2,3) = 1\\ f_y &= \dfrac{2y}{9} \longrightarrow f_y (2,3) = \dfrac{2}{3} \end{align}\]Finally, plug these into the directional derivative formula:

\[D_v = 1\left(\dfrac{3}{5}\right) + \dfrac{2}{3}\left(\dfrac{4}{5}\right) = \ans{\dfrac{17}{15}}\]The interpretation of this is that for every unit you travel in the direction of this vector, z increases by 17/15.

- Find the directional derivative of \(f(x,y) = \dfrac{1}{4}(x^2+2y^2)+2\) at \((3,2)\) in the direction of \(\vec{u}=\langle 1,1 \rangle\) and \(\vec{v}=\langle 1,-\sqrt{3} \rangle\).
- Find the directional derivative of \(f(x,y) = 3x^2+y^3\) at \((3,2)\) in the direction of \(\vec{u}=\langle 5,12 \rangle\).

\[\begin{align}
D_u &= \dfrac{7}{2\sqrt{2}} \approx 2.47\\
D_v &= \dfrac{3}{4}-\sqrt{3} \approx -0.98
\end{align}\]

\(D_u = 18\)

The gradient of \(f(x,y)\), denoted by the "del" operator \(\nabla\), is a vector that points in the direction of steepest ascent on the surface \(z=f(x,y)\). The magnitude of this vector is the slope in that direction (i.e. the largest slope at that point).

Find the gradient of \(f(x,y)=\dfrac{x^2}{4}+\dfrac{y^2}{9}\) at \((2,3,2)\).

A hill has a shape given by \(f(x,y)=1000-0.01x^2-0.02y^2\).

- In which direction should you travel from \((60,100,764)\) to reach the top the fastest?
- What is the slope in that direction?

- Find the gradient: \[\begin{align} \nabla f(x,y) &= -0.02x \hat{\imath} -0.04y \hat{\jmath}\\ \nabla f(60,100) &= -1.2 \hat{\imath} - 4 \hat{\jmath} \end{align}\] Thus, to reach the top the fastest, you should travel in the direction of \(\ans{\langle -1.2,-4 \rangle}\).
- The slope in that direction is the magnitude of the gradient: \[\begin{align} |\nabla f(60,100)| = \sqrt{1.2^2+4^2} = \ans{4.18} \end{align}\]

Note that if you traveled in the opposite direction (\(\langle 1.2,4 \rangle\)), the slope would be \(-4.18\).

\(\nabla f(x,y)\) points to the steepest ascent, \(-\nabla f(x,y)\) points to the steepest descent, and the directional derivative is zero in any direction orthogonal to \(\nabla f(x,y)\).

For instance, using the hill from the previous example, if you travel in the direction of \(\langle -4,-1.2 \rangle\) from \((60,100,764)\), you'll keep the same elevation.

Consider the function \(f(x,y)=3x^2-2y^2\).

- Compute \(\nabla f(x,y)\) and \(\nabla f(2,3)\).
- Consider the unit vector \(\hat{u} = \langle \cos \theta, \sin \theta \rangle\). At \((2,3)\), for what values of \(\theta\) between \(0\) and \(2\pi\) does the directional derivative have its maximum and minimum values?

- Find the gradient: \[\ans{\begin{align} \nabla f(x,y) &= 6x \hat{\imath} - 4y \hat{\jmath}\\ \nabla f(2,3) &= 12 \hat{\imath} - 12 \hat{\jmath} \end{align}}\]
- Find the directional derivative in the direction of \(\hat{u}\): \[D_u\ f(x,y) = \nabla f(x,y) \cdot \hat{u} \longrightarrow D_u\ f(2,3) = 12\cos \theta - 12\sin \theta\] To find the maximum and minimum values for this, take its derivative with respect to \(\theta\) and set the derivative to 0: \[D'_u\ f(2,3) = -12\sin\theta - 12\cos\theta = 0 \longrightarrow \sin\theta = -\cos\theta \longrightarrow \ans{\theta = \dfrac{3\pi}{4}, \dfrac{7\pi}{4}}\] Note that the slope is zero if \(\theta = \dfrac{\pi}{4}, \dfrac{5\pi}{4}\).

The gradient of a function of three variables is similar, with a third component: \(f_z (x,y,z) \hat{k}\).

Consider the function \(f(x,y,z)=x^2+2y^2+4z^2-1\).

- Find the gradient of \(f\) at \((2,0,0)\).
- Find the directional derivative of \(f\) at \((2,0,0)\) in the direction of \(\hat{u} = \left\langle \dfrac{1}{\sqrt{3}},\dfrac{1}{\sqrt{3}},\dfrac{1}{\sqrt{3}} \right\rangle\).

- Find the gradient: \[\begin{align} \nabla f(x,y,z) &= f_x (x,y,z) \hat{\imath} + f_y (x,y,z) \hat{\jmath} + f_z (x,y,z) \hat{k}\\ &= 2x \hat{\imath} + 4y \hat{\jmath} + 8z \hat{k}\\ \nabla f(2,0,0) &= 4 \hat{\imath} = \ans{\langle 4,0,0 \rangle} \end{align}\]
- Find the directional derivative in the direction of \(\hat{u}\): \[D_u\ f(2,0,0) = \nabla f(2,0,0) \cdot \left\langle \dfrac{1}{\sqrt{3}},\dfrac{1}{\sqrt{3}},\dfrac{1}{\sqrt{3}} \right\rangle = \ans{\dfrac{4\sqrt{3}}{3}}\]

- Find the gradient of \(f(x,y)=4x^2-2xy+y^2\).
- Find the gradient of \(f(x,y)=\sqrt{12-4x^2-y^2}\).
- Find the gradient of \(f(x,y)=xe^{2xy}\).
- Find the unit vector that gives the direction of steepest ascent for the surface \(z=x^2+4xy-y^2\) at \((2,1)\).

\(\nabla f(x,y) = \langle 8x-2y , -2x+2y \rangle\)

\(\nabla f(x,y) = \dfrac{1}{2\sqrt{12-4x^2-y^2}} \left\langle -8x , -2y \right\rangle\)

\(\nabla f(x,y) = \left\langle e^{2xy}+2xye^{2xy} , 2x^2e^{2xy} \right\rangle\)

\(\vec{u} = \nabla f(2,1) = \langle 8,6 \rangle \longrightarrow \hat{u} = \left\langle \dfrac{4}{5},\dfrac{3}{5} \right\rangle\)