Skip to main content

Directional derivatives

Imagine navigating a hilly landscape, searching for the steepest ascent or smoothest descent—this is the essence of directional derivatives. These mathematical tools are vital in meteorology for predicting temperature changes along wind paths, in finance for analysing portfolio shifts, and in machine learning for optimising algorithms. Use this resource to learn how to calculate directional derivatives.

This concept combines your understanding of vectors and calculus. Before you read any further, make sure that you are confident with differentiation.

Remember that the partial derivative of a function gives us the gradient or rate of change of the function along each axis. For example, let's consider a function with two variables: \(z=f(x,y)\).

  • For the rate of change of the function \(f\) with respect to \(x\), we find \(\dfrac{\partial f}{\partial x}\). This is the gradient of the graph as we move in the \(x\) direction.
  • For the rate of change of the function \(f\) with respect to \(y\), we find \(\dfrac{\partial f}{\partial y}\). This is the gradient of the graph as we move in the \(y\) direction.

Directional derivatives build on this and allow us to find the rate at which a function changes as we move in any direction defined by a vector.

Imagine you're hiking on a mountain, and the landscape is a complex surface. The directional derivative is like asking, "If I walk in a specific direction, how steep will the path be?"

A graph showing x, y and z axes in 3D space. A grey rectangle is used to show the x y plane. A section of a mountain terrain is shown on the x y plane. The equation for the surface of the mountain terrain is defined by function g. A red dot is shown to represent a point on the surface. From the dot is a vector that extends away from the surface.

Just as the steepness of your path changes depending on the direction you choose to walk (uphill, downhill, or along the side of the mountain), the directional derivative measures how steep or fast a function changes in a particular direction at a given point.

  • If the directional derivative is positive, the path goes uphill.
  • If the directional derivative is negative, the path goes downhill.
  • If the directional derivative is \(0\), the path is flat in that direction.

Finding the directional derivative

You can find the directional derivative of a function containing two variables \(f(x,y)\) or three variables \(g(x,y,z)\) at a point and in a given direction.

The directional derivative of function \(f\) in the direction of a vector \(\vec{u}\) is denoted by \(D_{u}\) and is given by:

\[D_{u} = \nabla f\cdot\hat{u}\]
where \(\nabla f\) ("grad \(f\)") is the gradient of the function \(f\) in the direction of the vector \(\vec{u}\) and \(\hat{u}\) is a unit vector in the direction of \(\vec{u}\).

\(\nabla f\) is found by partial differentiation according to the following:

\[\nabla f = \frac{\partial f}{\partial x}\hat{i} + \frac{\partial f}{\partial y}\hat{j} + \frac{\partial f}{\partial z}\hat{k}\]

And of course, the unit vector for vector \(\vec{u}\) is just the vector divided by its magnitude.

Let's look at the mountain example again.

A graph showing x, y and z axes in 3D space. A grey rectangle is used to show the x y plane. A section of a mountain terrain is shown on the x y plane. The equation for the surface of the mountain terrain is defined by function g. A red dot is shown to represent a point on the surface. The tangent at the point is drawn as well as the gradient vector, labelled nabla f, which is perpendicular to the tangent. From the dot is a direction vector that extends away from the surface. Its unit vector is named u hat. The gradient vector is projected onto vector u and this is given by the equation D u equals gradient f dot unit vector u.

Imagine you are standing at the point indicated by the red dot in the figure.

  • The tangent of the slope at that point is shown by the solid line.
  • The gradient \(\nabla f\) is perpendicular to the tangent.
  • We want to know how steep the path is in the direction of vector \(\vec{u}\); this is given by \(D_{u}\).
  • \(D_{u}\) is the projection of the gradient onto the direction vector.

Since the directional derivative relies on a dot product where \(\vec{a}\cdot\vec{b}=\left|\vec{a}\right|\left|\vec{b}\right|\cos\theta\):

  • \(D_{u}\) will be maximum when \(\vec{u}\) and \(\nabla f\) are in the same direction, i.e. when \(\theta=0\) and \(\cos\theta=1\).
  • \(D_{u}\) will have its greatest negative value when \(\vec{u}\) and \(\nabla f\) are in opposite directions, i.e. when \(\theta=\pi\).
  • \(D_{u}\) will be \(0\) when \(\vec{u}\) and \(\nabla f\) are at right angles, i.e. perpendicular to each other or when \(\theta=\dfrac{\pi}{2}\).

Example 1 – finding the directional derivative

Find the directional derivative of \(f(x,y)=x^{2}+y^{2}\) at the point \((2,3)\) in the direction of the vector \(\vec{u}=4\hat{i}-3\hat{j}\).

The first step is to find the vector \(\nabla f\) at the point \(x=2\), \(y=3\).
\[\begin{align*} \nabla f & = \frac{\partial f}{\partial x}\hat{i} +\frac{\partial f}{\partial y}\hat{j}\\
& = \frac{\partial}{\partial x}(x^{2}+y^{2})\hat{i} + \frac{\partial}{\partial y}(x^{2}+y^{2})\hat{j}\\
& = 2x\hat{i}+2y\hat{j}\\
& = 2(2)\hat{i}+2(3)\hat{j}\\
& = 4\hat{i}+6\hat{j}
\end{align*}\]

Next, we need to find the dot product of \(\nabla f\) and \(\hat{u}\), the unit vector in the direction of \(\vec{u}\). Let's find the \(\hat{u}\) first.

\[\begin{align*} \hat{u} & = \frac{\vec{u}}{\left| \vec{u} \right|}\\
& = \frac{4\hat{i}-3\hat{j}}{\sqrt{4^{2}+3^{2}}}\\
& = \frac{4\hat{i}-3\hat{j}}{5}\\
& = \frac{1}{5}(4\hat{i}-3\hat{j})\quad\textrm{or}\quad\frac{4}{5}\hat{i}-\frac{3}{5}\hat{j}
\end{align*}\]

Now, we can substitute \(\nabla f\) and \(\hat{u}\) into the formula to find the directional derivative.
\[\begin{align*} D_{u} & = (4\hat{i}+6\hat{j})\cdot(\frac{4}{5}\hat{i}-\frac{3}{5}\hat{j})\\
& = (4\times\frac{4}{5})+(6\times-\frac{3}{5})\\
& = \frac{16}{5}-\frac{18}{5}\\
& =-\frac{2}{5}
\end{align*}\]

If \(f(x,y,z)=x^{2}+y^{2}+xyz\), find a unit vector \(\hat{u}\) such that the rate of change of \(f\) at \((2,3,-1)\) in the direction of \(\vec{u}\) is maximum.

We have been given the equation for the function and the directional derivative. The question is asking for the unit vector \(\hat{u}\).

The formula that connects them is \(D_{u}=\nabla f\cdot \hat{u}\), so we should find \(\nabla f\) first for \(x=2\), \(y=3\) and \(z=-1\).

\[\begin{align*}
\nabla f & = \frac{\partial f}{\partial x}\hat{i}+\frac{\partial f}{\partial y}\hat{j}+\frac{\partial f}{\partial z}\hat{k}\\
& = \frac{\partial}{\partial x}(x^{2}+y^{2}+xyz)\hat{i} + \frac{\partial}{\partial y}(x^{2}+y^{2}+xyz)\hat{j} + \frac{\partial}{\partial z}(x^{2}+y^{2}+xyz)\hat{k}\\
& = (2x+yz)\hat{i} + (2y+xz)\hat{j} + (xy)\hat{k}\\
& = (2(2)+(3)(-1))\hat{i} + (2(3)+(2)(-1))\hat{j} + (2)(3)\hat{k}\\
& = (4-3)\hat{i} + (6-2)\hat{j} + 6\hat{k}\\
& = \hat{i} + 4\hat{j} + 6\hat{k}
\end{align*} \]

For the directional derivative to be maximum, \(\vec{u}=\nabla f\).
\[\vec{u} = \hat{i} + 4\hat{j} + 6\hat{k}\]

Now, we can find \(\hat{u}\).
\[\begin{align*} \hat{u} & = \frac{\vec{u}}{\left| \vec{u} \right|}\\
& = \frac{\hat{i} + 4\hat{j} + 6\hat{k}}{\sqrt{1^{2}+4^{2}+6^{2}}}\\
& = \frac{\hat{i} + 4\hat{j} + 6\hat{k}}{\sqrt{53}}\\
& = \frac{1}{\sqrt{53}}(\hat{i} + 4\hat{j} + 6\hat{k})
\end{align*}\]

Exercise – finding the directional derivative

  1. Find the directional derivative of the given function \(f\) at the given point \((x,y)\) in the direction of the indicated vector \(\vec{u}\).
    1. \(f(x,y)=xy^{2}\) at point \((3,2)\) and in the direction of \(\vec{u}=4\hat{i}+3\hat{j}\)
    2. \(f(x,y)=e^{xy}\) at point \((0,2)\) and in the direction of \(\vec{u}=\hat{i}\)
    3. \(f(x,y,z)=x^{2}y^{3}z\) at point \((2,-1,3)\) and in the direction of \(\vec{u}=\hat{i}-2\hat{j}-2\hat{k}\)
  2. Find the unit vector in the direction in which \(f\) increases most rapidly at \(P\left(1,\dfrac{\pi}{2}\right)\) for \(f(x,y)=x^{2}+\cos(xy)\).

    1. \(\dfrac{52}{5}\)
    2. \(2\)
    3. \(-\dfrac{76}{3}\)
  1. \(\hat{u}=0.394\hat{i}-0.919\hat{j}\)

Images on this page by RMIT, licensed under CC BY-NC 4.0


Further resources

Differentiation

Calculating directional derivatives requires you to be competent at differentiation. Use this resource to refresh your understanding.