---
title: The Laplacian and Laplace's equation
heading: Every point is the average of its neighbors
eyebrow: A9 · Lesson 46 · Laplace's equation
xp: 50
---

::: hook
In the empty space between conductors, the voltage obeys one equation, $\nabla^2V = 0$, and that equation has a remarkable consequence: the voltage at every point is exactly the average of the voltages around it. So there are no peaks or dips in empty space, the field is decided entirely by the voltages on the conductors, and a computer can find it by repeatedly replacing each grid point with the average of its neighbors. Field solvers for capacitors, connectors and circuit-board traces all start from this.
:::

::: play
- A rectangular slot has its floor and sides at 0 V and its lid held at a voltage that varies as $\sin(n\pi x)$ across the top. The shading is the potential inside; the lines are equipotentials.
- Raise $n$. The pattern on the lid dies away faster as you go down into the slot. Why do finer patterns fade more quickly?
:::
:::

```sim plot
view: flow
x: x = 0..1 m
y: y = 0..1 m
slider: n = 1..4 step 1 = 1
shade: sin(n*pi*x)*sinh(n*pi*y)/sinh(n*pi) | contours: 14
readout: lid value, halfway down, as a fraction = sinh(n*pi*0.5)/sinh(n*pi) | digits: 3
```

::: predict
## A square box has its top held at 1 V and its other three sides at 0 V. What is the voltage at the center?

- [ ] 0.5 V
- [x] 0.25 V
- [ ] 0.33 V
- [ ] 0 V

::: reveal
0.25 V, exactly. Rotate the box to put the 1 V side on each of the four sides in turn and add the four solutions: the sum has 1 V on every side, so it's 1 V everywhere, including the center. By symmetry each of the four contributes the same at the center, so each gives $\frac{1}{4}$. That's superposition, which works because Laplace's equation is linear.
:::
:::

::: nameit
## The Laplacian

$$\nabla^2V = \nabla\cdot\nabla V = \frac{\partial^2V}{\partial x^2} + \frac{\partial^2V}{\partial y^2} + \frac{\partial^2V}{\partial z^2}$$

It measures how much $V$ at a point differs from the average around it: on a grid with spacing $h$,

$$\nabla^2V \approx \frac{V_E + V_W + V_N + V_S - 4V}{h^2}$$

## Poisson's and Laplace's equations

Combining $\mathbf{E} = -\nabla V$ with Gauss's law $\nabla\cdot\mathbf{E} = \rho/\varepsilon_0$:

$$\nabla^2V = -\frac{\rho}{\varepsilon_0} \quad\text{(Poisson)} \qquad \nabla^2V = 0 \text{ where } \rho = 0 \quad\text{(Laplace)}$$

Solutions of Laplace's equation are called **harmonic**.

## The averaging property

A harmonic function's value at any point equals its average over any circle (or sphere) around it. Consequences:

- **No interior maxima or minima:** the extremes are on the boundary, the conductors.
- **Uniqueness:** the voltages on the boundary fix the solution everywhere inside.
- **Earnshaw's theorem:** no arrangement of static charges can hold another charge in stable equilibrium, since its potential energy can't have a minimum in empty space.

## Relaxation

Set the boundary values, guess the inside, then repeatedly replace each interior point with the average of its four neighbors. The grid settles to the discrete solution of Laplace's equation. Each sweep is cheap, but convergence takes roughly $N^2$ sweeps for an $N \times N$ grid; faster methods (multigrid, A13) speed this up enormously.
:::

::: example
## Check that $V = x^2 - y^2$ is harmonic, and find $\nabla^2(3x^2 + y^2)$.

::: solution
1. **Second partials of $x^2 - y^2$.**
   $$\begin{aligned} \frac{\partial^2 V}{\partial x^2} &= 2 \\ \frac{\partial^2 V}{\partial y^2} &= -2 \end{aligned}$$
   They cancel, so it's harmonic.
2. **Laplacian of $3x^2 + y^2$.**
   $$\begin{aligned} \nabla^2(3x^2 + y^2) &= 6 + 2 \\ &= 8 \end{aligned}$$
   not harmonic.
3. **What it would need.** By Poisson's equation it would need a charge density $\rho = -8\varepsilon_0$ to exist.

**Answer:** $x^2 - y^2$ is harmonic, and $\nabla^2(3x^2 + y^2) = 8$.
:::
:::

::: example
## Grid neighbors of a point are at 2, 4, 3 and 7 V, in a charge-free region. What is the point's voltage after relaxation?

::: solution
1. **Average the neighbors.**
   $$\frac{2 + 4 + 3 + 7}{4} = 4\ \text{V}$$
2. **Why the average.** In a converged solution every interior point satisfies this.

**Answer:** the point settles at 4 V.
:::
:::

::: example
## Check whether $V = \ln r$ and $V = r^2$ are harmonic in the plane ($r = \sqrt{x^2 + y^2}$).

::: solution
1. **Write $\ln r$ in $x$ and $y$.**
   $$\ln r = \tfrac12\ln(x^2 + y^2)$$
2. **Its second partials.**
   $$\begin{aligned} V_{xx} &= \frac{y^2 - x^2}{r^4} \\ V_{yy} &= \frac{x^2 - y^2}{r^4} \end{aligned}$$
   They add to zero away from the origin. It's the potential of a line charge.
3. **Now $r^2 = x^2 + y^2$.**
   $$\begin{aligned} \nabla^2V &= 2 + 2 \\ &= 4 \end{aligned}$$
   not zero.
4. **Interpret.** A charge-free region can't have this potential; it describes a uniform charge density, by Poisson's equation.

**Answer:** $\ln r$ is harmonic away from the origin; $r^2$ isn't, since its Laplacian is 4.
:::
:::

::: check
given: a = 1 | 3; b = 2 | -2
answer: 2*a + 2*b

## What is $\nabla^2(\given{a}x^2 + \given{b}y^2)$?

::: right
Right. $2a + 2b$ = {answer}.
:::

::: misses
- [a + b] Each second derivative of $x^2$ is 2.
- [any] Not yet. Add the second derivatives.
:::
:::

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

## A region holds charge density {rho} nC/m³. What is $\nabla^2V$ there?

::: right
Right. Poisson: $-\rho/\varepsilon_0$ = {answer}.
:::

::: misses
- [rho*1e-9/8.854e-12] Check the sign: $\nabla^2V = -\rho/\varepsilon_0$.
- [0] That's empty space.
- [any] Not yet. Poisson's equation.
:::
:::

::: check
given: v1 = 1 | 6; v2 = 3 | 8; v3 = 5 | 2; v4 = 7 | 0
answer: (v1 + v2 + v3 + v4)/4

## After relaxation, a charge-free grid point has neighbors at {v1}, {v2}, {v3} and {v4} V. What is its voltage?

::: right
Right. The average of its four neighbors: {answer} V.
:::

::: misses
- [(v1 + v2 + v3 + v4)/2] Average four values: divide by 4.
- [any] Not yet. Laplace's equation on a grid.
:::
:::

::: check
given: V1 = 10 | 4; V2 = 2 | 6
answer: (V1 + V2)/4

## A square box has its top at {V1} V, its bottom at {V2} V and both sides at 0 V. What is the voltage at the center?

::: right
Right. By superposition, each side contributes a quarter of its voltage at the center: {answer}.
:::

::: misses
- [(V1 + V2)/2] The two grounded sides count too: each side contributes a quarter.
- [any] Not yet. Add the single-side solutions.
:::
:::

::: check
given: V0 = 5 | 12; f = 0.25 | 0.4
answer: V0*f
unit: V

## Two large parallel plates are at 0 V and {V0} V. What is the voltage {f} of the way from the 0 V plate?

::: right
Right. In one dimension $V'' = 0$ makes $V$ linear: {answer}.
:::

::: misses
- [V0*(1 - f)] Measure from the 0 V plate.
- [any] Not yet. $V'' = 0$ gives a straight line.
:::
:::

::: check
kind: choice

## Can a set of fixed charges hold another charge in stable equilibrium in empty space?

- [x] No: the potential can't have a minimum where $\nabla^2V = 0$
- [ ] Yes, at the center of a cube of equal charges
- [ ] Yes, if the charges are large enough
- [ ] Only for negative charges

::: right
Right. That's Earnshaw's theorem. Ion traps get around it with oscillating fields or magnetic fields.
:::

::: misses
- [2] The center of a cube is a saddle: stable in some directions, unstable in others.
- [any] Think about the averaging property.
:::
:::

::: check
kind: python

## Write `solve_box(N, iters)`: an $N \times N$ grid with row 0 held at 1 V and the other edges at 0 V, relaxed by `iters` sweeps that replace every interior point with the average of its four neighbors (use NumPy slices). Return the grid.

```python starter
import numpy as np

def solve_box(N, iters):
    V = np.zeros((N, N))
    V[0, :] = 1.0
    # each sweep: V[1:-1, 1:-1] = average of the four shifted slices
    return V

V = solve_box(21, 2000)
print(V[10, 10])
```

```python solution
import numpy as np

def solve_box(N, iters):
    V = np.zeros((N, N))
    V[0, :] = 1.0
    for _ in range(iters):
        V[1:-1, 1:-1] = 0.25 * (V[:-2, 1:-1] + V[2:, 1:-1] + V[1:-1, :-2] + V[1:-1, 2:])
    return V

V = solve_box(21, 2000)
print(V[10, 10])
```

```python tests
import numpy as np
V = solve_box(21, 2000)
assert np.allclose(V[0, :], 1) and np.allclose(V[-1, :], 0) and np.allclose(V[1:, 0], 0) and np.allclose(V[1:, -1], 0), "Keep the edges fixed: 1 V on row 0, 0 V elsewhere."
assert abs(V[10, 10] - 0.25) < 1e-6, f"The center of the box should settle to exactly 0.25 V; got {V[10, 10]:.6f}."
lap = V[:-2, 1:-1] + V[2:, 1:-1] + V[1:-1, :-2] + V[1:-1, 2:] - 4 * V[1:-1, 1:-1]
assert np.max(np.abs(lap)) < 1e-6, "Every interior point should be the average of its neighbors."
```

::: right
Right. The center lands on 0.25 V, as superposition predicts, after a couple of thousand sweeps on a 21 × 21 grid.
:::
:::

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

## Take $V = \given{a}x^2 + \given{b}y^2 + cz^2$.

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

### What is $\nabla^2$ of the first two terms, $\given{a}x^2 + \given{b}y^2$?

::: misses
- [a + b] Each second derivative brings a factor 2.
- [any] $\frac{\partial^2}{\partial x^2}(ax^2) = 2a$.
:::
:::

::: part
answer: -(a + b)
tolerance: 0.5%

### What must $c$ be for $V$ to be harmonic?

::: misses
- [a + b] The $z$ term must cancel the other two: $2c = -(2a + 2b)$.
- [any] Set $2a + 2b + 2c = 0$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0..5, b = 0..5, c = 0..5, d = 0..5

## A grid point's four neighbors are at $a$, $b$, $c$ and $d$ volts, in a charge-free region.

::: step
answer: (a + b + c + d)/4

### What should the point's voltage be?
:::

::: right
Right. Laplace's equation on a grid says each point is the average of its neighbors.
:::
:::

::: explain
## Why can't the voltage in a charge-free region have a peak in the middle?

::: model
In a charge-free region the voltage satisfies Laplace's equation, which means its value at every point equals the average of its values on any small circle around it. A peak would have to be higher than everything around it, so it couldn't equal their average. The same goes for a dip. So the highest and lowest voltages always lie on the boundary, on the conductors or charges, never out in empty space.
:::
:::

::: practice

::: check
given: a = 2..9 int
answer: 0

## What is $\nabla^2(\given{a}xy)$?

::: misses
- [any] Both second derivatives are zero.
:::
:::

::: check
given: V1 = 4..40 step 4
answer: V1/4

## A square box has one side at {V1} V and the other three at 0 V. What is the voltage at the center?

::: misses
- [V1/2] Each of the four sides contributes a quarter.
- [any] $V_1/4$.
:::
:::

::: check
given: d = 0.01 | 0.002; V0 = 10 | 3
answer: V0/d
unit: V/m
tolerance: 0.5%

## Parallel plates {d} m apart are held {V0} V apart. How strong is the field between them?

::: misses
- [any] $V$ is linear, so $E = V_0/d$.
:::
:::
:::
