---
title: "Project: a microstrip's capacitance two ways"
heading: An exact answer from conformal mapping, a numerical one from relaxation, and how to trust both
eyebrow: "A12 · Lesson 53 · Project: a microstrip's capacitance two ways"
xp: 80
---

::: hook
Every high-speed board is laid out with traces of a chosen impedance, usually 50 Ω, and the trace widths come from a field solver or from formulas fitted to one. In this project you'll build both ends of that chain. First, the exact capacitance of a stripline (a thin strip midway between two ground planes) from a conformal map, as Cohn worked it out in 1954. Then a relaxation solver for Laplace's equation with dielectrics, checked against that exact answer and sharpened by Richardson extrapolation. Finally the microstrip, a strip on top of a substrate with air above it, which has no exact formula; you'll compare your solver with the Hammerstad–Jensen formula that PCB calculators use.
:::

::: predict
## A relaxation solver puts a zero-thickness strip on a grid. As the grid gets finer, how does its error in C′ shrink?

- [ ] As $h^2$, like the five-point stencil
- [x] Roughly as h: the field's singularity at the strip's edges spoils second-order accuracy
- [ ] Not at all
- [ ] Exponentially

::: reveal
Roughly as h. Near the edge of a thin strip the potential goes as $r^{1/2}$ (lesson 38, a knife edge), so the field is infinite there and the grid can't represent it well. Halving h about halves the error, which is what makes Richardson extrapolation from two grids so effective here.
:::
:::

::: nameit
## The exact stripline

A strip of width w midway between ground planes b apart, with $\varepsilon_r$ filling the space. Cohn mapped a quarter of the cross-section (half the strip and one ground plane) onto a parallel-plate rectangle with an elliptic-function map. Its sides are in the ratio $K(k')/K(k)$, where K is the complete elliptic integral of the first kind and

$$k = \text{sech}\frac{\pi w}{2b}, \qquad k' = \tanh\frac{\pi w}{2b}$$

so by lesson 24 each quarter has $\varepsilon K(k')/K(k)$, and the four are in parallel:

$$C' = 4\varepsilon_0\varepsilon_r\frac{K(k')}{K(k)}, \qquad Z_0 = \frac{\sqrt{\varepsilon_r}}{c\,C'}$$

K is easy to compute exactly with the arithmetic–geometric mean: $K(k) = \frac{\pi}{2\,\text{AGM}(1, \sqrt{1 - k^2})}$, where AGM repeats $a, b \leftarrow \frac{a + b}{2}, \sqrt{ab}$ until they agree.

## Relaxation with dielectrics

In a material, Laplace's equation becomes $\nabla\cdot(\varepsilon\nabla V) = 0$. On a grid, give each link between neighbors a permittivity, and make every free point the weighted average $V = \frac{\sum\varepsilon_kV_k}{\sum\varepsilon_k}$ of its four neighbors. A link lying along a dielectric surface gets the average, $\frac{1 + \varepsilon_r}{2}$. The capacitance comes from the energy, as in A9's project:

$$C' = \varepsilon_0\sum_{\text{links}}\varepsilon_{link}(\Delta V)^2$$

## Microstrip

With a substrate below and air above, the wave isn't purely in one material, so define $\varepsilon_{eff} = C'/C'_0$ (with and without the substrate) and

$$Z_0 = \frac{1}{c\sqrt{C'C'_0}}$$

Hammerstad and Jensen's fit, good to about 1% for a thin strip with $w/h \ge 1$:

$$\varepsilon_{eff} = \frac{\varepsilon_r + 1}{2} + \frac{\varepsilon_r - 1}{2}\left(1 + \frac{12h}{w}\right)^{-1/2}, \quad Z_0 = \frac{120\pi/\sqrt{\varepsilon_{eff}}}{w/h + 1.393 + 0.667\ln(w/h + 1.444)}$$

## Richardson extrapolation

If the error goes as h, two grids give $C(h) \approx C_\infty + Ah$ and $C(h/2) \approx C_\infty + Ah/2$, so $C_\infty \approx 2C(h/2) - C(h)$.
:::

::: example
## Find the exact capacitance of an air stripline with w = b.

::: solution
1. **The modulus.** Here $\frac{\pi w}{2b} = 1.5708$, so
   $$\begin{aligned} k &= \text{sech}\,1.5708 \\ &= 0.3985 \\ k' &= \tanh 1.5708 \\ &= 0.9172 \end{aligned}$$
2. **The elliptic integrals.** $K(k) = 1.6394$ and $K(k') = 2.3626$.
3. **The capacitance.**
   $$\begin{aligned} C' &= 4 \times 8.854 \times \frac{2.3626}{1.6394}\ \text{pF/m} \\ &= 51.04\ \text{pF/m} \end{aligned}$$
4. **The impedance.**
   $$\begin{aligned} Z_0 &= \frac{1}{c\,C'} \\ &= 65.4\ \Omega \end{aligned}$$

**Answer:** C′ = 51.04 pF/m, and $Z_0$ = 65.4 Ω.
:::
:::

::: example
## A relaxation solver gives 52.32 pF/m with 20 cells across b and 51.67 pF/m with 40. Extrapolate.

::: solution
1. **Extrapolate.**
   $$\begin{aligned} C' &\approx 2 \times 51.67 - 52.32 \\ &= 51.02\ \text{pF/m} \end{aligned}$$
2. **Compare with the exact value.** Against the exact 51.04, the two runs were off by 2.5% and 1.2%, and the extrapolation is off by 0.04%.

**Answer:** the extrapolated value is 51.02 pF/m, within 0.04% of the exact 51.04 pF/m.
:::
:::

::: check
kind: python

## Step 1. Write `K(k)`, the complete elliptic integral by the AGM, and `stripline_C(w_b, er)`, the exact capacitance per meter of a stripline with width-to-spacing ratio `w_b`.

```python starter
import math
eps0 = 8.854e-12

def K(k):
    return 0.0

def stripline_C(w_b, er):
    return 0.0

print(stripline_C(1, 1) * 1e12, "pF/m")
```

```python solution
import math
eps0 = 8.854e-12

def agm(a, b):
    while abs(a - b) > 1e-15 * a:
        a, b = (a + b) / 2, math.sqrt(a * b)
    return a

def K(k):
    return math.pi / (2 * agm(1.0, math.sqrt(1 - k * k)))

def stripline_C(w_b, er):
    k = 1 / math.cosh(math.pi * w_b / 2)
    kp = math.tanh(math.pi * w_b / 2)
    return 4 * eps0 * er * K(kp) / K(k)

print(stripline_C(1, 1) * 1e12, "pF/m")
```

```python tests
import math
assert abs(K(0) - math.pi / 2) < 1e-12, "K(0) should be π/2."
assert abs(K(1 / math.sqrt(2)) - 1.8540746773013719) < 1e-12, f"K(1/√2) should be 1.8540746773; got {K(1 / math.sqrt(2))}."
assert abs(stripline_C(1, 1) / 51.03879378957932e-12 - 1) < 1e-9, f"For w = b in air, C′ should be 51.0388 pF/m; got {stripline_C(1, 1) * 1e12:.4f}."
assert abs(stripline_C(2, 2.2) / (2.2 * 86.46005100156698e-12) - 1) < 1e-9, "For w = 2b, C′ should be 86.46 pF/m times εr."
```

::: right
Right. A few AGM steps give K to rounding error, and the conformal map gives 51.039 pF/m for w = b in air.
:::
:::

::: check
kind: python

## Step 2. Write `stripline_grid(nb, nw, side)` and `capacitance(V, ex, ey)`. The grid has rows 0 to nb (rows 0 and nb are the ground planes) and `nx = nw + 2*side + 1` columns (columns 0 and nx − 1 are grounded walls far out). The strip is row `nb // 2`, columns `side` to `side + nw`, at 1 V. Return `V`, the boolean mask `fixed`, and link permittivities `ex` (shape `(nb + 1, nx - 1)`, between `V[i, j]` and `V[i, j + 1]`) and `ey` (shape `(nb, nx)`, between `V[i, j]` and `V[i + 1, j]`), all 1 here. The solver `solve` is written for you.

```python starter
import math
import numpy as np
eps0 = 8.854e-12

def solve(V, fixed, ex, ey, iters):
    # Red-black SOR for div(eps grad V) = 0, weighting each neighbor by its link's permittivity.
    ny, nx = V.shape
    ii, jj = np.mgrid[0:ny, 0:nx]
    W = np.zeros_like(V)
    W[:, :-1] += ex; W[:, 1:] += ex; W[:-1, :] += ey; W[1:, :] += ey
    omega = 2 / (1 + math.sin(math.pi / (ny - 1)))
    for _ in range(iters):
        for m in (((ii + jj) % 2 == 0) & ~fixed, ((ii + jj) % 2 == 1) & ~fixed):
            S = np.zeros_like(V)
            S[:, :-1] += ex * V[:, 1:]; S[:, 1:] += ex * V[:, :-1]
            S[:-1, :] += ey * V[1:, :]; S[1:, :] += ey * V[:-1, :]
            V[m] += omega * (S[m] / W[m] - V[m])
    return V

def stripline_grid(nb, nw, side):
    nx = nw + 2 * side + 1
    V = np.zeros((nb + 1, nx))
    fixed = np.zeros(V.shape, dtype=bool)
    ex = np.ones((nb + 1, nx - 1))
    ey = np.ones((nb, nx))
    # mark the ground planes, the walls and the strip
    return V, fixed, ex, ey

def capacitance(V, ex, ey):
    return 0.0

V, f, ex, ey = stripline_grid(20, 20, 60)
print(capacitance(solve(V, f, ex, ey, 300), ex, ey) * 1e12, "pF/m")
```

```python solution
import math
import numpy as np
eps0 = 8.854e-12

def solve(V, fixed, ex, ey, iters):
    # Red-black SOR for div(eps grad V) = 0, weighting each neighbor by its link's permittivity.
    ny, nx = V.shape
    ii, jj = np.mgrid[0:ny, 0:nx]
    W = np.zeros_like(V)
    W[:, :-1] += ex; W[:, 1:] += ex; W[:-1, :] += ey; W[1:, :] += ey
    omega = 2 / (1 + math.sin(math.pi / (ny - 1)))
    for _ in range(iters):
        for m in (((ii + jj) % 2 == 0) & ~fixed, ((ii + jj) % 2 == 1) & ~fixed):
            S = np.zeros_like(V)
            S[:, :-1] += ex * V[:, 1:]; S[:, 1:] += ex * V[:, :-1]
            S[:-1, :] += ey * V[1:, :]; S[1:, :] += ey * V[:-1, :]
            V[m] += omega * (S[m] / W[m] - V[m])
    return V

def stripline_grid(nb, nw, side):
    nx = nw + 2 * side + 1
    V = np.zeros((nb + 1, nx))
    fixed = np.zeros(V.shape, dtype=bool)
    fixed[0, :] = fixed[-1, :] = fixed[:, 0] = fixed[:, -1] = True
    r = nb // 2
    V[r, side:side + nw + 1] = 1.0
    fixed[r, side:side + nw + 1] = True
    ex = np.ones((nb + 1, nx - 1))
    ey = np.ones((nb, nx))
    return V, fixed, ex, ey

def capacitance(V, ex, ey):
    return eps0 * (np.sum(ex * np.diff(V, axis=1) ** 2) + np.sum(ey * np.diff(V, axis=0) ** 2))

V, f, ex, ey = stripline_grid(20, 20, 60)
print(capacitance(solve(V, f, ex, ey, 300), ex, ey) * 1e12, "pF/m")
```

```python tests
exact = 51.03879378957932e-12
V, f, ex, ey = stripline_grid(20, 20, 60)
assert V.shape == (21, 141) and ex.shape == (21, 140) and ey.shape == (20, 141), "Check the shapes of V, ex and ey."
assert f[0].all() and f[-1].all() and f[:, 0].all() and f[:, -1].all() and f[10, 70] and not f[5, 70] and not f[10, 50], "Fix the ground planes, the walls and the strip, and nothing else."
c20 = capacitance(solve(V, f, ex, ey, 300), ex, ey)
assert abs(c20 / exact - 1) < 0.03, f"With 20 cells the solver should land within 3% of 51.04 pF/m; got {c20 * 1e12:.2f}."
V, f, ex, ey = stripline_grid(40, 40, 120)
c40 = capacitance(solve(V, f, ex, ey, 600), ex, ey)
assert abs(c40 / exact - 1) < abs(c20 / exact - 1), "The finer grid should be closer to the exact answer."
assert abs((2 * c40 - c20) / exact - 1) < 0.001, f"Richardson extrapolation should land within 0.1% of exact; got {(2 * c40 - c20) * 1e12:.3f} pF/m."
```

::: right
Right. The 20- and 40-cell grids are 2.5% and 1.2% high, and $2C_{40} - C_{20}$ is within a few hundredths of a percent of the conformal map's answer.
:::
:::

::: check
kind: python

## Step 3. Write `microstrip(h, er)` returning `(eeff, Z0)` for a strip of width w = 2h on a substrate h cells thick, with a grounded shield 10h above the ground plane and grounded walls 8h beyond each strip edge. Row 0 is the ground plane, the strip is row h (columns `8*h` to `8*h + 2*h`), and the substrate fills rows 0 to h: links below row h get $\varepsilon_r$, and horizontal links on row h get $(1 + \varepsilon_r)/2$. `solve` and `capacitance` are included; run 700 sweeps.

```python starter
import math
import numpy as np
eps0 = 8.854e-12
c0 = 299792458.0

def solve(V, fixed, ex, ey, iters):
    ny, nx = V.shape
    ii, jj = np.mgrid[0:ny, 0:nx]
    W = np.zeros_like(V)
    W[:, :-1] += ex; W[:, 1:] += ex; W[:-1, :] += ey; W[1:, :] += ey
    omega = 2 / (1 + math.sin(math.pi / (ny - 1)))
    for _ in range(iters):
        for m in (((ii + jj) % 2 == 0) & ~fixed, ((ii + jj) % 2 == 1) & ~fixed):
            S = np.zeros_like(V)
            S[:, :-1] += ex * V[:, 1:]; S[:, 1:] += ex * V[:, :-1]
            S[:-1, :] += ey * V[1:, :]; S[1:, :] += ey * V[:-1, :]
            V[m] += omega * (S[m] / W[m] - V[m])
    return V

def capacitance(V, ex, ey):
    return eps0 * (np.sum(ex * np.diff(V, axis=1) ** 2) + np.sum(ey * np.diff(V, axis=0) ** 2))

def microstrip(h, er):
    # build the grid twice (substrate er, then air), solve each, and return (C/C0, 1/(c0*sqrt(C*C0)))
    return 1.0, 0.0

print(microstrip(5, 4.3))
```

```python solution
import math
import numpy as np
eps0 = 8.854e-12
c0 = 299792458.0

def solve(V, fixed, ex, ey, iters):
    ny, nx = V.shape
    ii, jj = np.mgrid[0:ny, 0:nx]
    W = np.zeros_like(V)
    W[:, :-1] += ex; W[:, 1:] += ex; W[:-1, :] += ey; W[1:, :] += ey
    omega = 2 / (1 + math.sin(math.pi / (ny - 1)))
    for _ in range(iters):
        for m in (((ii + jj) % 2 == 0) & ~fixed, ((ii + jj) % 2 == 1) & ~fixed):
            S = np.zeros_like(V)
            S[:, :-1] += ex * V[:, 1:]; S[:, 1:] += ex * V[:, :-1]
            S[:-1, :] += ey * V[1:, :]; S[1:, :] += ey * V[:-1, :]
            V[m] += omega * (S[m] / W[m] - V[m])
    return V

def capacitance(V, ex, ey):
    return eps0 * (np.sum(ex * np.diff(V, axis=1) ** 2) + np.sum(ey * np.diff(V, axis=0) ** 2))

def microstrip_C(h, er):
    w, side, top = 2 * h, 8 * h, 10 * h
    nx = w + 2 * side + 1
    V = np.zeros((top + 1, nx))
    fixed = np.zeros(V.shape, dtype=bool)
    fixed[0, :] = fixed[-1, :] = fixed[:, 0] = fixed[:, -1] = True
    V[h, side:side + w + 1] = 1.0
    fixed[h, side:side + w + 1] = True
    ex = np.ones((top + 1, nx - 1))
    ey = np.ones((top, nx))
    ey[:h, :] = er
    ex[:h, :] = er
    ex[h, :] = (1 + er) / 2
    return capacitance(solve(V, fixed, ex, ey, 700), ex, ey)

def microstrip(h, er):
    C = microstrip_C(h, er)
    C0 = microstrip_C(h, 1.0)
    return C / C0, 1 / (c0 * math.sqrt(C * C0))

print(microstrip(5, 4.3))
```

```python tests
import math
eeff5, z5 = microstrip(5, 4.3)
assert abs(eeff5 - 3.2648) < 0.002 and abs(z5 - 46.749) < 0.05, f"With h = 5 cells on εr = 4.3, expect εeff ≈ 3.265 and Z0 ≈ 46.75 Ω; got {eeff5:.4f} and {z5:.3f}."
eeff10, z10 = microstrip(10, 4.3)
z = 2 * z10 - z5
hj_e = 2.65 + 1.65 * (1 + 6) ** -0.5
hj_z = 120 * math.pi / math.sqrt(hj_e) / (2 + 1.393 + 0.667 * math.log(3.444))
assert abs(z / hj_z - 1) < 0.02, f"The extrapolated Z0 ({z:.2f} Ω) should be within 2% of Hammerstad-Jensen's {hj_z:.2f} Ω."
print(f"extrapolated Z0 {z:.2f} Ω, Hammerstad-Jensen {hj_z:.2f} Ω")
```

::: right
Right. Extrapolated from h = 5 and h = 10 cells, the solver gives about 48.8 Ω against the formula's 49.4 Ω: within the formula's own accuracy plus the effect of the shield and walls in the solver's box.
:::
:::

::: check
given: Cc = 52.3 | 60.1 | 75.5; d = 0.6 | 0.8
answer: 2*(Cc - d) - Cc
unit: pF/m
tolerance: 0.5%

## A solver whose error goes as h gives {Cc} pF/m on one grid and {d} pF/m less on a grid twice as fine. What's the extrapolated value?

::: right
Right. $2C(h/2) - C(h)$ = {answer} pF/m.
:::

::: misses
- [Cc - d] That's the fine grid's own value; the error left there is as large as the change.
- [any] Not yet. $C_\infty \approx 2C(h/2) - C(h)$.
:::
:::

::: check
given: C = 100 | 130 | 160; C0 = 30 | 40
answer: 1/(3e8*sqrt(C*1e-12*C0*1e-12))
unit: Ω
tolerance: 0.5%

## A microstrip has C′ = {C} pF/m and, with its substrate replaced by air, $C'_0$ = {C0} pF/m. What's its characteristic impedance?

::: right
Right. $\frac{1}{c\sqrt{C'C'_0}}$ = {answer} Ω.
:::

::: misses
- [1/(3e8*C*1e-12)] That's for a line entirely in air; with a mixed dielectric use both capacitances.
- [any] Not yet. $Z_0 = 1/(c\sqrt{C'C'_0})$.
:::
:::

::: check
given: er = 3.5 | 4.3 | 10.2; u = 1 | 2 | 3
answer: (er + 1)/2 + (er - 1)/2*(1 + 12/u)^(-0.5)
tolerance: 0.5%

## What's the effective permittivity of a microstrip with w/h = {u} on a substrate with $\varepsilon_r$ = {er}, by Hammerstad and Jensen?

::: right
Right. {answer}: between 1 and {er}, because part of the field is in the air.
:::

::: misses
- [(er + 1)/2] That's the limit of a very narrow strip; add the second term.
- [any] Not yet. $\frac{\varepsilon_r + 1}{2} + \frac{\varepsilon_r - 1}{2}\left(1 + \frac{12h}{w}\right)^{-1/2}$.
:::
:::

::: explain
## Why is it worth checking a field solver against the stripline, which has an exact answer, before trusting it on a microstrip, which doesn't?

::: model
The stripline and the microstrip share everything that can go wrong in the solver: the grid, the relaxation, the thin strip with its singular edges, the boundary walls and the energy formula for C′. Only the stripline has an exact answer, from the conformal map, so comparing there measures the solver's actual error and how it shrinks with the grid (about as h here, so Richardson extrapolation works). Once that's known, the microstrip result, which adds only the dielectric interface, can be trusted to a similar accuracy, and its agreement with Hammerstad and Jensen to about 1% then says something about both.
:::
:::

::: practice

::: check
given: Cc = 44.2 | 88.4; d = 0.4 | 1.1
answer: 2*(Cc - d) - Cc
unit: pF/m
tolerance: 0.5%

## Extrapolate from {Cc} pF/m and {d} pF/m less on half the spacing.

::: misses
- [any] $2C(h/2) - C(h)$.
:::
:::

::: check
given: C = 90 | 150; C0 = 25 | 45
answer: 1/(3e8*sqrt(C*1e-12*C0*1e-12))
unit: Ω
tolerance: 0.5%

## $Z_0$ for C′ = {C} pF/m, $C'_0$ = {C0} pF/m?

::: misses
- [any] $1/(c\sqrt{C'C'_0})$.
:::
:::

::: check
given: er = 2.2 | 6; u = 1.5 | 4
answer: (er + 1)/2 + (er - 1)/2*(1 + 12/u)^(-0.5)
tolerance: 0.5%

## Hammerstad–Jensen $\varepsilon_{eff}$, $\varepsilon_r$ = {er}, w/h = {u}?

::: misses
- [any] $\frac{\varepsilon_r + 1}{2} + \frac{\varepsilon_r - 1}{2}(1 + 12/u)^{-1/2}$.
:::
:::
:::
