---
title: Vector identities
heading: The rules for combining gradient, divergence and curl
eyebrow: A9 · Lesson 35 · Vector identities
xp: 40
---

::: hook
Gradient, divergence and curl are three different derivatives, and they combine in a handful of identities that carry most of field theory. Two say that certain combinations always vanish: a gradient never curls, and a curl never diverges. Those two facts are why a static electric field can have a potential, why a magnetic field has no sources, and why charge is conserved. A third, the curl of a curl, is the step that turns Maxwell's equations into the wave equation for light.
:::

::: play
- The field is $\mathbf{F} = \alpha(x, y) + \beta(-y, x)$: a mixture of a pure gradient (spreading out from the origin) and a pure rotation.
- The readouts give its divergence and curl, which are constant everywhere: $2\alpha$ and $2\beta$.
- Set $\beta = 0$: the field is a gradient, and its curl is zero. Set $\alpha = 0$: it's a pure rotation, a curl of something, and its divergence is zero.
:::

```sim plot
view: flow
x: x = -2..2
y: y = -2..2
slider: al = -1..1 step 0.1 = 0.5
slider: be = -1..1 step 0.1 = 0.5
dx: al*x - be*y
dy: al*y + be*x
start: 0.3, 0 | forward
start: -0.3, 0.2 | forward
start: 0, -0.4 | forward
grid: 14
readout: divergence = 2*al | digits: 3
readout: curl = 2*be | digits: 3
```

::: predict
## For any smooth scalar function $f$, what is $\nabla\times(\nabla f)$?

- [ ] It depends on $f$
- [x] Always the zero vector
- [ ] Always $\nabla^2f$
- [ ] Always $\nabla f$

::: reveal
Always zero. Each component of $\nabla\times\nabla f$ is a difference of mixed partials, like $\frac{\partial^2f}{\partial x\,\partial y} - \frac{\partial^2f}{\partial y\,\partial x}$, and mixed partials of a smooth function are equal. Physically: walking around any closed loop on a hill, you end at the height you started, so a gradient field does no net work around a loop and has no circulation.
:::
:::

::: nameit
## Second derivatives that vanish

$$\nabla\times(\nabla f) = \mathbf 0, \qquad \nabla\cdot(\nabla\times\mathbf{A}) = 0$$

and, for fields defined on all of space (or any region without holes), the converses hold:
- a field with zero curl is a gradient, so a static $\mathbf E$ (with $\nabla\times\mathbf E = 0$) has a potential, $\mathbf E = -\nabla V$;
- a field with zero divergence is a curl, so $\nabla\cdot\mathbf B = 0$ means $\mathbf B = \nabla\times\mathbf A$.

## Product rules

$$\nabla\cdot(f\mathbf{F}) = f\,\nabla\cdot\mathbf{F} + \mathbf{F}\cdot\nabla f$$
$$\nabla\times(f\mathbf{F}) = f\,\nabla\times\mathbf{F} + \nabla f\times\mathbf{F}$$
$$\nabla\cdot(\mathbf{E}\times\mathbf{H}) = \mathbf{H}\cdot(\nabla\times\mathbf{E}) - \mathbf{E}\cdot(\nabla\times\mathbf{H})$$

The last one is the start of Poynting's theorem: energy flowing out of a region equals what the fields inside give up.

## Curl of a curl

$$\nabla\times(\nabla\times\mathbf{F}) = \nabla(\nabla\cdot\mathbf{F}) - \nabla^2\mathbf{F}$$

where $\nabla^2\mathbf F$ takes the Laplacian of each component. In empty space $\nabla\cdot\mathbf E = 0$, so taking the curl of Faraday's law and substituting Ampère–Maxwell gives $\nabla^2\mathbf E = \mu_0\varepsilon_0\frac{\partial^2\mathbf E}{\partial t^2}$: a wave at speed $\frac{1}{\sqrt{\mu_0\varepsilon_0}}$.

## Charge conservation from $\nabla\cdot\nabla\times = 0$

Taking the divergence of Ampère–Maxwell, $\nabla\times\mathbf H = \mathbf J + \frac{\partial\mathbf D}{\partial t}$, the left side vanishes, leaving $\nabla\cdot\mathbf J + \frac{\partial\rho}{\partial t} = 0$: the field equations force charge to be conserved.
:::

::: example
## Check $\nabla\times(\nabla f) = \mathbf 0$ for $f = x^2y$.

::: solution
1. **Gradient.**
   $$\nabla f = (2xy, x^2, 0)$$
2. **The curl's $z$ component.**
   $$\begin{aligned} &\frac{\partial}{\partial x}(x^2) - \frac{\partial}{\partial y}(2xy) \\ &= 2x - 2x \\ &= 0 \end{aligned}$$
3. **The other components.** They vanish because nothing depends on $z$ and there's no $z$ component.
4. **Interpret.** So $\nabla f$ is curl-free, and the work it does between two points is the change in $f$, whatever the path.

**Answer:** every component of $\nabla\times(\nabla f)$ is 0, as the identity says.
:::
:::

::: example
## Find $\nabla\cdot(r^2\mathbf{r})$, where $\mathbf r = (x, y, z)$ and $r^2 = x^2 + y^2 + z^2$.

::: solution
1. **Use the product rule.** With $f = r^2$ and $\mathbf F = \mathbf r$:
   $$\nabla\cdot\mathbf r = 3, \quad \nabla r^2 = 2\mathbf r$$
2. **Combine.**
   $$\begin{aligned} \nabla\cdot(r^2\mathbf r) &= r^2 \cdot 3 + \mathbf r\cdot 2\mathbf r \\ &= 3r^2 + 2r^2 \\ &= 5r^2 \end{aligned}$$
3. **Check directly.**
   $$\frac{\partial}{\partial x}(xr^2) = r^2 + 2x^2$$
   and adding the three components gives $3r^2 + 2r^2$, the same.

**Answer:** $\nabla\cdot(r^2\mathbf r) = 5r^2$.
:::
:::

::: example
## Check the curl-of-curl identity for $\mathbf F = (0, x^2, 0)$.

::: solution
1. **Left side: curl twice.**
   $$\nabla\times\mathbf F = (0, 0, 2x)$$
   and its curl is $(0, -2, 0)$, since $\frac{\partial(2x)}{\partial x} = 2$ enters the $y$ component with a minus sign.
2. **Right side: the divergence term.**
   $$\begin{aligned} \nabla\cdot\mathbf F &= \frac{\partial(x^2)}{\partial y} \\ &= 0 \end{aligned}$$
   so $\nabla(\nabla\cdot\mathbf F) = \mathbf 0$.
3. **Right side: the Laplacian term.**
   $$\nabla^2\mathbf F = (0, 2, 0)$$
4. **Compare.**
   $$\mathbf 0 - (0, 2, 0) = (0, -2, 0)$$

**Answer:** both sides equal $(0, -2, 0)$, so the identity holds.
:::
:::

::: check
given: a = 2 | 3; b = 1 | 4; x = 1 | 2
answer: 3*a*b*x^2
tolerance: 0.5%

## Use the product rule for $f = \given{a}x^2$ and $\mathbf F = (\given{b}x, 0, 0)$. What is $\nabla\cdot(f\mathbf F)$ at $x$ = {x}?

::: right
Right. $f\,\nabla\cdot\mathbf F + \mathbf F\cdot\nabla f = ax^2 \cdot b + bx \cdot 2ax = 3abx^2$ = {answer}.
:::

::: misses
- [a*b*x^2] That's only $f\,\nabla\cdot\mathbf F$; add $\mathbf F\cdot\nabla f$.
- [2*a*b*x^2] That's only $\mathbf F\cdot\nabla f$; add $f\,\nabla\cdot\mathbf F$.
- [any] Not yet. $\nabla\cdot(f\mathbf F) = f\,\nabla\cdot\mathbf F + \mathbf F\cdot\nabla f$.
:::
:::

::: check
given: k = 2 | 3 | 5
answer: (k + 3)
tolerance: 0.5%

## What is $\nabla\cdot(r^{\given{k}}\mathbf r)$ divided by $r^{\given{k}}$?

::: right
Right. $r^k \cdot 3 + \mathbf r\cdot kr^{k-2}\mathbf r = (k + 3)r^k$, so the ratio is {answer}.
:::

::: misses
- [3] Include the term $\mathbf r\cdot\nabla r^k = kr^k$.
- [k] Include $r^k\nabla\cdot\mathbf r = 3r^k$.
- [any] Not yet. Use $\nabla r^k = kr^{k-2}\mathbf r$.
:::
:::

::: check
kind: choice

## Which of these must be zero for every smooth field?

- [ ] $\nabla\cdot(\nabla f)$
- [x] $\nabla\cdot(\nabla\times\mathbf A)$
- [ ] $\nabla\times(\nabla\times\mathbf A)$
- [ ] $\nabla(\nabla\cdot\mathbf A)$

::: right
Right. The divergence of a curl always vanishes; that's why $\nabla\cdot\mathbf B = 0$ follows from $\mathbf B = \nabla\times\mathbf A$.
:::

::: misses
- [1] That's the Laplacian $\nabla^2f$, which is zero only for harmonic functions.
- [3] The curl of a curl is $\nabla(\nabla\cdot\mathbf A) - \nabla^2\mathbf A$, usually not zero.
- [4] The gradient of a divergence is usually nonzero.
:::
:::

::: check
given: k = 2 | 3; a = 2 | 5
answer: k^2*a
tolerance: 0.5%

## A wave has $E_x = \given{a}\cos(kz - \omega t)$ with $k$ = {k} rad/m. What is $|\nabla^2E_x|$ at a crest, where the cosine is 1?

::: right
Right. $\nabla^2E_x = -k^2a\cos(kz - \omega t)$, of size $k^2a$ = {answer} at a crest.
:::

::: misses
- [k*a] Two derivatives bring $k^2$.
- [any] Not yet. Differentiate twice with respect to $z$.
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 3 | 4

## Take $\mathbf F = (\given{a}x - \given{b}y, \given{a}y + \given{b}x, 0)$.

::: part
answer: 2*a
tolerance: 0.5%

### What is $\nabla\cdot\mathbf F$?

::: misses
- [a] Both $\frac{\partial F_x}{\partial x}$ and $\frac{\partial F_y}{\partial y}$ are $a$.
- [any] Add the two diagonal derivatives.
:::
:::

::: part
answer: 2*b
tolerance: 0.5%

### What is the $z$ component of $\nabla\times\mathbf F$?

::: misses
- [any] $\frac{\partial F_y}{\partial x} - \frac{\partial F_x}{\partial y} = b - (-b)$.
:::
:::
:::

::: check
kind: derivation
vars: x = -2..2, y = -2..2, z = -2..2

## Take $\mathbf A = (yz, xz, xy)$ and find the $x$ component of its curl.

::: step
answer: x

### What is $\frac{\partial A_z}{\partial y}$?
:::

::: step
answer: x

### What is $\frac{\partial A_y}{\partial z}$?
:::

::: right
Right. They cancel, and so do the other components: $\mathbf A = \nabla(xyz)$ is a gradient, so its curl is zero.
:::
:::

::: check
kind: python

## On a 101 × 101 grid over $[0, 2]^2$, compute $\nabla f$ for $f = y^2\sin x$ with `np.gradient`, then the $z$ component of the curl of that gradient. Set `worst` to its largest size at interior points (away from the two outermost rows and columns).

```python starter
import numpy as np

worst = 1.0
print(worst)
```

```python solution
import numpy as np

x = np.linspace(0, 2, 101)
h = x[1] - x[0]
X, Y = np.meshgrid(x, x, indexing="ij")
f = Y**2 * np.sin(X)
fx = np.gradient(f, h, axis=0)
fy = np.gradient(f, h, axis=1)
curl = np.gradient(fy, h, axis=0) - np.gradient(fx, h, axis=1)
worst = np.max(np.abs(curl[2:-2, 2:-2]))
print(worst)
```

```python tests
assert worst < 1e-9, f"The curl of a gradient vanishes; on a uniform grid the differences commute too; got {worst}."
```

::: right
Right. Central differences in $x$ and $y$ commute on a uniform grid, so the discrete identity holds to rounding, just like the continuous one.
:::
:::

::: explain
## Why does the identity $\nabla\cdot(\nabla\times\mathbf H) = 0$ force electric charge to be conserved?

::: model
Ampère–Maxwell says $\nabla\times\mathbf H = \mathbf J + \frac{\partial\mathbf D}{\partial t}$. The left side is a curl, and the divergence of any curl is zero, so the divergence of the right side must be zero too: $\nabla\cdot\mathbf J + \frac{\partial}{\partial t}\nabla\cdot\mathbf D = 0$. Gauss's law replaces $\nabla\cdot\mathbf D$ by $\rho$, leaving $\nabla\cdot\mathbf J + \frac{\partial\rho}{\partial t} = 0$: current flowing out of any point must be matched by charge there decreasing. Maxwell added the displacement current partly because, without it, Ampère's law contradicted this for a charging capacitor.
:::
:::

::: practice

::: check
given: k = -2..6 int
answer: k + 3
tolerance: 0.5%

## $\nabla\cdot(r^{\given{k}}\mathbf r)/r^{\given{k}}$?

::: misses
- [any] $k + 3$.
:::
:::

::: check
given: a = -2..2; b = -2..2
answer: 2*b
tolerance: 0.5%

## Curl of $(\given{a}x - \given{b}y, \given{a}y + \given{b}x, 0)$, $z$ component?

::: misses
- [any] $2b$.
:::
:::
:::
