# Directional Derivatives and Gradient Vectors

• By David A. Smith, Founder & CEO, Direct Knowledge
• David Smith has a B.S. and M.S. in Mathematics and has enjoyed teaching calculus, linear algebra, and number theory at both Tarrant County College and the University of Texas at Arlington. David is the Founder and current CEO of Direct Knowledge.

## Definition of Directional Derivative

Partial derivatives find the rate of change of $z=f(x,y)$ in the directions of the $x$ and $y$ axis; that is in the direction of the unit vectors ${i}$ and ${j}$, respectively.

Definition. Let $f$ be a function of two variables, and let ${u} = u_1{i}+u_2{j}$ be a unit vector. The directional derivative of $f$ at $P(a,b)$ in the direction of ${u}$ is defined by $$D_{{u}} f(a,b)=\lim_{h\to 0}\frac{f\left(a+h u_1, b+h u_2\right)-f(a,b)}{h}$$ provided the limit exists.

Theorem. (Directional Derivative) Let $f(x,y)$ be a function that is differentiable at $P(a,b).$ Then $f$ has a directional derivative in the direction of the unit vector ${u}=u_1{i}+u_2{j}$ which is given by $$\label{dirder} D_{{u}} f(a,b) = f_x(a,b)u_1 + f_y(a,b)u_2.$$

Proof. We define a function $F$ of a single variable $h$ by $F(h)=f\left(a+h u_1,b+h u_2\right)$ so that \begin{align*} D_{{u}}f(a,b) & =\lim_{h\to 0}\frac{f\left(a+h u_1,b+h u_2\right)-f(a,b)}{h} \\ & =\lim_{h\to 0}\frac{F(h)-F(0)}{h} \\& = F'(0). \end{align*} Applying the chain rule with $x=a+h u_1$ and $y=b+h u_2$ \begin{align*} F'(h) & =\frac{d F}{d h} \\& =\frac{\partial f}{\partial x}\frac{d x}{d h} +\frac{\partial f}{\partial y}\frac{d y}{d h} \\ & =f_x(x,y) u_1 + f_y(x,y) u_2.\end{align*} When $h=0,$ we have $x=a$ and $y=b$ so that \begin{align*} D_{{u}} f(a,b) & =F'(0) \\ & =\frac{\partial f}{\partial x}u_1 + \frac{\partial f}{\partial y}u_2 =f_x(a,b) u_1+f_y(a,b)u_2. \end{align*}

Example. Find the directional derivative $D_{{u}}f(x,y)$ where $f$ is the function defined by $$f(x,y)=x^3-3x y+4y^2$$ and ${u}$ is the unit vector given by the angle $\theta =\pi /6.$ What is $D_{{u}}f(1,2)?$

Solution. We let ${u}=\cos \left(\frac{\pi }{6}\right){i}+\sin \left(\frac{\pi }{6}\right){j}$ and use the above theorem to find \begin{align} D_{{u}}f(x,y) & = f_x(x,y)\cos \frac{\pi }{6}+f_y(x,y)\sin \frac{\pi }{6} \\ & = \left(3x^2-3y\right)\frac{\sqrt{3}}{2}+(-3x+8y)\frac{1}{2} \\ & =\frac{1}{2} \left[3\sqrt{3}x^2-3x+\left(8-3\sqrt{3}\right)y\right].\end{align} Therefore, the directional derivative is \begin{align*} D_{{u}} f(1,2) & =\frac{1}{2}\left( 3\sqrt{3}(1)^2-3(1)+8-3\sqrt{3}\right) \\ & =\frac{13-3\sqrt{3}}{2}. \end{align*}

Example. Find the directional derivative of the function $f$ defined by $$f(x,y)=y^2+3y x^2$$ at $P=(-1,-2)$ in the direction towards the origin.

Solution. A vector in the direction from $(-1,-2)$ to $(0,0)$ is ${i}+2{j},$ so a unit vector in this direction is therefore $${u}=\frac{1}{\sqrt{5}}{i}+\frac{2}{\sqrt{5}}{j}.$$ We find that $$f_y(-1,-2)=\left.\left(2y+3x^2\right)\right|{(-1,-2)}=-1$$ and $$f_x(-1,-2)=\left.6x y\right|{(-1,-2)}=12.$$ Therefore, the directional derivative is $$D_{{u}} f(-1,-2)=\frac{1}{\sqrt{5}}(12)+\frac{2}{\sqrt{5}}(-1)=2 \sqrt{5}.$$

Example. Find the directional derivative of the function $f$ defined by $$f(x,y)=x^2+3x y^2$$ at $P=(1,2)$ in the direction towards the origin.

Solution. A vector in the direction from $(1,2)$ to $(0,0)$ is $-{i}-2{j},$ so a unit vector in this direction is therefore $${u}=\frac{-1}{\sqrt{5}}{i}-\frac{2}{\sqrt{5}}{j}.$$ We find that $$f_x(1,2)=\left.\left(2x+3y^2\right)\right|{(1,2)}=14$$ and $$f_y(1,2)=\left.6x y\right|{(1,2)}=12.$$ Therefore, the directional derivative is given by $$D_{{u}}f(1,2)=\frac{-1}{\sqrt{5}}(14)-\frac{2}{\sqrt{5}}(12)=\frac{-38}{\sqrt{5}}.$$

## The Gradient of a Function

Definition. Let $f$ be a differentiable function at $(a,b).$ Then the gradient of $f$ is denoted by $\nabla f(x,y)=f_x(x,y){i}+f_y(x,y){j}.$ The value of the gradient at the point $P(a,b)$ is denoted by $$\nabla f_P=f_x(a,b){i}+f_y(a,b){j}.$$

Example. Find the gradient $\nabla f$ of the function $f$ defined by $$f(x,y)=\sin x+e^{x y}$$ and evaluate the gradient at $(0,1).$

Solution. If $f(x,y)=\sin x+e^{x y},$ then $$\nabla f(x,y)=\langle \cos x+y e^{x y},x e^{x y}\rangle$$ and $\nabla f(0,1)=\langle 2,0 \rangle.$

Theorem. (Directional Derivative and Gradient) If $f$ is a differentiable function of $x$ and $y$, then the directional derivative of $f$ at the point $P(a,b)$ in the direction of the unit vector ${u}$ is $$D_{{u}} f(a,b) = \nabla f_P\cdot {u}.$$

Proof. Since $\nabla f_P=f_x(a,b){i}+f_y(a,b){j}$ and ${u}=u_1{i}+u_2{j},$ we have $$\nabla f_P\cdot {u} = f_x(a,b) u_1 + f_y(a,b) u_2 = D_{{u}}f(a,b).$$

Example. Find the directional derivative of the function $f$ defined by $$f(x,y)=x^2+x y+y^2$$ at $P(1,-1)$ in the direction towards the origin.

Solution. We use the unit vector $${u}=\left(-\frac{1}{\sqrt{2}}\right){i}+\left(\frac{1}{\sqrt{2}}\right){j}$$ and find $\nabla f=(2x+y){i}+(2y+x){j}$ to determine \begin{align*} D_{{u}}f(1,-1) & =\nabla f(1,-1)\cdot {u} \\ & =({i}-{j})\cdot \left(-\frac{1}{\sqrt{2}}\right) {i}+\left(\frac{1}{\sqrt{2}}\right){j} \\ & =-\sqrt{2}. \end{align*}

Example. Find the directional derivative of the function $f$ defined by $$f(x,y)=x^3y^4$$ at the point $(6,-1)$ in the direction of the vector ${v}=2{i}+5{j}.$

Solution. We first compute the gradient vector at $(6,-1)$ $$\nabla f(x,y) =3x^2y^4{i}+4x^3y^3{j}$$ and $$\nabla f(6,-1)=108{i}-864{j}.$$ Note that ${v}$ is not a unit vector, but since $|{v}|=\sqrt{29}$, the unit vector in the direction of ${v}$ is $${u}=\frac{{v}}{|{v}|}=\frac{2}{\sqrt{29}}{i}+\frac{5}{\sqrt{29}}{j}.$$ Therefore we have \begin{align*} D_{{u}}f(6,-1) & =\nabla f(6,-1)\cdot {u} \\ & =(108{i}-864{j})\cdot \left( \frac{2}{\sqrt{29}}{i}+\frac{5}{\sqrt{29}}{j}\right) \\ & =\frac{-4104}{\sqrt{29}}. \end{align*}

Example. Let $f(x,y,z)=x y z,$ and let ${u}$ be a unit vector perpendicular to both ${v}={i}-2{j}+3{k}$ and ${w}=2 {i}+{j}-{k}.$ Find the directional derivative of $f$ at $P(1,-1,2)$ in the direction ${u}.$

Solution. The gradient is $$\nabla f=\nabla (x y z)=y z {i}+x z{j}+x y {k}$$ and $\nabla f_P=-2{i}+2{j}-{k}.$ Now since we are looking for a unit vector perpendicular to both ${v} = {i} – 2{j} + 3{k}$ and ${w}=2 {i}+{j}-{k}$ we find, ${v} \times {w}=-{i}+7{j}+5{k}$ and so ${u}=\frac{1}{\sqrt{75}}(-{i}+7{j}+5{k}).$ Therefore we have \begin{align*} D_{{u}}f & =(-2{i}+2{j}-{k})\cdot \left(\frac{-1}{\sqrt{75}}{i}+\frac{7}{\sqrt{75}}{j}+\frac{5} {\sqrt{75}} {k}\right) \\ & = \frac{11\sqrt{3}}{15}. \end{align*}

Theorem. (Properties of the Gradient) Let $f$ and $g$ be differentiable functions. Then

$(1) \quad \nabla c=0$ for any constant $c$

$(2) \quad \nabla (a f+b g)=a\nabla (f)+b\nabla (g)$ for any constants $a$ and $b$

$(3) \quad \nabla (f g)=f\cdot \nabla (g)+g\cdot \nabla (f)$

$(4) \quad \nabla \left(\frac{f}{g}\right)=\frac{g\cdot \nabla (f)-f\cdot \nabla (g)}{g^2}$ provided $g^2\neq 0$

$(5) \quad \nabla \left(f^n\right)=n f^{n-1}\cdot \nabla (f)$

Proof. An outline of how each part can be proven in listed below.

The (constant rule) is proved as follows by $\nabla c=(c)_x{i}+(c)_y{j}=0.$

The (linearity rule) is proved as follows \begin{align*} \nabla (a f +b g) & =\left(a f_x+ b g_x\right){i}+\left(a f_x+ b g_y\right){j} \\ & =a\nabla (f)+b\nabla (g). \end{align*}

The (product rule) is proved as follows \begin{align*} \nabla (f g) & =(f g)_x{i}+(f g)_y{j} \\ & =\left(f_xg+g_xf\right) {i}+\left(f_yg+g_yf\right) {j} \\ & =\left[f\left(g_x{i}+g_y{j}\right)\right]+\left[g\left(f_x{i}+f_y{j}\right)\right] \\ & =f\cdot \nabla (g)+g\cdot \nabla (f). \end{align*}

The (quotient rule) is proved as follows \begin{align*} \nabla \left(\frac{f}{g}\right) & =\left(\frac{f}{g}\right)_x{i}+\left(\frac{f}{g}\right)_y{j} \\& =\left(\frac{f_xg-g_xf }{g^2}\right){i}+\left(\frac{f_yg-g_yf }{g^2}\right) {j} \\ & =\frac{\left[g\left(f_x{i}+f_y{j}\right)\right]-\left[f\left(g_x{i} + g_y{j}\right)\right]}{g^2} \\ & =\frac{g\cdot \nabla (f)-f\cdot \nabla (g)}{g^2}. \end{align*}

The (power rule) is proved as follows \begin{align*} \nabla f^n & =\left(f^n\right)_x{i}+\left(f^n\right)_y{j} \\ & =\left(n f^{n-1}\right)f_xb {i}+\left(n f^{n-1}\right)f_yb {j} =n f^{n-1}\cdot \nabla (f). \end{align*}

Theorem. (Orthogonality of Gradient) Suppose the function $f$ is differentiable at the point $P$ and that the gradient at $P$ satisfies $\nabla f_P\neq 0.$ Then $\nabla f_P$ is orthogonal to the level surface (or curve) of $f$ through $P.$

Proof. Let $C$ be any smooth curve on the level surface $f(x,y,z)=K$ that passes through $P(a,b,c),$ and describe the curve $C$ by the vector function ${R}(t)=x(t){i}+y(t){j}+z(t){k}$ for all $t$ in some interval $I.$ We will show that the gradient $\nabla f_P$ is orthogonal to the tangent vector $d R/d t$ at $P.$ Because $C$ lies on the level surface, any point $P(x(t),y(t),z(t))$ on $C$ must satisfy $f[x(t),y(t),z(t)]=K,$ and by applying the chain rule, we obtain \begin{align*} & \frac{d}{d t}[f(x(t),y(t),z(t))] \\ \quad & =f_x(x,y,z)\frac{d x}{d t}
+f_y(x,y,z)\frac{d y}{d t}+f_z(x,y,z)\frac{d z}{d t}. \end{align*} Suppose $t=t_0$ at $P.$ Then \begin{align*} & \left. \frac{d}{d t}{ f[x(t),y(t),z(t)] }\right|_{t=t_0} \\ & \qquad = f_x \left(x \left(t_0 \right), y\left(t_0\right), z\left(t_0\right) \right)\frac{d x}{d t} \\ & \qquad + f_y \left(x \left(t_0\right), y\left(t_0\right), z\left(t_0\right)\right) \frac{d y}{d t} + f_z \left(x\left(t_0\right), y\left(t_0\right), z\left(t_0\right) \right)\frac{d z}{d t} \\ & \qquad = \nabla f_P\frac{d {R}}{d t} \end{align*} since $$\frac{d {R}}{d t}=\frac{d x}{d t}{i}+\frac{d y}{d t}{j}+\frac{d z}{d t}{k}.$$ We also know that $f(x(t),y(t),z(t))=K$ for all $t$ in $I.$ Thus, we have $$\frac{d}{d t} {f[x(t),y(t),z(t)] }=\frac{d}{d t}(K)=0$$ and it follows that $\nabla f_P\cdot \frac{d {R}}{d t}=0.$ We are given that $\nabla f_P\neq 0$ and $d {R}/d t\neq 0$ because the curve $C$ is smooth. Therefore, $\nabla f_P$ is orthogonal to $d {R}/d t,$ as required.

## Steepest Ascent and Steepest Descent

The direction of the greatest rate of increase (or decrease) of a given function at a specified point is called the direction of steepest ascent (or steepest descent). The gradient is the key for the direction of steepest ascent.

Theorem. (Steepest Ascent/Descent) Suppose $f$ is differentiable at the point $P$ and that the gradient of $f$ at $P$ satisfies $\nabla f_P\neq 0.$ Then

(1) The largest value of the directional derivative $D_{{u}}f$ at $P$ is $\left| \nabla f_P \right|$ and occurs when the unit vector ${u}$ points in the direction of $\nabla f_P.$

(2) The smallest value of the directional derivative $D_{{u}}f$ at $P$ is $-\left| \nabla f_P \right|$ and occurs when the unit vector ${u}$ points in the direction of $-\nabla f_P.$

Proof. If ${u}$ is any unit vector, then $D_{{u}}f=\nabla f_P\cdot {u}=\left|\nabla f_P\right||{u}| \cos \theta =\left|\nabla f_P\right| \cos \theta$ where $\theta$ is the angle between $\nabla f_P$ and ${u}.$ But $\cos \theta$ assumes its largest value of 1 at $\theta =0;$ that is, when ${u}$ points in the direction $\nabla f_P.$ Thus, the largest possible value of $D_{{u}}f$ is $$D_{{u}}f =\left|\nabla f_P\right|(1)=\left|\nabla f_P\right|.$$ Also $\cos \theta$ assumes its smallest value $-1$ when $\theta =\pi .$ This value occurs when ${u}$ points toward $-\nabla f_P,$ and in this direction $$D_{{u}}f = \left|\left|\left.\nabla f_P\right|(-1)\right.\right. =\left|\left|\left.\nabla f_P\right|(-1)\right.\right. =-\left|\nabla f_P\right|.$$

Example. Sketch the level curve corresponding to $C=1$ for the function $$f(x,y)=x^2-y^2$$ and find a normal vector at the point $P(2,\sqrt{3}).$

Solution. The level curve for $C=1$ is a hyperbola given by $x^2-y^2=1.$ The gradient vector is perpendicular to the level curve. We have $$\nabla f=f_x{i}+f_y{j}=2x{i}-2y{j}$$ so at the point $\left(2,\sqrt{3}\right),$ $\nabla f_P=4i-2\sqrt{3}j$ is the required normal.

Example. In what direction is the function defined by $$f(x,y)=x e^{2y-x}$$
increasing most rapidly at the point $P(2,1)$, and what is the maximum rate of increase? In what direction is $f$ decreasing most rapidly?

Solution. We begin by finding the gradient of $f,$ \begin{align} \nabla f & =f_x{i}+f_y{j} \\ & =\left[e^{2y-x}+x e^{2y-x}(-1)\right]{i}+\left[x e^{2y-x}(2)\right]{j} \\ & =e^{2y-x}(1-x){i}+2 x{j}\end{align}
At $P(2,1)$, $$\nabla f_P=e^{2(1)-2}[(1-2){i}+2(2){j}]=-{i}+4{j}.$$ The most rapid rate of increase is $\left|\nabla f_P\right|=\sqrt{(-1)^2+4^2}=\sqrt{17}$ and occurs in the direction of $-{i}+4{j}.$ The most rapid rate of decrease occurs in the direction of $-\nabla f_P={i}-4{j}$ and is $-\sqrt{17}.$

Example. Let $f(x,y,z)=y e^{x+z}+z e^{y-x}.$ At the point $P(2,2,-2),$ find the unit vector pointing in the direction of most rapid increase of $f.$

Solution. The gradient is \begin{align*} \nabla f=\left(y e^{x+z}-z e^{y-x}\right){i}+\left(e^{x+z}+x e^{y-x}\right){j}+\left(y e^{x+z}+e^{y-z}\right){k}. \end{align*} Thus, $\nabla f(2,2,-2)=4{i}-{j}+3{k}$ and so ${u}=\frac{1}{\sqrt{26}}(4{i}-{j}+3{k}).$

Example. Find the maximum rate of change of the function at the given point and the direction in which it occurs $f(x,y)=\sqrt{x^2+2y}$, $(4,10)$

Solution. We find \begin{align*} \nabla f(4,10)=\left.\frac{x}{\sqrt{x^2+2 y}}\right|_{(4,10)}{i}+\left.\frac{1}{\sqrt{x^2+2 y}}\right|_{(4,10)}{j} =\frac{2}{3}{i}+\frac{1}{6}{j}. \end{align*} Thus the maximum rate of change is $\sqrt{(2/3)^2+(1/6)^2}=\frac{\sqrt{17}}{6}$ and occurs in the direction of $\frac{2}{3}{i}+\frac{1}{6}{j}.$

Example. Find the maximum rate of change of the function at the given point and the direction in which it occurs $f(x,y)=\sqrt{y^2+2x}$, $(-4,-10)$

Solution. We find \begin{align*} \nabla f(-4,-10) & =\left.\frac{1}{\sqrt{2 x+y^2}}\right|{(-4,-10)}{i}+\left.\frac{y}{\sqrt{2 x+y^2}}\right|{(-4,-10)}{j} \\ & =\frac{1}{2 \sqrt{23}}{i}-\frac{5}{\sqrt{23}}{j}. \end{align*} Thus the maximum rate of change is $$\sqrt{\left(\frac{1}{2 \sqrt{23}} \right)^2 + \left(-\frac{5}{\sqrt{23}}\right)^2}=\frac{1}{2}\sqrt{\frac{101}{23}}$$ and occurs in the direction of $\frac{1}{2 \sqrt{23}}{i}-\frac{5}{\sqrt{23}}j.$

Example. Find the direction from $P(2,-1,2)$ in which the function $$f(x,y,z)=(x+y)^2+(y+z)^2+(x+z)^2$$ increases most rapidly and compute the magnitude of the greatest rate of increase.

Solution. We compute the gradient: \begin{align*} \nabla f=(4 x+2y+2z){ i}+(2x+4y+2z){ j}+(2x+2y+4z){ k} \end{align*} and at $(2,-1,2)$ we have, $\nabla f(2,-1,2)=10{ i}+4{ j}+10{ k}.$ Therefore, $|\nabla f|=\sqrt{216}$ is the magnitude of the greatest rate of increase and occurs in the direction of $10{ i}+4{ j}+10{ k}.$

## Exercises on Directional Derivatives and Gradient Vectors

Exercise. Find the directional derivative of $f(x,y)=x^2y^2-x^2+2y$ at the point $(2,2)$ in the direction of the unit vector ${u}=\frac{1}{2}{i}-\frac{\sqrt{3}}{2}{j}.$

Exercise. Find the gradient of the function $f(x,y)=y \tan x+\sin xy.$

Exercise. Find the directional directive of $f(x,y)=\frac{e^{-x}}y$ at $P(0,-1)$ in the direction of $\mathbf{v}=-\mathbf{i}+\mathbf{j}.$

Exercise. Find the gradient of the function.

$(1) \quad f(x,y)=x^2-2 x y$

$(2) \quad f(x,y)=\ln \left(x^2+y^2\right)$

$(3) \quad f(x,y)=\sin (x+2y)$

$(4) \quad f(x,y,z)=\frac{x y-1}{z+x}$

$(5) \quad f(x,y,z)= x y z^2$

$(6) \quad g(x,y,z)=x e^{y+3z}$

Exercise. Compute the directional derivative of the function $f(x,y)=\ln \left(x^2+3y\right)$ at the point $(1,1)$ in the direction of the vector $v={i}+{j}.$

Exercise. Compute the directional derivative of the function $f(x,y)=\sin x y$ at the point $\left(\sqrt{\pi },\sqrt{\pi }\right)$ in the direction of the vector $v=3\pi {i}-\pi {j} .$

Exercise. Find the directional derivative of the given function at the given point in the direction of the given vector.

$(1) \quad f(x,y)=x^2+x y$, $(1,-2),$ and ${i}+{j}$

$(2) \quad f(x,y)=\frac{e^{-x}}{y},$ $(2,-1),$ and $-{i}+{j}$

Exercise. Find the directional derivative of the given function at the given point in the direction of the given vector.

$(1) \quad f(x,y)=\ln \left(3x+y^2\right)$, $(0,1),$ and ${i}-{j}$

$(2) \quad f(x,y)=\sec \left(x y-y^3\right),$ $(2,0),$ and $-{i}-3{j}$

Exercise. Find the direction from $P_0$ in which the given function $f$ increases most rapidly and compute the magnitude of the greatest rate of increase.

$(3) \quad f(x,y,z)=(x+y)^2+(y+z)^2+(x+z)^2$ at $P_0(2,-1,2)$

$(4) \quad f(x,y,z)=z \ln \left(\frac{y}{z}\right)$ at $P_0(1,e,-1)$