---
title: The divergence theorem and Gauss's law
heading: Finding a field from the charge inside
eyebrow: A9 · Lesson 41 · Gauss's law
xp: 50
---

::: hook
How strong is the electric field 20 cm from a charged ball, or 1 cm from a charged wire, or just above a charged plate? Adding up the field of every bit of charge (lesson 14's integrals in three dimensions) is hard work. When the charge is arranged symmetrically, there's a shortcut: the divergence theorem turns Maxwell's first equation, $\nabla\cdot\mathbf{E} = \rho/\varepsilon_0$, into **Gauss's law**, which says the flux out of any closed surface depends only on the charge inside it. Pick a surface that matches the symmetry and the field falls out in one line.
:::

::: play
- A ball of radius $R$ holds charge $Q$ spread evenly through it. The curve is the field strength against distance from the center.
- Inside, the field grows in a straight line; outside, it falls as $1/r^2$. Where is it strongest?
- Change $R$ with $Q$ fixed. The outside field doesn't change at all. Why not?
:::
:::

```sim plot
view: graph
x: r = 0..0.4 m
y: E = 0..1500 V/m
slider: Q = 0.2..2 step 0.1 = 1 nC
slider: R = 0.05..0.2 step 0.01 = 0.1 m
plot: 8.988*Q*(r/R^3*(1 - step(r - R)) + step(r - R)/r^2) | label: field strength | samples: 1000
marker: x = R | label: surface
readout: field at the surface, V/m = 8.988*Q/R^2 | digits: 4
```

::: predict
## A charged ball of radius 10 cm is shrunk to 5 cm with the same total charge. What happens to the field 20 cm from its center?

- [ ] It quadruples
- [ ] It doubles
- [x] Nothing
- [ ] It halves

::: reveal
Nothing. A sphere of radius 20 cm encloses all the charge either way, and by symmetry the field is the same size everywhere on it, so $E \times 4\pi r^2 = Q/\varepsilon_0$ gives the same $E$. Outside, any spherically symmetric charge looks like a point charge at the center.
:::
:::

::: nameit
## The divergence theorem

For a closed surface $S$ enclosing a volume $V$, with outward normal:

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

Net outflow through the boundary equals the total of the sources inside (lesson 37).

## Gauss's law

With Maxwell's equation $\nabla\cdot\mathbf{E} = \rho/\varepsilon_0$:

$$\oint_S\mathbf{E}\cdot d\mathbf{A} = \frac{Q_\text{enc}}{\varepsilon_0}$$

## Using symmetry

Choose a **Gaussian surface** on which $\mathbf{E}$ is perpendicular and of constant size, so the flux is just $E \times$ area:

| Charge | Surface | Field |
|---|---|---|
| point or sphere, total $Q$ | sphere of radius $r$ | $E = \frac{Q}{4\pi\varepsilon_0r^2}$ outside |
| uniform ball, radius $R$ | sphere inside, $r < R$ | $E = \frac{Qr}{4\pi\varepsilon_0R^3}$ |
| line, $\lambda$ per meter | cylinder of radius $r$ | $E = \frac{\lambda}{2\pi\varepsilon_0r}$ |
| sheet, $\sigma$ per m² | pillbox through it | $E = \frac{\sigma}{2\varepsilon_0}$ each side |

With $\frac{1}{4\pi\varepsilon_0} = 8.988 \times 10^9$ N·m²/C², a nanocoulomb gives about 9 V/m at 1 m.

## Conservation of charge

Applied to current density $\mathbf{J}$, the same theorem says the current out of a closed surface equals the rate at which the charge inside falls: $\oint\mathbf{J}\cdot d\mathbf{A} = -\frac{dQ}{dt}$, or in differential form the **continuity equation**

$$\frac{\partial\rho}{\partial t} + \nabla\cdot\mathbf{J} = 0$$

which is the field version of Kirchhoff's current law.
:::

::: example
## A ball of radius 10 cm holds 1 nC uniformly. Find the field at 20 cm and at 5 cm from the center.

::: solution
1. **Outside, at 20 cm.** The whole charge counts:
   $$\begin{aligned} E &= \frac{kQ}{r^2} \\ &= \frac{8.988 \times 10^9 \times 10^{-9}}{0.04} \\ &= 225\ \text{V/m} \end{aligned}$$
2. **Inside, at 5 cm.** Only the charge within 5 cm counts, a fraction $(0.5)^3$ of it:
   $$\begin{aligned} E &= \frac{kQr}{R^3} \\ &= \frac{8.988 \times 0.05}{0.001} \\ &= 449\ \text{V/m} \end{aligned}$$

**Answer:** 225 V/m at 20 cm and 449 V/m at 5 cm.
:::
:::

::: example
## A long wire carries 1 nC/m. How strong is the field 1 cm away?

::: solution
1. **Field of a line charge.**
   $$\begin{aligned} E &= \frac{\lambda}{2\pi\varepsilon_0r} \\ &= \frac{2k\lambda}{r} \\ &= \frac{2 \times 8.988 \times 10^9 \times 10^{-9}}{0.01} \\ &= 1800\ \text{V/m} \end{aligned}$$
2. **Note how it falls.** It falls as $1/r$, slower than a point charge's $1/r^2$.

**Answer:** 1800 V/m at 1 cm.
:::
:::

::: example
## A large flat sheet carries 1 nC/m². What field does it make?

::: solution
1. **Choose a pillbox.** Take a pillbox straddling the sheet, with faces of area $A$.
2. **Use the symmetry.** The field is perpendicular to the sheet and equal on both sides, so the flux is $2EA$ and the enclosed charge is $\sigma A$.
3. **Solve for the field.**
   $$\begin{aligned} E &= \frac{\sigma}{2\varepsilon_0} \\ &= \frac{10^{-9}}{2 \times 8.854 \times 10^{-12}} \\ &= 56.5\ \text{V/m} \end{aligned}$$
4. **Note what's missing.** It doesn't depend on the distance from the sheet. Two oppositely charged sheets, a capacitor, double it between them and cancel it outside.

**Answer:** 56.5 V/m, the same at any distance from the sheet.
:::
:::

::: check
given: Q = 1 | 5; r = 0.1 | 0.5
answer: 8.988e9*Q*1e-9/r^2
unit: V/m
tolerance: 0.5%

## A sphere carries {Q} nC. How strong is the field {r} m from its center, outside it?

::: right
Right. $\frac{kQ}{r^2}$ = {answer}.
:::

::: misses
- [8.988e9*Q*1e-9/r] A point charge's field falls as $1/r^2$.
- [any] Not yet. $E \times 4\pi r^2 = Q/\varepsilon_0$.
:::
:::

::: check
given: Q = 2 | 4; R = 0.1 | 0.2; f = 0.25 | 0.5
answer: 8.988e9*Q*1e-9*(f*R)/R^3
unit: V/m
tolerance: 0.5%

## A ball of radius {R} m holds {Q} nC uniformly. How strong is the field at {f} of the way from the center to the surface?

::: right
Right. Inside, $E = \frac{kQr}{R^3}$ = {answer}.
:::

::: misses
- [8.988e9*Q*1e-9/(f*R)^2] Inside, only the enclosed charge counts.
- [any] Not yet. The enclosed charge is $Q(r/R)^3$.
:::
:::

::: check
given: l = 1 | 3; r = 0.01 | 0.05
answer: 2*8.988e9*l*1e-9/r
unit: V/m
tolerance: 0.5%

## A long wire carries {l} nC/m. How strong is the field {r} m away?

::: right
Right. $\frac{2k\lambda}{r}$ = {answer}.
:::

::: misses
- [8.988e9*l*1e-9/r^2] A line charge's field falls as $1/r$.
- [8.988e9*l*1e-9/r] It's $\frac{\lambda}{2\pi\varepsilon_0r} = \frac{2k\lambda}{r}$: include the 2.
- [any] Not yet. Use a cylindrical Gaussian surface.
:::
:::

::: check
given: s = 1..20 int
answer: s*1e-9/(2*8.854e-12)
unit: V/m
tolerance: 0.5%

## A large flat sheet carries {s} nC/m². How strong is the field near it?

::: right
Right. $\frac{\sigma}{2\varepsilon_0}$ = {answer}, the same at any distance.
:::

::: misses
- [s*1e-9/8.854e-12] The flux leaves through both faces of the pillbox: $\frac{\sigma}{2\varepsilon_0}$.
- [any] Not yet. A pillbox through the sheet.
:::
:::

::: check
given: q1 = 2 | 5; q2 = -1 | 3
answer: (q1 + q2)*1e-9/8.854e-12
unit: V·m
tolerance: 0.5%

## A closed surface surrounds charges of {q1} nC and {q2} nC. What is the electric flux out of it?

::: right
Right. $\frac{Q_\text{enc}}{\varepsilon_0}$ = {answer}, whatever the surface's shape.
:::

::: misses
- [q1*1e-9/8.854e-12] Count every enclosed charge, including the second.
- [any] Not yet. Gauss's law.
:::
:::

::: check
given: d = 1..20 int
answer: -d

## In a region, $\nabla\cdot\mathbf{J}$ = {d} A/m³. At what rate is the charge density changing, in C/(m³·s)?

::: right
Right. $\frac{\partial\rho}{\partial t} = -\nabla\cdot\mathbf{J}$ = {answer}: current flowing out of a point drains its charge.
:::

::: misses
- [d] More current leaving means the charge falls.
- [any] Not yet. The continuity equation.
:::
:::

::: check
kind: parts
given: s = 1 | 5; d = 0.5 | 2

## A large sheet carries {s} nC/m².

::: part
answer: s*1e-9/(2*8.854e-12)
unit: V/m
tolerance: 0.5%

### What field does it make?

::: misses
- [s*1e-9/8.854e-12] That's the field between two opposite sheets; one sheet gives half.
- [any] $E = \frac{\sigma}{2\varepsilon_0}$.
:::
:::

::: part
answer: s*1e-9/(2*8.854e-12)*d/100
unit: V
tolerance: 0.5%

### What voltage appears across {d} cm of it?

::: misses
- [any] The field is uniform: $V = Ed$.
:::
:::
:::

::: check
kind: derivation
vars: Q = 0.1..10, R = 0.05..0.5, r = 0.01..0.04

## A ball of radius $R$ (m) holds charge $Q$ (nC) uniformly. Find the field inside at radius $r < R$.

::: step
answer: Q*r^3/R^3

### How much charge (nC) is enclosed within radius $r$?
:::

::: step
answer: 8.988*Q*r/R^3

### What is $E$ in V/m? (Use $\frac{1}{4\pi\varepsilon_0} = 8.988 \times 10^9$, so $kQ_\text{enc}/r^2$ with $Q$ in nC gives $8.988\,Q_\text{enc}/r^2$.)
:::

::: right
Right. Inside, the field grows linearly with $r$; outside, it falls as $1/r^2$.
:::
:::

::: check
kind: python

## A ball of radius 10 cm holds 1 nC uniformly. Write `E(r)` that finds the enclosed charge by adding 10 000 thin shells out to $\min(r, R)$, then applies Gauss's law, $E = \frac{kQ_\text{enc}}{r^2}$. Set `e5` and `e20` for $r$ = 5 cm and 20 cm.

```python starter
import numpy as np

def E(r):
    return 0.0

e5, e20 = E(0.05), E(0.2)
print(e5, e20)
```

```python solution
import numpy as np

k, Q, R = 8.988e9, 1e-9, 0.1
rho = Q / (4 / 3 * np.pi * R**3)

def E(r):
    top = min(r, R)
    s = (np.arange(10000) + 0.5) * top / 10000
    q = np.sum(rho * 4 * np.pi * s**2) * top / 10000
    return k * q / r**2

e5, e20 = E(0.05), E(0.2)
print(e5, e20)
```

```python tests
assert abs(e5 - 8.988e9 * 1e-9 * 0.05 / 0.1**3) < 1e-3, f"Inside, E = kQr/R^3 = 449.4 V/m at 5 cm; got {e5}."
assert abs(e20 - 8.988e9 * 1e-9 / 0.2**2) < 1e-3, f"Outside, E = kQ/r^2 = 224.7 V/m at 20 cm; got {e20}."
```

::: right
Right. The field rises linearly inside and falls as $1/r^2$ outside, peaking at the surface.
:::
:::

::: explain
## Why can't Gauss's law alone give the field of a charged cube, when it gives the field of a charged sphere so easily?

::: model
Gauss's law always holds, but it only gives the total flux through a surface. To turn that into the field, you need a surface on which the field is perpendicular and has the same size everywhere, so that the flux is just $E$ times the area. A sphere around a spherical charge has that by symmetry. A cube's field varies in size and direction over any simple surface around it, so knowing the total flux doesn't tell you the field at each point. You'd have to integrate Coulomb's law instead.
:::
:::

::: practice

::: check
given: Q = 1..20 int
answer: 8.988e9*Q*1e-9
unit: V/m
tolerance: 0.5%

## How strong is the field 1 m from a point charge of {Q} nC?

::: misses
- [any] $kQ/r^2$ with $r$ = 1 m.
:::
:::

::: check
given: Q = 2 | 6; R = 0.1 | 0.3
answer: 8.988e9*Q*1e-9/R^2
unit: V/m
tolerance: 0.5%

## Where is the field of a uniformly charged ball strongest, and how strong is it? Give the value for {Q} nC and radius {R} m.

::: misses
- [any] At the surface: $kQ/R^2$.
:::
:::

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

## What is the electric flux out of a cube that contains a {Q} nC point charge anywhere inside it?

::: misses
- [any] $Q/\varepsilon_0$.
:::
:::
:::
