---
title: Directional Derivatives, the Gradient, and the Chain Rule
module: Functions of Several Variables (Introduction)
moduleNumber: 8
lessonNumber: 2
order: 802
summary: >
  The directional derivative measures the rate of change of a scalar field along
  a chosen heading and equals the derivative applied to that direction. The
  gradient collects these into a vector that points along steepest ascent and
  sits orthogonal to level sets. The chain rule composes derivatives by
  multiplying Jacobians, and a mean value theorem holds for scalar fields but
  fails for vector-valued maps.
topics: [Functions of Several Variables (Introduction)]
sources:
  - book: Shkoller
    ref: "§2.6 The directional derivative; §2.7 The chain-rule and product-rule"
  - book: Shkoller
    ref: "§2.8 The geometry of the gradient; §2.9 The Mean Value Theorem"
draft: false
---

The [derivative](/real-analysis/several-variables/differentiability-rn)
$Df(x_0)$ is a full linear transformation. Two narrower questions extract less
from it and are often what one needs: the rate of change of $f$ along a single
direction, and, for a scalar field, the direction of fastest increase. The first
answer is the directional derivative, a single number; the second is the
gradient, the vector that assembles the directional derivatives.

## The directional derivative

Fix an open neighborhood $U$ of $x_0 \in \mathbb{R}^n$ and a scalar field
$f : U \to \mathbb{R}$. To measure the rate of change of $f$ as we leave $x_0$
along a unit vector $e$, restrict $f$ to the line $t \mapsto x_0 + t e$ and
differentiate the resulting one-variable function at $t = 0$.

> **Definition (Directional derivative).** Let $e \in \mathbb{R}^n$ be a unit
> vector, $\lVert e \rVert = 1$. The **directional derivative** of $f$ at $x_0$ in
> the direction $e$ is
>
> $$
> \left. \frac{\d}{\d t} f(x_0 + t e) \right|_{t=0} = \lim_{t \to 0} \frac{f(x_0 + t e) - f(x_0)}{t},
> $$
>
> when the limit exists.

When $f$ is differentiable at $x_0$, the directional derivative is not a new
computation — it is the derivative read along $e$. Taking $x = x_0 + te$ in the
definition of $Df(x_0)$ gives, for any $\varepsilon > 0$ and small $|t|$,

$$
\left\lVert \frac{f(x_0 + t e) - f(x_0)}{t} - Df(x_0)\,e \right\rVert \le \varepsilon,
$$

so the limit exists and

$$
\lim_{t \to 0} \frac{f(x_0 + t e) - f(x_0)}{t} = Df(x_0)\,e.
$$

The partial derivatives are the special case $e = e_i$: $\partial f / \partial x_i$
is the directional derivative along the $i$-th coordinate axis.

$$
% caption: The directional derivative is the slope of $f$ restricted to the line
% through $x_0$ along $e$: the rise of the graph per unit step in direction $e$.
\begin{tikzpicture}[>=stealth, font=\footnotesize, scale=1.0]
  \definecolor{acc}{HTML}{4A6FA5}
  % ground plane (domain) as a parallelogram
  \draw[black] (-2.6,-0.9) -- (2.6,-0.9) -- (3.6,0.4) -- (-1.6,0.4) -- cycle;
  \node[black, anchor=north] at (2.4,-0.9) {domain};
  % point x0 and direction e
  \fill[black] (0,-0.35) circle (1.6pt);
  \node[black, anchor=north] at (0,-0.42) {$x_0$};
  \draw[->, acc, thick] (0,-0.35) -- (1.4,-0.05);
  \node[acc, anchor=west] at (1.4,-0.05) {$e$};
  % graph curve rising above the line
  \draw[thick, black] plot[domain=0:1.4, samples=30] ({\x}, {-0.35 + 0.21*\x + 1.1 + 0.5*\x*\x});
  \draw[thick, black] plot[domain=-1.6:0, samples=30] ({\x}, {-0.35 + 0.21*\x + 1.1 + 0.5*\x*\x});
  \node[black, anchor=west] at (1.35,2.1) {graph of $f$};
  % vertical connectors
  \draw[black, dashed] (0,-0.35) -- (0,1.1);
  \draw[black, dashed] (1.4,-0.05) -- (1.4,{-0.35 + 0.21*1.4 + 1.1 + 0.5*1.4*1.4});
  % tangent slope indicator
  \draw[acc, thick] (0.0,1.1) -- (1.4,{1.1 + 0.98});
  \node[acc, anchor=south east] at (1.1,{1.1+0.75}) {slope $= Df(x_0)\,e$};
\end{tikzpicture}
$$

**Directional derivatives do not imply differentiability.** As with partials, the
existence of _every_ directional derivative at a point is weaker than
differentiability — it does not even force continuity.

> **Example (all directional derivatives, yet discontinuous).** Let
> $f(x, y) = \dfrac{xy}{x^2 + y}$ where $x^2 + y \neq 0$, and $f = 0$ where
> $x^2 + y = 0$. For a unit direction $e = (e_1, e_2)$ with $e_2 \neq 0$,
>
> $$
> \frac{1}{t} f(t e_1, t e_2) = \frac{t^2 e_1 e_2}{t\,(t e_1^2 + e_2)} \to e_1 \quad\text{as } t \to 0,
> $$
>
> and the limit is $0$ when $e_2 = 0$. So every directional derivative exists at
> the origin. But along the curve $x^2 = -y + s$ with small $s > 0$, the value
> $f = xy/s$ is unbounded near the origin, so $f$ is not continuous there and
> therefore not differentiable.

This is stronger than the axis counterexample for partial derivatives: sampling
$f$ along every straight line still misses its behavior along curves, and only
differentiability controls all approaches at once.

**Tangent plane.** For $f : \mathbb{R}^2 \to \mathbb{R}$, the directional
derivatives assemble the tangent plane to the graph at $(x_0, f(x_0))$:

$$
z = f(x_0) + Df(x_0)\,(x - x_0).
$$

For $f(x, y) = x^2 + y$ at $(1, 2)$, $Df = (2x, 1)$ so $Df(1,2) = (2, 1)$, and the
tangent plane is $z = 3 + 2(x - 1) + (y - 2)$, i.e. $2x + y - z = 1$.

## The chain rule

Derivatives of composites are computed by matrix multiplication of the
Jacobians, in the order the maps are
applied.

> **Definition (Composite).** For open sets $A \subseteq \mathbb{R}^n$,
> $B \subseteq \mathbb{R}^m$ and maps $f : A \to \mathbb{R}^m$, $g : B \to
> \mathbb{R}^p$ with $f(A) \subseteq B$, the composite $g \circ f : A \to
> \mathbb{R}^p$ is $(g \circ f)(x) = g(f(x))$.

> **Theorem (Chain rule).** If $f$ is differentiable on $A$ and $g$ is
> differentiable on $B$ with $f(A) \subseteq B$, then $g \circ f$ is
> differentiable on $A$ and, for $x_0 \in A$,
>
> $$
> D(g \circ f)(x_0) = Dg\bigl(f(x_0)\bigr) \cdot Df(x_0).
> $$

The dimensions line up: $Df(x_0) : \mathbb{R}^n \to \mathbb{R}^m$ and
$Dg(f(x_0)) : \mathbb{R}^m \to \mathbb{R}^p$, so their product is a well-defined
linear map $\mathbb{R}^n \to \mathbb{R}^p$. In coordinates, with $h = g \circ f$,

$$
\frac{\partial h_i}{\partial x_k}(x) = \sum_{j=1}^{m} \frac{\partial g_i}{\partial y_j}\bigl(f(x)\bigr)\, \frac{\partial f_j}{\partial x_k}(x),
$$

which reproduces the row-times-column rule of matrix multiplication.

$$
% caption: The chain rule composes derivatives by multiplying Jacobians in the
% order the maps are applied, each a linear map between the intermediate spaces.
\begin{tikzpicture}[>=stealth, font=\footnotesize, scale=1.0,
  sp/.style={draw, minimum width=13mm, minimum height=10mm, align=center}]
  \definecolor{acc}{HTML}{4A6FA5}
  \node[sp] (rn) at (0,0) {$R^n$};
  \node[sp] (rm) at (3.4,0) {$R^m$};
  \node[sp, draw=acc, text=acc] (rp) at (6.8,0) {$R^p$};
  \draw[->, thick, acc] (rn) -- (rm) node[midway, above] {$Df(x_0)$};
  \draw[->, thick, acc] (rm) -- (rp) node[midway, above] {$Dg(f(x_0))$};
  % composite arc below
  \draw[->, thick, black] (rn.south) .. controls (2.2,-1.4) and (4.6,-1.4) .. (rp.south);
  \node[black, anchor=north] at (3.4,-1.25) {composite $= Dg(f(x_0))\, Df(x_0)$};
\end{tikzpicture}
$$

> **Worked example (polar coordinates).** For $f : \mathbb{R}^2 \to \mathbb{R}$ with
> $x = r\cos\theta$, $y = r\sin\theta$, the chain rule on
> $f(x(r,\theta), y(r,\theta))$ gives
>
> $$
> \frac{\partial f}{\partial r} = \frac{\partial f}{\partial x}\cos\theta + \frac{\partial f}{\partial y}\sin\theta,
> \qquad
> \frac{\partial f}{\partial \theta} = -\frac{\partial f}{\partial x}\,r\sin\theta + \frac{\partial f}{\partial y}\,r\cos\theta,
> $$
>
> which derives the polar-coordinate differential operators once for reuse.

> **Worked example (chain rule end to end).** For $f(u, v, w) = u^2 v + w v^2$ with
> $u = xy$, $v = \sin x$, $w = e^x$, the composite is
> $h(x, y) = x^2 y^2 \sin x + e^x \sin^2 x$. Differentiating directly,
>
> $$
> \frac{\partial h}{\partial x} = 2xy^2 \sin x + x^2 y^2 \cos x + e^x \sin^2 x + 2 e^x \sin x \cos x.
> $$
>
> The chain rule assembles the same expression from the factors
> $f_u = 2uv$, $f_v = u^2 + 2wv$, $f_w = v^2$ and $u_x = y$, $v_x = \cos x$,
> $w_x = e^x$:
>
> $$
> \frac{\partial h}{\partial x} = f_u\,u_x + f_v\,v_x + f_w\,w_x = 2uv\,y + (u^2 + 2wv)\cos x + v^2 e^x,
> $$
>
> which re-expands to the direct computation on substituting $u, v, w$.

The other differentiation rules also hold. The derivative
operator $D$ is linear — $D(u + v) = Du + Dv$ and $D(\alpha u) = \alpha\,Du$ — and
there is a product rule for a scalar times a vector field.

> **Theorem (Product rule).** For $f : A \to \mathbb{R}^m$ and a scalar
> $g : A \to \mathbb{R}$, both differentiable, the product $g f$ is differentiable
> and
>
> $$
> D(g f)(x)\,w = g(x)\,\bigl[ Df(x)\,w \bigr] + \bigl[ Dg(x)\,w \bigr]\,f(x)
> \qquad \text{for all } w \in \mathbb{R}^n.
> $$

Abbreviated, $D(g f) = g\,Df + Dg\,f$, with the understanding that $g$ scales the
vector $f$ and $Dg\,w$ is a scalar scaling it too.

## The geometry of the gradient

For a scalar field $f : A \subseteq \mathbb{R}^n \to \mathbb{R}$, the derivative
is the single row vector

$$
\operatorname{grad} f(x) = \nabla f(x) = \left( \frac{\partial f}{\partial x_1}, \dots, \frac{\partial f}{\partial x_n} \right),
$$

and the directional derivative becomes an inner product,
$Df(x_0)\,e = \nabla f(x_0) \cdot e$. Two geometric facts follow from that one
identity.

**Steepest ascent.** Writing the inner product with the angle $\theta$ between
$\nabla f(x_0)$ and the unit direction $e$,

$$
\nabla f(x_0) \cdot e = \lVert \nabla f(x_0) \rVert \cos\theta.
$$

This is largest when $\theta = 0$, i.e. when $e$ points along $\nabla f(x_0)$. The
gradient points in the direction of fastest increase of $f$, and its length is
that maximal rate. The opposite direction, $-\nabla f$, is the direction of
steepest descent.

> **Worked example (steepest ascent computed).** For $f(x, y) = x^2 y$ at the
> point $(1, 2)$, $\nabla f = (2xy,\ x^2)$, so $\nabla f(1, 2) = (4, 1)$. The
> direction of fastest increase is the unit gradient
> $\left( 4/\sqrt{17},\ 1/\sqrt{17} \right)$, and the maximal rate of increase is
> $\lVert \nabla f(1,2) \rVert = \sqrt{17}$. Along the unit direction
> $e = \left( \tfrac{3}{5}, \tfrac{4}{5} \right)$, the rate is only
>
> $$
> \nabla f(1,2) \cdot e = \frac{4 \cdot 3 + 1 \cdot 4}{5} = \frac{16}{5} = 3.2 < \sqrt{17} \approx 4.12,
> $$
>
> and along the level direction $\left( -1/\sqrt{17},\ 4/\sqrt{17} \right)$
> orthogonal to $\nabla f(1,2)$ it is $0$.

$$
% caption: The directional rate $\nabla f\cdot e=\lVert\nabla f\rVert\cos\theta$ is
% the projection of the gradient onto $e$, largest when $e$ aligns with the gradient.
\begin{tikzpicture}[>=stealth, font=\footnotesize, scale=1.0]
  \definecolor{acc}{HTML}{4A6FA5}
  \coordinate (o) at (0,0);
  \draw[->, acc, very thick] (o) -- (3.4,1.7);
  \node[acc, anchor=south east] at (3.4,1.72) {grad f};
  \draw[->, black, thick] (o) -- (3.9,0);
  \node[black, anchor=north] at (3.9,-0.02) {e};
  \draw[black, dashed] (3.4,1.7) -- (3.4,0);
  \draw[acc!60, line width=2pt] (o) -- (3.4,0);
  \node[black, anchor=north] at (1.7,-0.05) {rate along e};
  \draw[black] (0.85,0) arc (0:26.57:0.85);
\end{tikzpicture}
$$

**Orthogonality to level sets.** Let $S = \{ x : f(x) = c \}$ be a level set. If
$t \mapsto \gamma(t)$ is a differentiable curve lying in $S$ with $\gamma(0) =
x_0$, then $f(\gamma(t)) = c$ is constant, and differentiating with the chain rule,

$$
\nabla f(x_0) \cdot \gamma'(0) = 0.
$$

Since $\gamma'(0)$ can be any tangent vector to $S$ at $x_0$, the gradient is
orthogonal to $S$. The tangent plane to $S$ at $x_0$ is therefore
$\nabla f(x_0) \cdot (x - x_0) = 0$.

$$
% caption: The gradient at a point is orthogonal to the level curve through it and
% points toward higher values; a step along a level curve leaves $f$ unchanged.
\begin{tikzpicture}[>=stealth, font=\footnotesize, scale=1.0]
  \definecolor{acc}{HTML}{4A6FA5}
  % nested level curves
  \draw[black] plot[domain=-2.6:2.6, samples=60] (\x, {1.9 - 0.16*\x*\x});
  \draw[black] plot[domain=-2.6:2.6, samples=60] (\x, {0.9 - 0.16*\x*\x});
  \draw[black, thick] plot[domain=-2.6:2.6, samples=60] (\x, {-0.1 - 0.16*\x*\x});
  \node[black, anchor=west] at (2.0,1.55) {$f = c_2$};
  \node[black, anchor=west] at (2.0,-0.55) {$f = c_0$};
  % point on middle curve
  \def\px{-1.1}
  \pgfmathsetmacro\py{0.9 - 0.16*\px*\px}
  \fill[black] (\px,\py) circle (1.8pt);
  % gradient (normal, pointing up toward higher c)
  \draw[->, acc, very thick] (\px,\py) -- ({\px + 0.19*0.32*\px}, {\py + 0.95});
  \node[acc, anchor=east] at ({\px-0.05},{\py+0.7}) {grad $f$};
  % tangent along level curve
  \pgfmathsetmacro\tsl{-0.32*\px}
  \draw[black, thick] ({\px-0.9},{\py - 0.9*\tsl}) -- ({\px+0.9},{\py + 0.9*\tsl});
  \node[black, anchor=north] at (0.1,-0.75) {tangent to level curve};
  \node[acc, anchor=south] at (0,2.0) {toward higher values};
\end{tikzpicture}
$$

> **Worked example (unit normal to a sphere).** For $f(x, y, z) = x^2 + y^2 + z^2$
> and the level set $f = 3$, $\nabla f = (2x, 2y, 2z)$, so at $(1,1,1)$ the normal
> is $(2,2,2)$ and the unit normal is $\left( 1/\sqrt{3},\ 1/\sqrt{3},\
> 1/\sqrt{3} \right)$.

> **Worked example (tangent plane to a level surface).** For
> $f(x_1, x_2, x_3) = x_1^2 - x_2^2 + x_1 x_3 = 2$ at $x_0 = (1, 0, 1)$,
> $\nabla f(x_0) = (3, 0, 1)$, so the tangent plane is
> $3(x_1 - 1) + (x_3 - 1) = 0$, i.e. $3x_1 + x_3 = 4$.

## The mean value theorem in several variables

The one-variable
[mean value theorem](/real-analysis/differentiation/mean-value-theorem) —
$f(b) - f(a) = f'(c)(b - a)$ for some interior $c$ — does not carry over intact
to vector-valued maps.

> **Example (no single $c$ for vector output).** Let $f : \mathbb{R} \to
> \mathbb{R}^2$ be $f(x) = (x^2, x^3)$. A point $c \in (0,1)$ with
> $f(1) - f(0) = Df(c)$ would need $(1, 1) = (2c, 3c^2)$, forcing $2c = 1$ and
> $3c^2 = 1$ at once, which is impossible.

For a **scalar** field the theorem does hold, along the segment joining two
points. Call $c$ **between** $x$ and $y$ if $c = (1 - \lambda) x + \lambda y$ for
some $\lambda \in [0, 1]$.

> **Theorem (Mean value theorem for scalar fields).** Let $f : A \subseteq
> \mathbb{R}^n \to \mathbb{R}$ be differentiable on an open set $A$, and suppose
> the segment joining $x$ and $y$ lies in $A$. Then there is a point $c$ on that
> segment with
>
> $$
> f(y) - f(x) = Df(c)\,(y - x).
> $$

> **Proof.** Set $h(t) = f\bigl((1 - t) x + t y\bigr)$ on $[0, 1]$. By the chain rule
> $h$ is differentiable with $h'(t) = Df((1-t)x + ty)\,(y - x)$. The one-variable
> mean value theorem gives $t_0 \in (0,1)$ with $h(1) - h(0) = h'(t_0)$; since
> $h(1) = f(y)$ and $h(0) = f(x)$, take $c = (1 - t_0) x + t_0 y$. $\blacksquare$

The segment must actually lie inside $A$, which is guaranteed when $A$ is
**convex**: every segment between two of its points stays in the set. A useful
consequence: on a convex open set, $Df = 0$ everywhere forces $f$ to be constant,
because each component satisfies $f_j(y) - f_j(x) = Df_j(c_j)(y - x) = 0$. This is
the several-variable version of "zero derivative means constant," and it needs the
convexity hypothesis to connect the points.

$$
% caption: The theorem needs the whole segment from $x$ to $y$ inside the domain;
% a convex set contains it, and on a non-convex set the segment can escape.
\begin{tikzpicture}[>=stealth, font=\footnotesize, scale=1.0]
  \definecolor{acc}{HTML}{4A6FA5}
  \begin{scope}
    \draw[black, fill=acc!8] (0,0) ellipse (1.5 and 1.15);
    \node[black, anchor=south] at (0,1.2) {convex};
    \fill[black] (-1.0,-0.4) circle (1.5pt);
    \node[black, anchor=north east] at (-0.9,-0.35) {x};
    \fill[black] (1.05,0.5) circle (1.5pt);
    \node[black, anchor=south west] at (1.22,0.66) {y};
    \draw[acc, thick] (-1.0,-0.4) -- (1.05,0.5);
    \fill[acc] (0.02,0.05) circle (1.6pt);
    \node[acc, anchor=north west] at (0.06,0.02) {c};
  \end{scope}
  \begin{scope}[xshift=5cm]
    \draw[black, fill=acc!8] (0,0) .. controls (0.4,1.5) and (2.6,1.5) .. (3.0,0)
      .. controls (2.3,0.78) and (0.7,0.78) .. (0,0) -- cycle;
    \node[black, anchor=south] at (1.5,1.15) {non-convex};
    \fill[black] (0.32,0.14) circle (1.5pt);
    \node[black, anchor=east] at (0.28,0.16) {x};
    \fill[black] (2.68,0.14) circle (1.5pt);
    \node[black, anchor=west] at (2.72,0.16) {y};
    \draw[black, thick, dashed] (0.32,0.14) -- (2.68,0.14);
    \node[black, anchor=north] at (1.5,0.12) {segment escapes};
  \end{scope}
\end{tikzpicture}
$$

For vector-valued $f : \mathbb{R}^n \to \mathbb{R}^m$ the theorem holds in
componentwise form: there are points $c_1, \dots, c_m$ on the segment (one per
component, not a single shared $c$) with
$f_j(y) - f_j(x) = Df_j(c_j)(y - x)$.

| Statement | Scalar field $f : \mathbb{R}^n \to \mathbb{R}$ | Vector map $f : \mathbb{R}^n \to \mathbb{R}^m$ |
| --- | --- | --- |
| one shared point $c$ | yes, on the segment | no (the $(x^2, x^3)$ example) |
| componentwise, one $c_j$ each | trivially (single component) | yes |
| $Df = 0$ on convex open set $\Rightarrow$ constant | yes | yes |

The vanishing of $\nabla f$ at a critical point is classified by the second
derivative, through the
[Hessian and Taylor's theorem](/real-analysis/several-variables/higher-derivatives-taylor-extrema).[^sh-grad]

[^sh-grad]: **Shkoller**, _MAT125B Lecture Notes_, §2.6 (directional derivative, Definition 2.23, and Example 2.24), §2.7 (chain rule Theorem 2.27 and product rule Theorem 2.31), §2.8 (geometry of the gradient), and §2.9 (mean value theorem for scalar fields, Theorem 2.37, and the vector-valued failure).
