---
title: The continuity equation
heading: Conservation of charge, written as a divergence
eyebrow: A9 · Lesson 40 · The continuity equation
xp: 40
---

::: hook
Charge is never created or destroyed: if it leaves a region, the charge inside goes down by exactly that much. Written with the divergence theorem, that becomes a statement about every point, $\frac{\partial\rho}{\partial t} + \nabla\cdot\mathbf J = 0$, the **continuity equation**. Kirchhoff's current law is its steady-state form. It also explains a surprising fact about conductors: any charge placed inside one flees to the surface, in a time set by the material's permittivity and conductivity, about $10^{-19}$ s for copper.
:::

::: play
- A charge density placed inside a material decays as $\rho_0e^{-t/\tau}$ with $\tau = \varepsilon/\sigma$, the **relaxation time**.
- Change the conductivity across fourteen orders of magnitude, from glass to copper. The relaxation time follows.
- The charge doesn't vanish: it moves to the surface, where the continuity equation no longer constrains it the same way.
:::

```sim plot
view: graph
x: t = 0..5
y: rho = 0..1.05
slider: lg = -12..8 step 0.5 = 0
slider: er = 1..81 step 1 = 5
plot: exp(-t) | label: ρ(t)/ρ₀, with t in units of τ
readout: conductivity, S/m = 10^lg | digits: 3
readout: relaxation time τ, s = er*8.854e-12/10^lg | digits: 4
```

::: predict
## Current flows into a small region at 3 mA and out at 5 mA. What happens to the charge inside?

- [ ] Nothing: current is conserved
- [x] It falls at 2 mC per second
- [ ] It rises at 2 mC per second
- [ ] It falls at 8 mC per second

::: reveal
It falls at 2 mC/s: net outflow is $5 - 3 = 2$ mA, and every coulomb that leaves comes from the charge inside. In a circuit node there's no room to store charge, so the outflow must be zero, which is KCL. A capacitor plate is a region where charge does build up, at a rate equal to the net current in.
:::
:::

::: nameit
## From the integral form to a point

Charge $Q$ in a volume changes only by what flows through its surface:

$$\frac{dQ}{dt} = -\oint\mathbf J\cdot d\mathbf A$$

With $Q = \int\rho\,dV$ and the divergence theorem, $\int\left(\frac{\partial\rho}{\partial t} + \nabla\cdot\mathbf J\right)dV = 0$ for every volume, so

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

## Steady currents

If nothing changes in time, $\nabla\cdot\mathbf J = 0$: current lines never start or stop. Integrated over a small volume around a circuit node, that's KCL: the currents in sum to zero.

## Charge relaxation

In a conductor, $\mathbf J = \sigma\mathbf E$ (Ohm's law at a point) and $\nabla\cdot\mathbf E = \rho/\varepsilon$ (Gauss). Substituting into the continuity equation:

$$\frac{\partial\rho}{\partial t} = -\frac\sigma\varepsilon\rho, \qquad \rho = \rho_0e^{-t/\tau}, \quad \tau = \frac\varepsilon\sigma$$

| Material | $\sigma$ (S/m) | $\varepsilon_r$ | $\tau$ |
|---|---|---|---|
| Copper | $5.8 \times 10^7$ | 1 | $1.5 \times 10^{-19}$ s |
| Seawater | 4 | 81 | 0.18 ns |
| Glass | about $10^{-12}$ | 5 | about 40 s |

Compared with a signal's period, a short $\tau$ makes a material a conductor and a long one makes it an insulator. Seawater conducts at radio frequencies but not at hundreds of gigahertz.

## The same law elsewhere

Any conserved quantity obeys the same form: heat (with $\mathbf J$ the heat flux), mass in a fluid, probability in quantum mechanics.
:::

::: example
## A current density $\mathbf J = (2x, 0, 0)$ A/m² flows in a region. How is the charge density changing?

::: solution
1. **Divergence of the current.**
   $$\nabla\cdot\mathbf J = 2\ \text{A/m}^3$$
2. **Apply continuity.**
   $$\frac{\partial\rho}{\partial t} = -2\ \text{C/(m³·s)}$$
   Charge is draining away everywhere at 2 C per cubic meter per second.
3. **Picture it.** The current grows with $x$, so more leaves each small box through its right face than enters through its left face.

**Answer:** the charge density is falling at 2 C/(m³·s) everywhere.
:::
:::

::: example
## Find the charge relaxation time of copper and of seawater.

::: solution
1. **Copper.**
   $$\begin{aligned} \tau &= \frac{\varepsilon_0}{\sigma} \\ &= \frac{8.854 \times 10^{-12}}{5.8 \times 10^7} \\ &= 1.5 \times 10^{-19}\ \text{s} \end{aligned}$$
2. **Seawater.**
   $$\begin{aligned} \tau &= \frac{81 \times 8.854 \times 10^{-12}}{4} \\ &= 1.8 \times 10^{-10}\ \text{s} \end{aligned}$$
3. **What copper's figure means.** It's shorter than any physical process can follow, so in practice charge inside a metal is always zero.
4. **What seawater's figure means.** Its 0.18 ns means it acts as a conductor for signals below a few gigahertz, which is why radio can't reach submarines at depth.

**Answer:** about $1.5 \times 10^{-19}$ s for copper and $1.8 \times 10^{-10}$ s (0.18 ns) for seawater.
:::
:::

::: example
## A sphere of glass ($\varepsilon_r$ = 5, $\sigma$ = $10^{-12}$ S/m) is charged internally. How long until 99% of the charge has moved to its surface?

::: solution
1. **Relaxation time.**
   $$\begin{aligned} \tau &= \frac{5 \times 8.854 \times 10^{-12}}{10^{-12}} \\ &= 44\ \text{s} \end{aligned}$$
2. **Time to reach 1% remaining.**
   $$\begin{aligned} t &= \tau\ln 100 \\ &= 4.6\tau \\ &= 204\ \text{s} \end{aligned}$$
   about three and a half minutes.
3. **Interpret.** Insulators hold charge where it's put on human time scales, which is why a rubbed balloon stays charged.

**Answer:** about 204 s, three and a half minutes.
:::
:::

::: check
given: er = 1 | 5 | 81; s = 0.001 | 4
answer: er*8.854e-12/s
unit: s
tolerance: 0.5%

## What is the charge relaxation time of a material with $\varepsilon_r$ = {er} and $\sigma$ = {s} S/m?

::: right
Right. $\tau = \frac{\varepsilon_r\varepsilon_0}{\sigma}$ = {answer}.
:::

::: misses
- [s/(er*8.854e-12)] Upside down: that's the decay rate.
- [any] Not yet. $\tau = \varepsilon/\sigma$.
:::
:::

::: check
given: a = 2 | 5; b = 1 | 3
answer: -(a + b)
unit: C/(m³·s)
tolerance: 0.5%

## $\mathbf J = (\given{a}x, \given{b}y, 0)$ A/m². At what rate is the charge density changing?

::: right
Right. $\frac{\partial\rho}{\partial t} = -\nabla\cdot\mathbf J = -(a + b)$ = {answer}.
:::

::: misses
- [a + b] Positive divergence means charge leaving: $\rho$ falls.
- [any] Not yet. Use the continuity equation.
:::
:::

::: check
given: I1 = 2 | 7; I2 = 3 | 4; I3 = 1 | 4
answer: I1 + I2 - I3
unit: mA
tolerance: 0.5%

## Currents of {I1} mA and {I2} mA flow into a node, and {I3} mA flows out through a third branch. What current must the fourth branch carry out?

::: right
Right. In steady state $\nabla\cdot\mathbf J = 0$: what flows in flows out. {answer}.
:::

::: misses
- [I1 + I2 + I3] The {I3} mA is already leaving.
- [any] Not yet. The outflows must equal the inflows.
:::
:::

::: check
given: Q = 1 | 10; I = 0.5 | 2
answer: Q/I
unit: ms
tolerance: 0.5%

## A region holds {Q} µC, and current leaves it at a net {I} mA. How long until the charge inside is gone, if that continues?

::: right
Right. $\frac{dQ}{dt} = -I$, so it takes $Q/I$ = {answer}.
:::

::: misses
- [Q*I] Charge divided by current gives time.
- [any] Not yet. $Q = It$.
:::
:::

::: check
kind: parts
given: er = 5 | 10; lg = -12 | -10

## An insulator has $\varepsilon_r$ = {er} and $\sigma = 10^{\given{lg}}$ S/m.

::: part
answer: er*8.854e-12/10^lg
unit: s
tolerance: 0.5%

### What is its relaxation time?

::: misses
- [any] $\tau = \frac{\varepsilon_r\varepsilon_0}{\sigma}$.
:::
:::

::: part
answer: er*8.854e-12/10^lg*ln(100)
unit: s
tolerance: 0.5%

### How long until 99% of an internal charge reaches the surface?

::: misses
- [er*8.854e-12/10^lg*0.99] The decay is exponential: 1% remains after $\tau\ln 100$.
- [any] Solve $e^{-t/\tau} = 0.01$.
:::
:::
:::

::: check
kind: derivation
vars: s = 0.1..10, e = 1..10, r0 = 0.1..5, t = 0..3

## Combine $\mathbf J = s\mathbf E$, $\nabla\cdot\mathbf E = \rho/e$ and the continuity equation.

::: step
answer: s*r0/e

### What is $\nabla\cdot\mathbf J$ when $\rho = r_0$? (So $\frac{\partial\rho}{\partial t} = -\nabla\cdot\mathbf J$.)
:::

::: step
answer: r0*exp(-s*t/e)

### Solve $\frac{d\rho}{dt} = -\frac se\rho$ from $r_0$. What is $\rho(t)$?
:::

::: right
Right. Exponential decay with $\tau = e/s$: the material's own RC time constant.
:::
:::

::: check
kind: python

## Simulate $\frac{d\rho}{dt} = -\frac\sigma\varepsilon\rho$ for seawater ($\varepsilon_r$ = 81, $\sigma$ = 4 S/m) with RK4, 2000 steps of $\tau/200$, from $\rho = 1$. Set `t1` to the first time $\rho$ falls below 0.01 (interpolated) and `predict` to $\tau\ln 100$.

```python starter
import math

t1 = predict = 0.0
print(t1, predict)
```

```python solution
import math

eps, sig = 81 * 8.854e-12, 4.0
tau = eps / sig
h = tau / 200
rho, t = 1.0, 0.0
f = lambda r: -sig / eps * r
for _ in range(2000):
    k1 = f(rho); k2 = f(rho + h / 2 * k1); k3 = f(rho + h / 2 * k2); k4 = f(rho + h * k3)
    new = rho + h / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
    if rho >= 0.01 > new:
        t1 = t + (rho - 0.01) / (rho - new) * h
        break
    rho, t = new, t + h
predict = tau * math.log(100)
print(t1, predict)
```

```python tests
import math
tau = 81 * 8.854e-12 / 4
assert abs(predict - tau * math.log(100)) < 1e-20, "predict should be tau ln 100."
assert abs(t1 / predict - 1) < 1e-4, f"The simulation should reach 1% at tau ln 100 = {tau * math.log(100):.4e} s; got {t1:.4e}."
```

::: right
Right. 0.83 ns: the charge reaches the surface in well under a nanosecond.
:::
:::

::: explain
## Why is the charge relaxation time $\varepsilon/\sigma$ like an RC time constant?

::: model
Take a slab of the material between two plates of area $A$ separated by $d$. Its capacitance is $C = \frac{\varepsilon A}{d}$ and its resistance is $R = \frac{d}{\sigma A}$, so $RC = \frac{\varepsilon}{\sigma}$, with the geometry cancelling completely. Charge sitting in the material is like charge on that capacitor, and it leaks away through the material's own resistance. Because the shape drops out, the time is a property of the material alone, which is why it decides whether something behaves as a conductor or an insulator at a given frequency.
:::
:::

::: practice

::: check
given: er = 1..100; s = 0.0001..100
answer: er*8.854e-12/s
unit: s
tolerance: 0.5%

## Relaxation time in seconds for $\varepsilon_r$ = {er}, $\sigma$ = {s} S/m?

::: misses
- [any] $\varepsilon_r\varepsilon_0/\sigma$.
:::
:::

::: check
given: a = 0.1..10; b = 0.1..10
answer: -(a + b)
tolerance: 0.5%

## $\partial\rho/\partial t$ for $\mathbf J = (\given{a}x, \given{b}y, 0)$?

::: misses
- [any] $-(a + b)$.
:::
:::
:::
