Tutorials › Calculus III › Directional Derivative Calculation Workshop

Directional Derivatives and Gradients · Tutorial 398 of 999

Directional Derivative Calculation Workshop

Learn a reliable step-by-step method for computing directional rates from partial derivatives, gradients, and normalized direction vectors.

Intermediate 9 min read

What You'll Learn

  • Find the gradient by computing and evaluating all required partial derivatives.
  • Normalize a nonzero direction vector before using it for a directional rate.
  • Calculate directional derivatives for functions of two and three variables.
  • Verify a computed rate by differentiating the function along a parametrized line.
  • Recognize and correct the error of using an unnormalized direction.

From Partial Derivatives to a Directional Rate

A directional derivative combines familiar ingredients into one calculation: partial derivatives, a gradient evaluated at a point, and a unit vector specifying a direction. The main challenge is keeping these steps in the right order. In particular, a direction vector must have length one when it is used to calculate the rate of change per unit distance.

This workshop develops a consistent procedure and applies it to functions of two and three variables. Each answer will also be checked by differentiating the function along a parametrized line in the chosen direction.

Definition and Calculation Rule

Let \(f\) be differentiable at a point \(\mathbf{a}\) in two- or three-dimensional space. A direction is represented by a nonzero vector \(\mathbf{v}\). Its associated unit vector is \(\mathbf{u}=\mathbf{v}/\|\mathbf{v}\|\). The directional derivative is the rate of change of \(f\) at \(\mathbf{a}\) in the direction of \(\mathbf{u}\).

Definition: For a unit vector \(\mathbf{u}\), the directional derivative of \(f\) at \(\mathbf{a}\) in direction \(\mathbf{u}\), when the limit exists, is \(D_{\mathbf{u}}f(\mathbf{a})=\lim_{t\to 0}\frac{f(\mathbf{a}+t\mathbf{u})-f(\mathbf{a})}{t}\). If \(f\) is differentiable at \(\mathbf{a}\), then \(D_{\mathbf{u}}f(\mathbf{a})=\nabla f(\mathbf{a})\cdot\mathbf{u}\).

For \(f(x,y)\), the gradient is \(\nabla f=(f_x,f_y)\). For \(f(x,y,z)\), it is \(\nabla f=(f_x,f_y,f_z)\). The partial derivatives are first found as functions, then evaluated at the specified point. The dot product with the unit direction gives a single number: the instantaneous rate of change in that direction.

$$ \mathbf{u}=\frac{\mathbf{v}}{\|\mathbf{v}\|}, \qquad \|\mathbf{v}\|=\sqrt{v_1^2+\cdots+v_n^2}, \qquad D_{\mathbf{u}}f(\mathbf{a})=\nabla f(\mathbf{a})\cdot\mathbf{u}. $$

The formula using the gradient requires differentiability at the point. Without that assumption, partial derivatives alone need not determine a directional derivative, and a directional derivative need not be given by a gradient dot product. Here the worked problems use functions differentiable at the specified points.

Why the Gradient Formula Works

The formula follows from the meaning of differentiability. At a differentiability point \(\mathbf{a}\), the change in \(f\) for a small displacement \(\mathbf{h}\) is its linear approximation \(\nabla f(\mathbf{a})\cdot\mathbf{h}\), plus an error that becomes negligible compared with \(\|\mathbf{h}\|\). In the direction \(\mathbf{u}\), set \(\mathbf{h}=t\mathbf{u}\). Since \(\|\mathbf{u}\|=1\), the error divided by \(t\) tends to zero as \(t\to0\).

$$ f(\mathbf{a}+t\mathbf{u}) = f(\mathbf{a})+ \nabla f(\mathbf{a})\cdot(t\mathbf{u})+r(t\mathbf{u}), \qquad \frac{r(t\mathbf{u})}{|t|}\longrightarrow 0. $$

Subtract \(f(\mathbf{a})\), divide by \(t\), and take the limit. The linear term becomes \(\nabla f(\mathbf{a})\cdot\mathbf{u}\), while the error term tends to zero. This proves the directional-derivative formula. Normalization matters because a unit vector describes displacement per unit distance; a vector of another length also changes the speed at which the line is traversed.

A Reliable Calculation Sequence

1
Differentiate.
Compute every required first partial derivative of \(f\).
2
Evaluate the gradient.
Substitute the given point into the partial derivatives.
3
Normalize the direction.
Divide the given nonzero direction vector by its length.
4
Take the dot product.
Multiply corresponding components and add them.
5
Check along a line.
Parametrize a line with the unit direction and differentiate the resulting one-variable function at zero.

Worked Examples

Worked Example: A Polynomial in Two Variables

Find the directional derivative of \(f(x,y)=x^2y+3y^2\) at \((1,-1)\) in the direction of \(\mathbf{v}=(3,4)\). First compute the partial derivatives:

$$ f_x=2xy, \qquad f_y=x^2+6y. $$

Evaluate them at the point:

$$ f_x(1,-1)=2(1)(-1)=-2, \qquad f_y(1,-1)=1^2+6(-1)=-5. $$

Thus \(\nabla f(1,-1)=(-2,-5)\). The direction vector has length \(\sqrt{3^2+4^2}=5\), so its unit vector is \(\mathbf{u}=(3/5,4/5)\). The directional derivative is

$$ D_{\mathbf{u}}f(1,-1) =(-2)\frac35+(-5)\frac45 =-\frac65-\frac{20}{5} =-\frac{26}{5}. $$

To check, follow the line \((x(t),y(t))=(1+3t/5,-1+4t/5)\). Differentiating \(f(x(t),y(t))\) at \(t=0\) gives \(2x(0)x'(0)y(0)+x(0)^2y'(0)+6y(0)y'(0)\). Substitution gives \(2(1)(3/5)(-1)+1(4/5)+6(-1)(4/5)=(-6+4-24)/5=-26/5\), as required.

Worked Example: A Logarithm in Two Variables

Let \(f(x,y)=\ln(x^2+y^2)\). Find the rate at \((1,2)\) in the direction \(\mathbf{v}=(-1,2)\). The function is defined and differentiable wherever \(x^2+y^2>0\), which includes the given point. Its partial derivatives are

$$ f_x=\frac{2x}{x^2+y^2}, \qquad f_y=\frac{2y}{x^2+y^2}. $$

At \((1,2)\), the denominator is \(1^2+2^2=5\), so \(\nabla f(1,2)=(2/5,4/5)\). The direction has length \(\sqrt{(-1)^2+2^2}=\sqrt5\), giving \(\mathbf{u}=(-1/\sqrt5,2/\sqrt5)\). Therefore

$$ D_{\mathbf{u}}f(1,2) = \frac25\left(-\frac1{\sqrt5}\right) +\frac45\left(\frac2{\sqrt5}\right) = -\frac{2}{5\sqrt5}+\frac{8}{5\sqrt5} = \frac{6}{5\sqrt5}. $$

For a check, use \(x(t)=1-t/\sqrt5\) and \(y(t)=2+2t/\sqrt5\). The derivative of \(\ln(x(t)^2+y(t)^2)\) at zero is \(\frac{2x(0)x'(0)+2y(0)y'(0)}{x(0)^2+y(0)^2}\). Its numerator is \(2(1)(-1/\sqrt5)+2(2)(2/\sqrt5)=6/\sqrt5\), and its denominator is \(5\). The result is again \(6/(5\sqrt5)\).

Worked Example: A Polynomial in Three Variables

Let \(f(x,y,z)=xyz+x^2-2yz\). Find the directional derivative at \((1,-1,2)\) in the direction \(\mathbf{v}=(2,-1,2)\). Differentiate with respect to each variable:

$$ f_x=yz+2x, \qquad f_y=xz-2z, \qquad f_z=xy-2y. $$

Evaluating at the point gives \(f_x=-2+2=0\), \(f_y=2-4=-2\), and \(f_z=-1+2=1\). Thus \(\nabla f(1,-1,2)=(0,-2,1)\). The direction vector has length \(\sqrt{2^2+(-1)^2+2^2}=3\), so \(\mathbf{u}=(2/3,-1/3,2/3)\). Hence

$$ D_{\mathbf{u}}f(1,-1,2) = 0\left(\frac23\right)+(-2)\left(-\frac13\right)+1\left(\frac23\right) = \frac23+\frac23 = \frac43. $$

To verify, take \((x(t),y(t),z(t))=(1+2t/3,-1-t/3,2+2t/3)\). Differentiating \(xyz+x^2-2yz\) along this path at zero gives \(x'yz+xy'z+xyz'+2xx'-2(y'z+yz')\). At the point, the three terms from \(xyz\) sum to \((2/3)(-2)+(1)(-1/3)(2)+(1)(-1)(2/3)=-8/3\). The \(x^2\) term contributes \(2(1)(2/3)=4/3\), and the \(-2yz\) term contributes \(-2((-1/3)(2)+(-1)(2/3))=8/3\). The total is \(-8/3+4/3+8/3=4/3\).

A Common Error: Skipping Normalization

Suppose \(f(x,y)=x^2+y^2\), the point is \((1,0)\), and the direction is represented by \((3,4)\). A tempting but incorrect calculation is to use the vector as given:

$$ \nabla f(1,0)=(2,0), \qquad (2,0)\cdot(3,4)=6. $$

The value \(6\) is not the directional rate per unit distance in that direction. The vector \((3,4)\) has length \(5\); the corresponding unit vector is \((3/5,4/5)\). The correct calculation is

$$ D_{\mathbf{u}}f(1,0) = (2,0)\cdot\left(\frac35,\frac45\right) = \frac65. $$

The difference is not a matter of notation: using the unnormalized vector means moving five times as fast along the same line as when using its unit vector. Indeed, along \((1,0)+t(3,4)\), the derivative at zero is \(6\); along the unit-speed path \((1,0)+t(3/5,4/5)\), it is \(6/5\). The latter is the directional derivative under the unit-vector convention.

Keeping the Steps Distinct

Many calculation errors can be avoided by recording the gradient, the point, and the direction separately before taking the dot product. In three variables, check that all three partial derivatives are included. When a direction is given as a nonzero vector, calculate its length explicitly; do not assume it is already a unit vector. If the given direction is already a unit vector, its length is one and normalization leaves it unchanged.

A final line check is especially useful when the arithmetic is complicated. Build the path as \(\mathbf{a}+t\mathbf{u}\), substitute its coordinates into \(f\), and differentiate with respect to \(t\) at zero. The path must use the unit vector if the goal is to check the directional derivative per unit distance.

Takeaway: For a differentiable function, evaluate its gradient at the point, normalize the direction vector, and take their dot product. A line-derivative check should use the same unit direction.

Check Your Understanding

For each question, keep partial differentiation, point evaluation, and direction normalization as separate steps.

  1. For \(f(x,y)=xy+y^2\), find the directional derivative at \((2,1)\) in the direction \((1,1)\).
  2. What is the unit vector in the direction \((-2,1,2)\)?
  3. For \(f(x,y,z)=x^2+y^2+z^2\), find the directional derivative at \((1,0,-1)\) in the direction \((0,3,4)\).
  4. For a differentiable function, why must a direction vector be normalized when computing the rate per unit distance?
  5. Describe the parametrized-line check for a directional derivative at \(\mathbf{a}\) in unit direction \(\mathbf{u}\).