# 13.6: Directional Derivatives and the Gradient

\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

In Partial Derivatives, we introduced the partial derivative. A function \(z=f(x,y)\) has two partial derivatives: \(∂z/∂x\) and \(∂z/∂y\). These derivatives correspond to each of the independent variables and can be interpreted as instantaneous rates of change (that is, as slopes of a tangent line). For example, \(∂z/∂x\) represents the slope of a tangent line passing through a given point on the surface defined by \(z=f(x,y),\) assuming the tangent line is parallel to the *x-axis*. Similarly, \(∂z/∂y\) represents the slope of the tangent line parallel to the **y-axis.** Now we consider the possibility of a tangent line parallel to neither axis.

### Directional Derivatives

We start with the graph of a surface defined by the equation \(z=f(x,y)\). Given a point \((a,b)\) in the domain of \(f\), we choose a direction to travel from that point. We measure the direction using an angle \(θ\), which is measured counterclockwise in the *x, y*-plane, starting at zero from the positive *x*-axis (Figure \(\PageIndex{1}\)). The distance we travel is \(h\) and the direction we travel is given by the unit vector \(u=(\cos θ)i+(\sin θ)j.\) Therefore, the \(z\)-coordinate of the second point on the graph is given by \(z=f(a+h\cos θ,b+h\sin θ).\)

**Figure \(\PageIndex{1}\):** Finding the directional derivative at a point on the graph of \(z=f(x,y)\). The slope of the black arrow on the graph indicates the value of the directional derivative at that point.

We can calculate the slope of the secant line by dividing the difference in **z-values** by the length of the line segment connecting the two points in the domain. The length of the line segment is \(h\). Therefore, the slope of the secant line is

\[m_{sec}=\dfrac{f(a+h\cos θ,b+h\sin θ)−f(a,b)}{h}\]

To find the slope of the tangent line in the same direction, we take the limit as \(h\) approaches zero.

Definition: Directional Derivatives

Suppose \(z=f(x,y)\) is a function of two variables with a domain of \(D\). Let \((a,b)∈D\) and define \(u=cosθi+sinθj\). Then the directional derivative of \(f\) in the direction of \(u\) is given by

\[D_uf(a,b)=\lim_{h→0}\dfrac{f(a+h \cos θ,b+h\sin θ)−f(a,b)}{h} \label{DD}\]

provided the limit exists.

Equation provides a formal definition of the directional derivative that can be used in many cases to calculate a directional derivative.

Example \(\PageIndex{1}\): Finding a Directional Derivative from the Definition

Let \(θ=\arccos(3/5).\) Find the directional derivative \(D_uf(x,y)\) of \(f(x,y)=x^2−xy+3y^2\) in the direction of \(u=(\cos θ)i+(\sin θ)j\). What is \(D_uf(−1,2)\)?

**Solution**

First of all, since \(\cos θ=3/5\) and \(θ\) is acute, this implies

\[\sin θ=\sqrt{1−\left(\dfrac{3}{5}\right)^2}=\sqrt{\dfrac{16}{25}}=\dfrac{4}{5}. \nonumber\]

Using \(f(x,y)=x^2−xy+3y^2,\) we first calculate \(f(x+h\cos θ,y+h\sin θ)\):

\[\begin{align*} f(x+h\cos θ,y+h\sin θ)&=(x+h\cos θ)^2−(x+h\cos θ)(y+h\sin θ)+3(y+h\sin θ)^2 \\&=x^2+2xh\cos θ+h^2\cos^2 θ−xy−xh\sin θ−yh\cos θ−h^2\sin θ\cos θ+3y^2+6yh\sin θ+3h^2\sin^2 θ \\ &=x^2+2xh(\dfrac{3}{5})+\dfrac{9h^2}{25}−xy−\dfrac{4xh}{5}−\dfrac{3yh}{5}−\dfrac{12h^2}{25}+3y^2+6yh(\dfrac{4}{5})+3h^2(\dfrac{16}{25})\\&=x^2−xy+3y^2+\dfrac{2xh}{5}+\dfrac{9h^2}{5}+\dfrac{21yh}{5}. \end{align*}\]

We substitute this expression into Equation:

\[\begin{align*} D_uf(a,b)&=\lim_{h→0}\dfrac{f(a+h\cos θ,b+h\sin θ)−f(a,b)}{h}\\ &=\lim_{h→0}\dfrac{(x^2−xy+3y^2+\dfrac{2xh}{5}+\dfrac{9h^2}{5}+\dfrac{21yh}{5})−(x^2−xy+3y^2)}{h}\\ &=\lim_{h→0}\dfrac{\dfrac{2xh}{5}+\dfrac{9h^2}{5}+\dfrac{21yh}{5}}{h}\\ &=\lim_{h→0}\dfrac{2x}{5}+\dfrac{9h}{5}+\dfrac{21y}{5}\\&=\dfrac{2x+21y}{5}. \end{align*}\]

To calculate \(D_uf(−1,2),\) we substitute \(x=−1\) and \(y=2\) into this answer (Figure \(\PageIndex{2}\)):

\[ D_uf(−1,2)=\dfrac{2(−1)+21(2)}{5}=\dfrac{−2+42}{5}=8. \nonumber\]

**Figure \(\PageIndex{2}\): **Finding the directional derivative in a given direction \(u\) at a given point on a surface. The plane is tangent to the surface at the given point \((−1,2,15).\)

Another approach to calculating a directional derivative involves partial derivatives, as outlined in the following theorem.

Directional Derivative of a Function of Two Variables

Let \(z=f(x,y)\) be a function of two variables \(x\) and \(y\), and assume that \(f_x\) and \(f_y\) exist. Then the directional derivative of \(f\) in the direction of \(u=\cos θi+\sin θj\) is given by

\[D_uf(x,y)=f_x(x,y)\cos θ+f_y(x,y)\sin θ. \label{DD2v}\]

Proof

Equation \ref{DD} states that the directional derivative of \(f\) in the direction of \(u=\cos θi+\sin θj\) is given by

\[D_uf(a,b)=\lim_{t→0}\dfrac{f(a+t \cos θ,b+t\sin θ)−f(a,b)}{t}.\]

Let \(x=a+t\cos θ\) and \(y=b+t\sin θ,\) and define \(g(t)=f(x,y)\). Since \(f_x\) and \(f_y\) both exist, we can use the chain rule for functions of two variables to calculate \(g′(t)\):

\[g′(t)=\dfrac{∂f}{∂x}\dfrac{dx}{dt}+\dfrac{∂f}{∂y}\dfrac{dy}{dt}=f_x(x,y)\cos θ+f_y(x,y)\sin θ.\]

If \(t=0,\) then \(x=x_0\) and \(y=y_0,\) so

\[g′(0)=f_x(x_0,y_0)\cos θ+f_y(x_0,y_0)\sin θ\]

By the definition of \(g′(t),\) it is also true that

\[g′(0)=\lim_{t→0}\dfrac{g(t)−g(0)}{t}=\lim_{t→0}\dfrac{f(x_0+t\cos θ,y_0+t\sin θ)−f(x_0,y_0)}{t}.\]

Therefore, \(D_uf(x_0,y_0)=f_x(x,y)\cos θ+f_y(x,y)\sin θ.\)

□

Example \(\PageIndex{2}\): Finding a Directional Derivative: Alternative Method

Let \(θ=\arccos (3/5).\) Find the directional derivative \(D_uf(x,y)\) of \(f(x,y)=x^2−xy+3y^2\) in the direction of \(u=(\cos θ)i+(\sin θ)j\). What is \(D_uf(−1,2)\)?

**Solution**

First, we must calculate the partial derivatives of \(f\):

\[\begin{align*}f_x&=2x−y \\ f_y&=−x+6y, \end{align*}\]

Then we use Equation with \(θ=\arccos (3/5)\):

\[\begin{align*} D_uf(x,y)&=f_x(x,y)\cos θ+f_y(x,y)\sin θ \\&=(2x−y)\dfrac{3}{5}+(−x+6y)\dfrac{4}{5} \\ &=\dfrac{6x}{5}−\dfrac{3y}{5}−\dfrac{4x}{5}+\dfrac{24y}{5}\\&=\dfrac{2x+21y}{5}. \end{align*}\]

To calculate \(D_uf(−1,2),\) let \(x=−1\) and \(y=2\):

\[D_uf(−1,2)=\dfrac{2(−1)+21(2)}{5}=\dfrac{−2+42}{5}=8.\]

This is the same answer obtained in Example \(\PageIndex{1}\).

Exercise \(\PageIndex{1}\):

Find the directional derivative \(D_uf(x,y)\) of \(f(x,y)=3x^2y−4xy^3+3y^2−4x\) in the direction of \(u=(\cos \dfrac{π}{3})i+(\sin \dfrac{π}{3})j\) using Equation. What is \(D_u f(3,4)\)?

**Hint**-
Calculate the partial derivatives and determine the value of \(θ\).

**Answer**-
\(D_uf(x,y)=\dfrac{(6xy−4y^3−4)(1)}{2}+\dfrac{(3x^2−12xy^2+6y)\sqrt{3}}{2}\)

\(D_uf(3,4)=\dfrac{72−256−4}{2}+\dfrac{(27−576+24)\sqrt{3}}{2}=−94−\dfrac{525\sqrt{3}}{2}\)

If the vector that is given for the direction of the derivative is not a unit vector, then it is only necessary to divide by the norm of the vector. For example, if we wished to find the directional derivative of the function in Example in the direction of the vector \(⟨−5,12⟩\), we would first divide by its magnitude to get \(u\). This gives us \(u=⟨−(5/13),12/13⟩.\) Then

\[ \begin{align*} D_uf(x,y)&= ∇f(x,y)⋅u \\ &=−\dfrac{5}{13}(2x−y)+\dfrac{12}{13}(−x+6y) \\ &=−\dfrac{22}{13}x+\dfrac{17}{13}y \end{align*}\]

## Gradient

The right-hand side of Equation is equal to \(f_x(x,y)\cos θ+f_y(x,y)\sin θ,\) which can be written as the dot product of two vectors. Define the first vector as \(∇f(x,y)=f_x(x,y)i+f_y(x,y)j\) and the second vector as \(u=(\cos θ)i+(\sin θ)j.\) Then the right-hand side of the equation can be written as the dot product of these two vectors:

\[D_uf(x,y)=∇f(x,y)⋅u.\]

The first vector in Equation has a special name: the gradient of the function \(f\). he symbol \(∇\) is called nabla and the vector \(∇f\) is read “**del** \(f\).”

Definition: The Gradient

Let \(z=f(x,y)\) be a function of \(x\) and \(y\) such that \(f_x\) and \(f_y\) exist. The vector \(∇f(x,y)\) is called the **gradient** of \(f\) and is defined as

\[∇f(x,y)=f_x(x,y)i+f_y(x,y)j. \label{grad}\]

The vector \(∇f(x,y)\) is also written as “**grad **\(f\).”

Example \(\PageIndex{3}\): Finding Gradients

Find the gradient \(∇f(x,y)\) of each of the following functions:

- \(f(x,y)=x^2−xy+3y^2\)
- \(f(x,y)=\sin 3 x \cos 3y\)

**Solution**

For both parts a. and b., we first calculate the partial derivatives \(f_x\) and \(f_y\), then use Equation \ref{grad}.

a. \[\begin{align*} f_x(x,y)&=2x−y\; \text{and}\; f_y(x,y)=−x+6y,\; \text{so} \\ ∇f(x,y)&=f_x(x,y)i+f_y(x,y)j\\&=(2x−y)i+(−x+6y)j.\end{align*}\]

b. \[\begin{align*} f_x(x,y)&=3\cos 3x \cos 3y \; \text{and} \; f_y(x,y)=−3\sin 3x \sin 3y, \text{so} \\ ∇f(x,y)&=f_x(x,y)i+f_y(x,y)j \\ &=(3\cos 3x \cos 3y)i−(3\sin 3x \sin 3y)j. \end{align*}\]

Exercise \(\PageIndex{2}\)

Find the gradient \(∇f(x,y)\) of \(f(x,y)=(x^2−3y^2)/(2x+y).\)

**Hint**-
Calculate the partial derivatives, then use Equation \ref{grad}.

**Answer**-
\(∇f(x,y)=\dfrac{2x^2+2xy+6y^2}{(2x+y)^2}i−\dfrac{x^2+12xy+3y^2}{(2x+y)^2}j\)

The gradient has some important properties. We have already seen one formula that uses the gradient: the formula for the directional derivative. Recall from The Dot Product that if the angle between two vectors \(a\) and \(b\) is \(φ\), then \(a⋅b=‖a‖∥b∥\cos φ.\) Therefore, if the angle between \(∇f(x_0,y_0)\) and \(u=(cosθ)i+(sinθ)j \text{is} φ,\) we have

\[D_uf(x_0,y_0)=∇f(x_0,y_0)⋅u=∥∇f(x_0,y_0)∥‖u‖\cos φ=∥∇f(x_0,y_0)∥\cos φ.\]

The \(‖u‖\) disappears because \(u\) is a unit vector. Therefore, the directional derivative is equal to the magnitude of the gradient evaluated at \((x_0,y_0)\) multiplied by \(\cos φ\). Recall that \(\cos φ\) ranges from \(−1\) to \(1\). If \(φ=0,\) then \(\cos φ=1\) and \(∇f(x_0,y_0)\) and \(u\) both point in the same direction. If \(φ=π\), then \(\cos φ=−1\) and \(∇f(x_0,y_0)\) and u point in opposite directions. In the first case, the value of \(D_uf(x_0,y_0)\) is maximized; in the second case, the value of \(D_uf(x_0,y_0)\) is minimized. If \(∇f(x_0,y_0)=0\), then

\[ D_uf(x_0,y_0)=∇f(x_0,y_0)⋅u=0\]

for any vector \(u\). These three cases are outlined in the following theorem.

Properties of the Gradient

Suppose the function \(z=f(x,y)\) is differentiable at \((x_0,y_0)\) (Figure \(\PageIndex{3}\)).

- If \(∇f(x_0,y_0)=0,\) then \(D_uf(x_0,y_0)=0\) for any unit vector \(u\).
- If \(∇f(x_0,y_0)≠0\), then \(D_uf(x_0,y_0)\) is maximized when u points in the same direction as \(∇f(x_0,y_0)\). The maximum value of \(D_uf(x_0,y_0)\) is \(∥∇f(x_0,y_0)∥.\)
- If \(∇f(x_0,y_0)≠0,\) then \(D_uf(x_0,y_0)\) is minimized when u points in the opposite direction from \(∇f(x_0,y_0)\). The minimum value of \(D_uf(x_0,y_0)\) is \(−∥∇f(x_0,y_0)∥.\)

**Figure \(\PageIndex{3}\): **The gradient indicates the maximum and minimum values of the directional derivative at a point.

Example \(\PageIndex{4}\): Finding a Maximum Directional Derivative

Find the direction for which the directional derivative of \(f(x,y)=3x^2−4xy+2y^2\) at \((−2,3)\) is a maximum. What is the maximum value?

**Solution:**

The maximum value of the directional derivative occurs when \(∇f\) and the unit vector point in the same direction. Therefore, we start by calculating \(∇f(x,y\)):

\[f_x(x,y)=6x−4y \; \text{and}\; f_y(x,y)=−4x+4y \nonumber\]

so

\[∇f(x,y)=f_x(x,y)i+f_y(x,y)j=(6x−4y)i+(−4x+4y)j. \nonumber\]

Next, we evaluate the gradient at \((−2,3)\):

\[∇f(−2,3)=(6(−2)−4(3))i+(−4(−2)+4(3))j=−24i+20j. \nonumber\]

We need to find a unit vector that points in the same direction as \(∇f(−2,3),\) so the next step is to divide \(∇f(−2,3)\) by its magnitude, which is \(\sqrt{(−24)^2+(20)^2}=\sqrt{976}=4\sqrt{61}−\). Therefore,

\[\dfrac{∇f(−2,3)}{∥∇f(−2,3)∥}=\dfrac{−24}{4\sqrt{61}}i+\dfrac{20}{4\sqrt{61}}j=−\dfrac{6\sqrt{61}}{61}i+\dfrac{5\sqrt{61}}{61}j. \nonumber\]

This is the unit vector that points in the same direction as \(∇f(−2,3).\) To find the angle corresponding to this unit vector, we solve the equations

\[\cos θ=\dfrac{−6\sqrt{61}}{61}\; \text{and}\; \sin θ=\dfrac{5\sqrt{61}}{61} \nonumber\]

for \(θ\). Since cosine is negative and sine is positive, the angle must be in the second quadrant. Therefore, \(θ=π−\arcsin((5\sqrt{61})/61)≈2.45rad.\)

The maximum value of the directional derivative at \((−2,3)\) is \(∥∇f(−2,3)∥=4\sqrt{61}\) (see the Figure \(\PageIndex{4}\)).

**Figure \(\PageIndex{4}\): **The maximum value of the directional derivative at \((−2,3)\) is in the direction of the gradient.

Exercise \(\PageIndex{3}\):

Find the direction for which the directional derivative of \(g(x,y)=4x−xy+2y^2\) at \((−2,3)\) is a maximum. What is the maximum value?

**Hint**-
Evaluate the gradient of \(g\) at point \((−2,3)\).

**Answer**-
The gradient of \(g\) at \((−2,3)\) is \(∇g(−2,3)=i+14j\). The unit vector that points in the same direction as \(∇g(−2,3)\) is \(\dfrac{∇g(−2,3)}{∥∇g(−2,3)∥}=\dfrac{1}{\sqrt{197}}i+\dfrac{14}{\sqrt{197}}j=\dfrac{\sqrt{197}}{197}i+\dfrac{14\sqrt{197}}{197}j,\) which gives an angle of \(θ=\arcsin ((14\sqrt{197})/197)≈1.499rad\).

The maximum value of the directional derivative is \(∥∇g(−2,3)∥=\sqrt{197}\).

Figure \(\PageIndex{5}\) shows a portion of the graph of the function \(f(x,y)=3+\sin x \sin y\). Given a point \((a,b)\) in the domain of \(f\), the maximum value of the gradient at that point is given by \(∥∇f(a,b)∥\). This would equal the rate of greatest ascent if the surface represented a topographical map. If we went in the opposite direction, it would be the rate of greatest descent.

**Figure \(\PageIndex{5}\):** A typical surface in \(R^3\). Given a point on the surface, the directional derivative can be calculated using the gradient.

When using a topographical map, the steepest slope is always in the direction where the contour lines are closest together (Figure \(\PageIndex{6}\)). This is analogous to the contour map of a function, assuming the level curves are obtained for equally spaced values throughout the range of that function.

* Figure \(\PageIndex{6}\): Contour map for the function \(f(x,y)=x^2−y^2\) using level values between \(−5\) and \(5\)*.

## Gradients and Level Curves

Recall that if a curve is defined parametrically by the function pair \((x(t),y(t)),\) then the vector \(x′(t)i+y′(t)j\) is tangent to the curve for every value of \(t\) in the domain. Now let’s assume \(z=f(x,y)\) is a differentiable function of \(x\) and \(y\), and \((x_0,y_0)\) is in its domain. Let’s suppose further that \(x_0=x(t_0)\) and \(y_0=y(t_0)\) for some value of \(t\), and consider the level curve \(f(x,y)=k\). Define \(g(t)=f(x(t),y(t))\) and calculate \(g′(t)\) on the level curve. By the chain Rule,

\[g′(t)=f_x(x(t),y(t))x′(t)+f_y(x(t),y(t))y′(t).\]

But \(g′(t)=0\) because \(g(t)=k\) for all \(t\). Therefore, on the one hand,

\[f_x(x(t),y(t))x′(t)+f_y(x(t),y(t))y′(t)=0;\]

on the other hand,

\[f_x(x(t),y(t))x′(t)+f_y(x(t),y(t))y′(t)=∇f(x,y)⋅⟨x′(t),y′(t)⟩.\]

Therefore,

\[∇f(x,y)⋅⟨x′(t),y′(t)⟩=0.\]

Thus, the dot product of these vectors is equal to zero, which implies they are orthogonal. However, the second vector is tangent to the level curve, which implies the gradient must be normal to the level curve, which gives rise to the following theorem.

Gradient Is Normal to the Level Curve

Suppose the function \(z=f(x,y)\) has continuous first-order partial derivatives in an open disk centered at a point \((x_0,y_0)\). If \(∇f(x_0,y_0)≠0\), then \(∇f(x_0,y_0)\) is normal to the level curve of \(f\) at \((x_0,y_0).\)

We can use this theorem to find tangent and normal vectors to level curves of a function.

Example \(\PageIndex{5}\): Finding Tangents to Level Curves

For the function \(f(x,y)=2x^2−3xy+8y^2+2x−4y+4,\) find a tangent vector to the level curve at point \((−2,1)\). Graph the level curve corresponding to \(f(x,y)=18\) and draw in \(∇f(−2,1)\) and a tangent vector.

**Solution:**

First, we must calculate \(∇f(x,y):\)

\[f_x(x,y)=4x−3y+2 \;\text{and}\; f_y=−3x+16y−4 \;\text{so}\; ∇f(x,y)=(4x−3y+2)i+(−3x+16y−4)j.\]

Next, we evaluate \(∇f(x,y)\) at \((−2,1):\)

\[∇f(−2,1)=(4(−2)−3(1)+2)i+(−3(−2)+16(1)−4)j=−9i+18j.\]

This vector is orthogonal to the curve at point \((−2,1)\). We can obtain a tangent vector by reversing the components and multiplying either one by \(−1\). Thus, for example, \(−18i−9j\) is a tangent vector (see the following graph).

**Figure \(\PageIndex{7}\): **Tangent and normal vectors to \(2x^2−3xy+8y^2+2x−4y+4=18\) at point \((−2,1)\).

Exercise \(\PageIndex{4}\):

For the function \(f(x,y)=x^2−2xy+5y^2+3x−2y+4\), find the tangent to the level curve at point \((1,1)\). Draw the graph of the level curve corresponding to \(f(x,y)=8\) and draw \(∇f(1,1)\) and a tangent vector.

**Hint**-
Calculate the gradient at point \((1,1)\).

**Answer**-
\(∇f(x,y)=(2x−2y+3)i+(−2x+10y−2)j\)

\(∇f(1,1)=3i+6j\)

Tangent vector: \(6i−3j\) or \(−6i+3j\)

### Three-Dimensional Gradients and Directional Derivatives

The definition of a gradient can be extended to functions of more than two variables.

Definition: Gradients in 3D

Let \(w=f(x, y, z)\) be a function of three variables such that \(f_x, \, f_y\),

\[∇f(x,y,z)=f_x(x,y,z)i+f_y(x,y,z)j+f_z(x,y,z)k.\]

\(∇f(x,y,z)\) can also be written as **grad **\(f(x,y,z).\)

Calculating the gradient of a function in three variables is very similar to calculating the gradient of a function in two variables. First, we calculate the partial derivatives \(f_x, \, f_y,\) and \(f_z\), and then we use Equation.

Example \(\PageIndex{6}\): Finding Gradients in Three Dimensions

Find the gradient \(∇f(x,y,z)\) of each of the following functions:

- \(f(x,y)=5x^2−2xy+y^2−4yz+z^2+3xz\)
- \(f(x,y,z)=e^{−2z}\sin 2x \cos 2y\)

**Solution:**

For both parts a. and b., we first calculate the partial derivatives \(f_x,f_y,\) and \(f_z\), then use Equation.

a.

\[\begin{align*} f_z(x,y,z)&=10x−2y+3z,f_y(x,y,z)=−2x+2y−4z \; \text{and} \; f_z(x,y,z)=3x−4y+2z, \text{so} \\ ∇f(x,y,z)&=f_x(x,y,z)i+f_y(x,y,z)j+f_z(x,y,z)k \\ &=(10x−2y+3z)i+(−2x+2y−4z)j+(−4x+3y+2z)k. \end{align*}\]

b.

\[\begin{align*} f_x(x,y,z)&=−2e^{−2z}\cos 2x \cos 2y, f_y(x,y,z)=−2e^{−2z} \sin 2x \sin 2y \; \text{and} \\ f_z(x,y,z)&=−2e^{−2z}\sin 2x \cos 2y, \; \text{so} \\ ∇f(x,y,z)&=f_x(x,y,z)i+f_y(x,y,z)j+f_z(x,y,z)k \\&=(2e^{−2z}\cos 2x \cos 2y)i+(−2e^{−2z})j+(−2e^{−2z}) \\ & =2e^{−2z}(\cos 2x \cos 2y i−\sin 2x \sin 2yj−\sin 2x \cos2yk). \end{align*}\]

Exercise \(\PageIndex{5}\):

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

**Answer**-
\[ ∇f(x,y,z)=\dfrac{2x^2+2xy+6y^2−8xz−2z^2}{(2x+y−4z)^2}i−\dfrac{x^2+12xy+3y^2−24yz+z^2}{(2x+y−4z)^2}j+\dfrac{4x^2−12y^2−4z^2+4xz+2yz}{(2x+y−4z)^2}k\]

The directional derivative can also be generalized to functions of three variables. To determine a direction in three dimensions, a vector with three components is needed. This vector is a unit vector, and the components of the unit vector are called *directional cosines***.** Given a three-dimensional unit vector \(u\) in standard form (i.e., the initial point is at the origin), this vector forms three different angles with the positive \(x−,y−,\) and \(z-\)axes. Let’s call these angles \(α,β,\) and \(γ\). Then the directional cosines are given by \(\cos α,\cos β,\) and \(\cos γ\). These are the components of the unit vector \(u\); since \(u\) is a unit vector, it is true that \(\cos^2 α+\cos^2 β+\cos^2 γ=1.\)

Definition: Directional Derivative of a Function of Three variables

Suppose \(w=f(x,y,z)\) is a function of three variables with a domain of \(D\). Let \((x_0,y_0,z_0)∈D\) and let \(u=\cos αi+\cos βj+\cos γk\) be a unit vector. Then, the directional derivative of \(f\) in the direction of \(u\) is given by

\[D_uf(x_0,y_0,z_0)=\lim_{t→0}\dfrac{f(x_0+t \cos α,y_0+t\cos β,z_0+t\cos γ)−f(x_0,y_0,z_0)}{t}\]

provided the limit exists.

We can calculate the directional derivative of a function of three variables by using the gradient, leading to a formula that is analogous to Equation.

Directional Derivative of a Function of Three Variables

Let \(f(x,y,z)\) be a differentiable function of three variables and let \(u=\cos αi+\cos βj+\cos γk\) be a unit vector. Then, the directional derivative of \(f\) in the direction of \(u\) is given by

\[D_uf(x,y,z)=∇f(x,y,z)⋅u=f_x(x,y,z)\cos α+f_y(x,y,z)\cos β+f_z(x,y,z)\cos γ.\]

The three angles \(α,β,\) and \(γ\) determine the unit vector \(u\). In practice, we can use an arbitrary (nonunit) vector, then divide by its magnitude to obtain a unit vector in the desired direction.

Example \(\PageIndex{7}\): Finding a Directional Derivative in Three Dimensions

Calculate \(D_uf(1,−2,3)\) in the direction of \(v=−i+2j+2k\) for the function

\[ f(x,y,z)=5x^2−2xy+y^2−4yz+z^2+3xz. \nonumber\]

**Solution: **

First, we find the magnitude of \(v\):

\[‖v‖=\sqrt{(−1)^2+(2)^2}=3. \nonumber\]

Therefore, \(\dfrac{v}{‖v‖}=\dfrac{−i+2j+2k}{3}=−\dfrac{1}{3}i+\dfrac{2}{3}j+\dfrac{2}{3}k\) is a unit vector in the direction of \(v\), so \(\cos α=−\dfrac{1}{3},\cos β=\dfrac{2}{3},\) and \(\cos γ=\dfrac{2}{3}\). Next, we calculate the partial derivatives of f:

\[\begin{align*} f_x(x,y,z)& =10x−2y+3z \\ f_y(x,y,z)&=−2x+2y−4z \\ f_z(x,y,z)&=−4y+2z+3x, \end{align*} \]

then substitute them into Equation:

\[\begin{align*} D_uf(x,y,z)&=f_x(x,y,z)\cos α+f_y(x,y,z)\cos β+f_z(x,y,z)\cos γ \\ &=(10x−2y+3z)(−\dfrac{1}{3})+(−2x+2y−4z)(\dfrac{2}{3})+(−4y+2z+3x)(\dfrac{2}{3}) \\ &=−\dfrac{10x}{3}+\dfrac{2y}{3}−\dfrac{3z}{3}−\dfrac{4x}{3}+\dfrac{4y}{3}−\dfrac{8z}{3}−\dfrac{8y}{3}+\dfrac{4z}{3}+\dfrac{6x}{3} \\ &=−\dfrac{8x}{3}−\dfrac{2y}{3}−\dfrac{7z}{3}. \end{align*}\]

Last, to find \(D_uf(1,−2,3),\) we substitute \(x=1,y=−2,\) and \(z=3:\)

\[\begin{align*} D_uf(1,−2,3)&=−\dfrac{8(1)}{3}−\dfrac{2(−2)}{3}−\dfrac{7(3)}{3} \\ &=−\dfrac{8}{3}+\dfrac{4}{3}−\dfrac{21}{3} \\&=−\dfrac{25}{3}. \end{align*}\]

Exercise \(\PageIndex{6}\):

Calculate \(D_uf(x,y,z)\) and \(D_uf(0,−2,5)\) in the direction of \(v=−3i+12j−4k\) for the function

\[f(x,y,z)=3x^2+xy−2y^2+4yz−z^2+2xz.\nonumber \]

**Hint**-
First, divide \(v\) by its magnitude, calculate the partial derivatives of \(f\), then use Equation.

**Answer**-
\(D_uf(x,y,z)=−\dfrac{3}{13}(6x+y+2z)+\dfrac{12}{13}(x−4y+4z)−\dfrac{4}{13}(2x+4y−2z)\)

\(D_uf(0,−2,5)=\dfrac{384}{13}\)

### Summary

- A directional derivative represents a rate of change of a function in any given direction.
- The gradient can be used in a formula to calculate the directional derivative.
- The gradient indicates the direction of greatest change of a function of more than one variable.

### Key Equations

**directional derivative (two dimensions)**

\(D_uf(a,b)=\lim_{h→0}\dfrac{f(a+h\cos θ,b+h\sin θ)−f(a,b)}{h}\)

or

\(D_uf(x,y)=f_x(x,y)\cos θ+f_y(x,y)\sin θ\)

**gradient (two dimensions)**

\(∇f(x,y)=f_x(x,y)i+f_y(x,y)j\)

**gradient (three dimensions)**

\(∇f(x,y,z)=f_x(x,y,z)i+f_y(x,y,z)j+f_z(x,y,z)k\)

**directional derivative (three dimensions)**

\(D_uf(x,y,z)=∇f(x,y,z)⋅u=f_x(x,y,z)\cos α+f_y(x,y,z)\cos β+f_x(x,y,z)\cos γ\)

### Glossary

**directional derivative**-
the derivative of a function in the direction of a given unit vector

**gradient**-
the gradient of the function \(f(x,y)\) is defined to be \(∇f(x,y)=(∂f/∂x)i+(∂f/∂y)j,\) which can be generalized to a function of any number of independent variables

### Contributors

Gilbert Strang (MIT) and Edwin “Jed” Herman (Harvey Mudd) with many contributing authors. This content by OpenStax is licensed with a CC-BY 3/0 license. Download for free at http://cnx.org/contents/fd53eae1-fa2...49835c3c@5.191.