Esc to close · to navigate · to open

WI20

Distributed Systems & Fields

PDEs and vector fields in continuous media — waves, heat diffusion, and electromagnetic field structure, solved both analytically and on a grid.

Concepts learned

Tech

  • Python
  • NumPy
  • Matplotlib

Hero demo Charge Field Plotter

N = 2\max |E| = 84.63\max |V| = 8.25

A classic dipole: +1 on the left, -1 on the right. Field sampled on a 20×20 grid over [-2, 2] × [-2, 2].

20
20
1.0
0
charges 2 · max |E| = 84.63

Reflection

Pre-interview preview. Akwasi’s first-person reflection on this course is pending — track at issue #48.

1D wave equation (string)

Plucked-string wave equation with reflective boundary conditions.

Walk me through this step by step
  1. Pluck a guitar string and watch the shape travel, oscillate, return, and oscillate again. One simple rule governs every plucked string, every taut wire, every acoustic-pipe mode. That rule is the wave equation, and it falls out of nothing more exotic than Newton’s second law applied to a tiny segment of the string.

  2. Here is the idea in plain English. How fast a point on the string accelerates up or down depends on how curved the string is right there. If the string is straight at that point, it doesn’t accelerate. If it’s bent upward (like the bottom of a smile), it gets yanked up. If it’s bent downward (like the top of a frown), it gets pushed down. Curvature creates acceleration. That’s it.

  3. Where does the curvature-acceleration rule come from? Think of a tiny segment of string under tension. Tension pulls on both ends. If the string is straight there, the two pulls point in opposite directions and cancel — no net force. If the string is curved, both pulls have a small vertical component pointing toward the “inside” of the curve. Newton’s F = ma turns that vertical force into vertical acceleration.

  4. In symbols, that becomes

    \frac{\partial^2 u}{\partial t^2} = c^2 \, \frac{\partial^2 u}{\partial x^2}

    where u(x,t) is the string’s height at position x and time t. The left side is “how fast the string is accelerating right now.” The right side is “how curved the string is right now,” times a constant c^2. The constant c is the wave speed — bigger for tighter or lighter strings.

  5. The boundary matters. A guitar string is clamped at both ends — u(0, t) = u(L, t) = 0 for all time. That is what makes it different from a whip or a free-hanging rope. The clamps mean only certain “shapes” can vibrate cleanly — the modes. Every other initial shape is just a sum of these modes, oscillating at different rates.

  6. The allowed shapes are \sin(m\pi x / L) for m = 1, 2, 3, … The “Fundamental” preset shows mode 1: a single bump from one end to the other. The “Second harmonic” preset shows mode 2: a full sine wave with a node — a permanently still point — in the middle. (Press a string at the 12th fret of a guitar and you have forced mode 2.)

  7. The demo doesn’t use that closed form to draw the animation, though — it solves the equation directly on a grid. Replace the smooth string with N points spaced dx apart. For each interior point, “value next” = 2·(value now) − (value before) + curvature term. The curvature term is just (left neighbour + right neighbour − 2·middle), which is the discrete version of u_{xx}. This is the leapfrog scheme.

  8. There is one inequality the numerical scheme must respect: c \cdot dt / dx \le 1. Physically: in one timestep dt, the true wave moves a distance c·dt. If that distance is more than one grid spacing dx, the wave has “skipped” past data the scheme needed, and the simulation blows up. This is called the CFL condition, and it is the one trap every PDE solver shares.

  9. Try it yourself.

  10. The featured problem “Standing-wave frequencies on a fixed-end string by separation of variables” just below derives the mode shapes from scratch by assuming the solution factors as X(x) · T(t). For the travelling-wave (rather than standing-wave) picture, the featured problem “d’Alembert solution to the 1D wave equation” decomposes any initial pulse into a left-mover plus a right-mover. And to see what happens when two waves meet on a 2D membrane, jump to the 2D wave interference demo immediately below.

c = 1.00r = 0.395t = 0.00\,s

Standing wave mode 1 on a 1 m string with wave speed c = 1.00 m/s, 80 grid points, timestep 0.005 s, CFL ratio r = 0.395 (stable when r ≤ 1).

1.00 m/s

Speed of transverse waves on the string.

0.005 s

Smaller dt keeps the CFL ratio r = c·dt/dx ≤ 1 for stability.

80

Number of points discretising the 1 m string.

1

Initial standing-wave mode number m: u₀(x) = sin(mπx/L).

CFL r = 0.395 · t = 0.00 s · mode 1

2D wave interference

Two-source interference pattern with adjustable phase, frequency, and source separation.

c = 1.00r = 0.020n = 0\max |u| = 0.000
60

Grid resolution n × n cells.

1.00

Propagation speed. Combined with dt and dx, sets the CFL ratio r.

0.020

Integrator step size. CFL stability requires c·dt/dx ≤ 1/√2.

0

Forcing pattern: single, two-sources (interference), or corner.

step n = 0 · max |u| = 0.000 · r = 0.020

1D heat equation

Finite-difference solver for heat diffusion along a rod; tune the boundary conditions and watch the profile relax.

Walk me through this step by step
  1. You pull a metal rod out of a fire and grab the cool end. The heat doesn’t leap to your hand — it crawls along the rod, smoothing out the hot spot a little more every second. Eventually the whole rod settles to one warm temperature. The heat equation is the rule that governs that crawl, and it turns up wherever something diffuses: temperature in a wall, ink in still water, even the price of a stock option.

  2. Forget formulas for a moment. The whole physics is this: heat flows from hot to cold, and the flow is faster when the temperature gap is bigger. Two beads sitting at 100° and 0° pull on each other much harder than two beads at 100° and 99°. So a sharp temperature spike levels out quickly at first and then more slowly as it fades. That is all “Fourier’s law” really says — no Greek letters required.

  3. To put this on a computer, chop the rod into N evenly-spaced beads, each holding a temperature ui. Every timestep, each interior bead nudges itself toward the average of its two neighbours. If a bead is already sitting at the neighbour average, nothing happens — it is already “in line”. If it is hotter than the average it cools; cooler, it warms. That nudge-toward-the- average is the discrete Laplacian, and smoothing — not wave-like propagation — is the only thing the heat equation ever does.

  4. Make it concrete. Take five beads with temperatures (0, 10, 20, 30, 0) and a smoothing strength r = 0.25. Focus on bead i = 3, currently at 30. Its neighbours are 20 and 0, so the discrete second derivative is (20 - 2 \cdot 30 + 0) = -40 and the new value is 30 + 0.25 \cdot (-40) = 20 — bead 3 dropped ten degrees in one step, precisely because it was sticking out way above the local average. Do this for every interior bead in parallel, leave the pinned endpoints alone, and you have advanced one timestep.

  5. Written for any interior bead, the update rule is

    u_i^{n+1} = u_i^n + r\,(u_{i+1}^n - 2 u_i^n + u_{i-1}^n)

    where the superscript n labels the timestep and r = \alpha\, dt / dx^2 is the smoothing strength per step. The bracketed term is the discrete second derivative — three samples reading off how “bent” the temperature profile is at that point. Concave-down hot peak: the bracket is negative and the bead cools. Concave-up valley: it warms. Curvature drives change here too, exactly as it did for the wave equation, but with a first time derivative rather than a second.

  6. Shrink dx → 0 and dt → 0 and that update rule becomes the continuous heat equation:

    \frac{\partial u}{\partial t} = \alpha \, \frac{\partial^2 u}{\partial x^2}

    The constant \alpha (thermal diffusivity) sets how fast smoothing happens — bigger for copper, smaller for wood. Sine-shaped modes are eigenfunctions: feed the rod a clean \sin(m\pi x / L) bump and it decays as \exp(-\alpha (m\pi/L)^2 t) while keeping its shape. Higher modes (more wiggles) decay much faster than the fundamental — the rod forgets fine detail first and broad bumps last.

  7. There is one trap. The smoothing strength r = \alpha\, dt / dx^2 must stay at or below 1/2 for this explicit forward Euler scheme — that is the CFL condition for diffusion. Step too big and the smoothing overshoots: a bead that ought to drift toward its neighbours’ average instead leaps past, then leaps back further next step, and the simulation explodes into ringing negative temperatures inside a few iterations. Halve dx for resolution and you must quarter dt — diffusion is unforgiving that way.

  8. Try it yourself.

  9. That contrast with the 1D wave equation (string) demo just above is the whole point of putting the two side by side. The wave equation has a second time derivative — energy sloshes between potential and kinetic and is preserved, so a pluck rings forever. The heat equation has a first time derivative, so energy leaks out monotonically and the rod relaxes to silence. Same Laplacian on the right-hand side, very different behaviour on the left. The Laplace in a rectangle demo immediately below is what is left when even the time derivative is zero — the steady state the heat equation generalises toward as t → ∞.

t = 0.000 \text{ s}r = 0.240\max|u| = 0.999

1D heat equation with initial condition "Sine mode 1". α = 0.100, dt = 0.0010 s, stability r = 0.240.

0.100

Thermal diffusivity. Larger α → faster smoothing toward zero.

0.0010 s

FTCS step size. Stability requires r = α·dt/dx² ≤ 0.5.

50

Number of spatial samples on [0, L]. Smaller dx → tighter stability.

t = 0.000 s

Laplace in a rectangle

Iterative Laplace solver on a rectangular domain with mixed Dirichlet boundaries.

iterations: 357converged: residual: 9.70e-7ω: 1.50
30

Grid resolution (used for both nx and ny).

1.50

Successive over-relaxation: 1 = Gauss-Seidel; ≈1.7 often fastest.

100
0
0
0
iter 357 · residual 9.70e-7 · converged ✓

Vector field visualizer

Type any 2D vector field; render its arrows, divergence, and curl.

\max |F| = 1.044\max |\nabla\cdot F| = 0.000\max |(\nabla\times F)_z| = 0.000
0

magnitude / divergence (red = source, blue = sink) / curl (red = CCW, blue = CW)

0

uniform · radial · vortex · saddle — current: uniform

16

Samples along x.

16

Samples along y.

max |F| 1.04 · max |div| 0.00 · max |curl| 0.00

RC / RL step response

First-order circuit step response paired with its frequency response.

\tau = 1.00e-1\,\text{s}t_{90} = 2.30e-1\,\text{s}
0

0 = RC charge · 1 = RC discharge · 2 = RL

100 Ω

Series resistance Ω.

0.001000 F

Capacitance — only relevant for RC modes.

0.500 H

Inductance — only relevant for RL mode.

5 V

Magnitude of the step input.

τ = 1.000e-1 s · t90 = 2.303e-1 s

Biot-Savart B-field

Magnetic field from a current loop or coil, visualised as field lines and arrows.

Plan view · |Bz| heatmap (red out, blue in)
On-axis Bz(z) for circular loop · z ∈ [−3R, 3R]
1.00 A

Loop current in amperes.

1.00 m

Loop radius / half-spacing in metres.

24

Number of straight segments approximating curved carriers.

18

Heatmap grid cells per axis.

0

circular-loop (1/3)

max |Bz| = 0 T · on-axis peak 628.319 nT

Faraday’s law / induced EMF

Slide a magnet through a coil; live flux and induced EMF traces.

Rotating coil in uniform B

Φ(t) and ε(t) over one period

1

Number of loops in the coil. EMF scales linearly with N.

0.50 T

Uniform field strength.

0.050 m²

Loop area enclosing the flux.

60 rad/s

Rotation rate. Peak EMF = N·B·A·ω.

peak ε = 1.500 V · period T = 0.105 s

What’s coming

The author’s written reflection lands alongside the v7 interview. The demos and featured problems above are wired and playable today.