Skip to content

Physics · Quantum Mechanics · common

Particle in a Box

walls force whole half-waves, so energy comes in steps

A particle trapped between hard walls can only hold standing waves, so its energy is quantized as n² and superpositions slosh at beat frequencies.

View .md
Interactive visual

The cyan curve is the probability density |Ψ|², the orange curve above it is Re Ψ, and the yellow cone marks the mean position ⟨x⟩. Raise the excited-state mix or pick an even level n to make the density slosh between the grey walls; the readout gives the beat period.

What it is

Put a particle between two infinitely high walls a distance L apart. The wavefunction must vanish at both walls, so only waves that fit a whole number of half-wavelengths survive: sin(nπx/L) for n = 1, 2, 3…. Each of these eigenstates has a fixed energy that grows as n².

A single eigenstate is *stationary*: its phase spins at a rate set by its energy, but |ψ|² never changes. Mix two eigenstates and the phases drift apart. Their interference makes the probability density slosh from wall to wall at the beat frequency (E_n − E_1)/ħ.

This is the simplest model of quantization (electrons in a quantum dot, conjugated molecules, a guitar string's harmonics) and a good first test case for any Schrödinger solver, because the answer is exact. Real walls are finite, which is where tunneling comes in.

Key formulas

Eigenstates
Energy levels
Two-state superposition
Beat period of the density

With even n the density sloshes left–right; odd n keeps ⟨x⟩ = L/2 by symmetry.

Rules of thumb

  • Natural units (ħ = m = L = 1, energies in E_1) keep the numbers near 1; the visual uses them.
  • An electron in a 1 nm box has E_1 ≈ 0.38 eV, so the n = 1 → 2 gap is ≈ 1.1 eV (near-infrared light).
  • Sample at least ~20 points per half-wave: n = 6 needs ≥ 120 samples across the box to look smooth.
  • Amplitudes are √(probability): a 45 % excited mix means a_n = √0.45 ≈ 0.67, not 0.45.

Implementation

Probability density of a two-level superposition, written into a reusable buffer:
// Natural units: ħ = m = L = 1, energies in units of E1, so E_n = n².
export function boxDensity(
  out: Float32Array, // length = samples
  t: number,
  n: number,
  mix: number // probability in the excited state, 0..1
) {
  const a1 = Math.sqrt(1 - mix)
  const an = Math.sqrt(mix)
  const c1 = Math.cos(t), s1 = Math.sin(t)
  const cn = Math.cos(n * n * t), sn = Math.sin(n * n * t)
  for (let i = 0; i < out.length; i++) {
    const x = i / (out.length - 1)
    const p1 = Math.SQRT2 * a1 * Math.sin(Math.PI * x)
    const pn = Math.SQRT2 * an * Math.sin(n * Math.PI * x)
    const re = p1 * c1 + pn * cn
    const im = -(p1 * s1 + pn * sn)
    out[i] = re * re + im * im // integrates to 1 over [0, 1]
  }
  return out
}

Common mistakes

  • Using the mix probability as the amplitude, which breaks normalization; amplitudes are square roots.
  • Animating each eigenstate's density on its own: a single eigenstate's |ψ|² never moves; only the cross term oscillates.
  • Giving every level the same phase speed. The phase rate is E_n/ħ ∝ n², which sets the beat frequency.
  • Forgetting the √(2/L) normalization when changing L, so the total probability drifts away from 1.

Prompt

Write a TypeScript module plus a Three.js visual for a particle in an infinite square well. Use natural units (ħ = m = L = 1, E_n = n²). Export boxDensity(out: Float32Array, t, n, mix) that fills |Ψ(x,t)|² for Ψ = √(1−mix)·ψ1·e^{−it} + √mix·ψn·e^{−in²t} with ψk = √2·sin(kπx), allocation-free. Render the density as a line between two wall meshes and move a marker to ⟨x⟩ each frame by updating buffers in place. Clamp n to integers 2–6 and mix to 0–0.95. Write unit tests: the density integrates to 1 (trapezoid rule, 1e-3 tolerance) at several times, and with mix = 0 it is time-independent.

Further reading

Updated 2026-11-01