---
title: Gauss's and Stokes's theorems
heading: What the boundary knows about the inside
eyebrow: A9 · Lesson 37 · Gauss's and Stokes's theorems
xp: 50
---

::: hook
Divergence and curl are measured at points. Flux and circulation are measured around whole regions. Two theorems connect them: add up the divergence over a region and you get the flux out of its boundary; add up the curl over a surface and you get the circulation around its edge. With them, Maxwell's equations can be written either way, and in the integral form they let you find the field of a charge or a wire in two lines.

::: play
- The field here has divergence and curl both equal to $x^2 + y^2$. The circle has center $(a, b)$ and radius $R$; the sim measures the flux out of it and the circulation around it.
- The third readout adds up $x^2 + y^2$ over the disk inside the circle, from a formula. Compare all three as you move and resize the circle.
- Make the circle tiny. What happens to all three numbers, and why?
:::
:::

```sim plot
view: flow
x: x = -2..2
y: y = -2..2
slider: a = -1..1 step 0.1 = 0.3
slider: b = -1..1 step 0.1 = 0
slider: R = 0.1..1 step 0.05 = 0.8
dx: x^3/3 - y^3/3
dy: x^3/3 + y^3/3
arrows: scaled
grid: 14
shade: x^2 + y^2 | contours: 6 | scale: 8
path: a + R*cos(u), b + R*sin(u) | over: u = 0..2*pi | flux: P | work: W
readout: flux out = P
readout: circulation = W
readout: ∬(x² + y²) dA = pi*R^4/2 + pi*R^2*(a^2 + b^2)
```

::: predict
## Fill a region with tiny boxes and add up the flux out of every one. Why does the total equal the flux out of the region's outer boundary?

- [ ] Because the boxes are tiny
- [x] Because every inner face is shared by two boxes, and its flux counts out of one and into the other
- [ ] Because the field is zero inside
- [ ] It doesn't: the inner faces add extra flux

::: reveal
Every inner face belongs to two neighboring boxes. Flux leaving one box through that face enters the other, so in the total it counts once as $+$ and once as $-$, and cancels. Only the outer faces, which have no neighbor, survive. And each tiny box's flux is its divergence times its volume, so the total divergence inside equals the flux out of the boundary. The same cancellation, applied to circulation around tiny loops, gives Stokes's theorem.
:::
:::

::: nameit
## The two theorems

**The divergence theorem** (Gauss's theorem). For a region $V$ with closed boundary surface $S$, normal pointing out:

$$\oint_S \mathbf{F} \cdot d\mathbf{A} = \iiint_V \nabla \cdot \mathbf{F}\ dV$$

**Stokes's theorem.** For a surface $S$ with boundary curve $C$, traveled so the surface is on your left when your head points along the normal:

$$\oint_C \mathbf{F} \cdot d\mathbf{r} = \iint_S (\nabla \times \mathbf{F}) \cdot d\mathbf{A}$$

Both come from the same picture: cut the inside into tiny pieces, use the definition of divergence or curl on each piece, and notice that everything shared between neighbors cancels. In the plane, Stokes's theorem is called **Green's theorem**: $\oint (F_x\,dx + F_y\,dy) = \iint (\partial_x F_y - \partial_y F_x)\,dA$.

**Maxwell's equations both ways:**

| Law | At a point | Around a region |
|---|---|---|
| Gauss | $\nabla \cdot \mathbf{E} = \rho/\varepsilon_0$ | $\oint \mathbf{E} \cdot d\mathbf{A} = Q_\text{inside}/\varepsilon_0$ |
| no magnetic charge | $\nabla \cdot \mathbf{B} = 0$ | $\oint \mathbf{B} \cdot d\mathbf{A} = 0$ |
| Faraday | $\nabla \times \mathbf{E} = -\partial\mathbf{B}/\partial t$ | $\oint \mathbf{E} \cdot d\mathbf{l} = -d\Phi_B/dt$ |
| Ampère (steady) | $\nabla \times \mathbf{B} = \mu_0\mathbf{J}$ | $\oint \mathbf{B} \cdot d\mathbf{l} = \mu_0 I_\text{through}$ |

**Using symmetry.** The integral forms find fields quickly when symmetry tells you the field's shape:

- **A point charge.** By symmetry E points straight out and has the same strength on any sphere around the charge. Gauss: $E \cdot 4\pi r^2 = Q/\varepsilon_0$, so $E = \dfrac{Q}{4\pi\varepsilon_0 r^2}$, which is $kQ/r^2$ with $k = 1/(4\pi\varepsilon_0)$.
- **A long straight wire.** B circles the wire with the same strength on any circle around it. Ampère: $B \cdot 2\pi r = \mu_0 I$, so $B = \dfrac{\mu_0 I}{2\pi r}$. That's 20 µT at 1 cm from a 1 A wire, about half of Earth's field.
:::

::: example
## Check the divergence theorem for $\mathbf{F} = (x, y, z)$ and a sphere of radius $R$.

::: solution
1. **Volume side.** $\nabla\cdot\mathbf{F} = 3$, so
   $$\begin{aligned} \iiint 3\,dV &= 3 \times \tfrac{4}{3}\pi R^3 \\ &= 4\pi R^3 \end{aligned}$$
2. **Surface side.** On the surface $\mathbf{F}$ points outward with size $R$, so the flux is
   $$\begin{aligned} \Phi &= R \times 4\pi R^2 \\ &= 4\pi R^3 \end{aligned}$$
3. **Compare.** They agree.

**Answer:** both sides give $4\pi R^3$.
:::
:::

::: example
## Check Stokes's theorem for $\mathbf{F} = (-y, x, 0)$ and the disk of radius $R$.

::: solution
1. **Flux of the curl.** The curl is $(0, 0, 2)$, so its flux through the disk is $2\pi R^2$.
2. **Circulation around the edge.** There $\mathbf{F}$ is tangent with size $R$, so
   $$\begin{aligned} \oint\mathbf{F}\cdot d\mathbf{l} &= R \times 2\pi R \\ &= 2\pi R^2 \end{aligned}$$

**Answer:** both sides give $2\pi R^2$.
:::
:::

::: example
## Find the flux of $\mathbf{F} = (x, y, z)$ out of a cylinder of radius 1 and height 2.

::: solution
1. **Use the divergence theorem.** The flux is the integral of $\nabla\cdot\mathbf{F} = 3$ over the volume, $\pi \times 1^2 \times 2 = 2\pi$:
   $$\begin{aligned} \Phi &= 3 \times 2\pi \\ &= 6\pi \\ &= 18.85 \end{aligned}$$
2. **Check the curved side directly.** There $\mathbf{F}\cdot\hat n = r = 1$ over area $4\pi$, giving $4\pi$.
3. **Check the ends.** If the cylinder runs from $z = -1$ to 1, the top and bottom each contribute $1 \times \pi$.
4. **Add them.** The total is $6\pi$.

**Answer:** the flux is $6\pi = 18.85$.
:::
:::

::: check
given: Q = 1..9 int
answer: Q*1e-9/8.854e-12
unit: V*m
tolerance: 1%

## A closed surface of any shape surrounds a {Q} nC charge. What is the total electric flux out of it?

::: right
Right. Gauss's law: $Q/\varepsilon_0$ = {answer}, whatever the surface's shape or size.
:::

::: misses
- [Q*1e-9*8.854e-12] Divide by $\varepsilon_0$.
- [Q*1e-9/(4*pi*8.854e-12)] That's $kQ$, the field times $r^2$. The total flux is $4\pi$ times that.
- [any] Not yet. $\oint \mathbf{E} \cdot d\mathbf{A} = Q/\varepsilon_0$.
:::
:::

::: check
given: I = 1..20 int; r = 1 | 2 | 5 | 10
answer: 4*pi*1e-7*I/(2*pi*r/100)
unit: T
tolerance: 0.5%

## How strong is the magnetic field {r} cm from a long straight wire carrying {I} A?

::: right
Right. Ampère's law around a circle: $B = \mu_0 I/(2\pi r)$ = {answer}.
:::

::: misses
- [4*pi*1e-7*I/(2*pi*r)] Convert {r} cm to meters.
- [4*pi*1e-7*I/(4*pi*(r/100)^2)] That's the shape of a point charge's field. A wire's field falls as $1/r$, from a circle of length $2\pi r$.
- [any] Not yet. $B \cdot 2\pi r = \mu_0 I$.
:::
:::

::: check
given: c = 2..9 int; L = 2 | 3 | 4
answer: c*L^3
tolerance: 0.5%

## A field has divergence {c} everywhere. What is the total flux out of a cube {L} m on a side?

::: right
Right. The divergence theorem: flux = $\iiint \nabla \cdot \mathbf{F}\,dV = \given{c} \times \given{L}^3$ = {answer}.
:::

::: misses
- [6*c*L^2] Use the volume, not the surface area: the divergence is per unit volume.
- [c*L^2] It's a cube: the volume is $L^3$.
- [any] Not yet. Multiply the divergence by the volume.
:::
:::

::: check
given: k = 1..9 int; R = 3 | 4 | 5
answer: 2*k*pi*R^2
tolerance: 0.5%

## A field has curl $2\given{k}$ everywhere (pointing out of the page). Use Stokes's theorem to find its circulation around a circle of radius {R}.

::: right
Right. Circulation = curl × area = $2\given{k} \times \pi\given{R}^2$ = {answer}.
:::

::: misses
- [k*pi*R^2] The curl is $2\given{k}$, not {k}.
- [2*k*2*pi*R] Multiply by the area enclosed, not the circumference.
- [any] Not yet. $\oint \mathbf{F} \cdot d\mathbf{r} = (\nabla \times \mathbf{F}) \times \text{area}$ when the curl is uniform.
:::
:::

::: check
kind: choice

## A closed surface has two charges outside it and none inside. What is the total electric flux out of it?

- [x] Zero
- [ ] The sum of the two charges divided by $\varepsilon_0$
- [ ] It depends on how close the charges are
- [ ] It can't be found without knowing the field

::: right
Right. Only charge inside counts. Field lines from the outside charges enter the surface and leave it again.
:::

::: misses
- [2] Only the charge inside the surface counts.
- [3] The field on the surface depends on that, but the total flux doesn't.
- [4] Gauss's law gives the total flux from the charge inside alone.
:::
:::

::: check
kind: parts
given: R = 1 | 2; h = 2 | 3

## Use the divergence theorem for $\mathbf{F} = (x, y, z)$ and a cylinder of radius {R} and height {h}.

::: part
answer: 3*pi*R^2*h
tolerance: 0.5%

### What is the outward flux?

::: misses
- [pi*R^2*h] Multiply by $\nabla\cdot\mathbf{F} = 3$.
- [any] $3 \times$ volume.
:::
:::
:::

::: check
kind: derivation
vars: R = 0.5..3

## Check Stokes's theorem for $\mathbf{F} = (-y, x, 0)$ on the disk of radius $R$.

::: step
answer: 2*pi*R^2

### What is $\oint\mathbf{F}\cdot d\mathbf{l}$ around the circle? ($|\mathbf{F}| = R$, parallel to the path.)
:::

::: step
answer: 2*pi*R^2

### What is $\iint(\nabla\times\mathbf{F})\cdot\hat z\,dA$, with curl 2?
:::

::: right
Right. Both are $2\pi R^2$, as Stokes's theorem says.
:::
:::

::: explain
## Using Ampère's law, explain why the magnetic field of a long straight wire falls off as $1/r$.

::: model
By symmetry the field circles the wire and has the same strength everywhere on a circle around it. Ampère's law says the field added up around any such circle equals $\mu_0$ times the current through it, which is the same current I for every circle. The circle's length grows as $2\pi r$, so to give the same total the field must shrink in proportion: $B = \mu_0 I/(2\pi r)$.
:::
:::

::: practice

::: check
given: Q1 = 1..9 int; Q2 = -9..-1 int
answer: (Q1 + Q2)*1e-9/8.854e-12
unit: V*m
tolerance: 1%

## A closed surface surrounds charges of {Q1} nC and {Q2} nC. What is the total flux out of it?

::: misses
- [(Q1 - Q2)*1e-9/8.854e-12] Add the charges with their signs.
- [any] $Q_\text{inside}/\varepsilon_0$.
:::
:::

::: check
given: Q = 1..9 int; r = 0.1 | 0.2 | 0.5 | 2
answer: Q*1e-9/(4*pi*8.854e-12*r^2)
unit: V/m
tolerance: 1%

## Using Gauss's law, how strong is the field {r} m from a {Q} nC point charge?

::: misses
- [Q*1e-9/(8.854e-12*r^2)] The sphere's area is $4\pi r^2$.
- [Q*1e-9/(4*pi*8.854e-12*r)] Divide by the area, which goes as $r^2$.
- [any] $E \cdot 4\pi r^2 = Q/\varepsilon_0$.
:::
:::

::: check
given: I1 = 2..9 int; I2 = 1 | 3 | 5
answer: 4*pi*1e-7*(I1 - I2)
unit: T*m
tolerance: 1%

## A loop encloses two wires, one carrying {I1} A up through it and one carrying {I2} A down. What is $\oint \mathbf{B} \cdot d\mathbf{l}$ around the loop?

::: misses
- [4*pi*1e-7*(I1 + I2)] The currents flow opposite ways: subtract.
- [any] $\mu_0$ times the net current through the loop.
:::
:::
:::
