Solve the Schrödinger equation for a particle in a 1D box or finite well, then watch two energy states beat.
Check: running...
The science
Energies are in units of E1 = pi^2 hbar^2/(2 m L^2); for an electron in a 1 nm box E1 = 0.376 eV.
Time-independent: -(hbar^2/2m) psi'' + V(x) psi = E psi
Infinite box: E_n = n^2 pi^2 hbar^2/(2 m L^2), psi_n = sqrt(2/L) sin(n pi x/L)
Superposition: Psi(x,t) = a psi_A e^(-i E_A t/hbar) + b psi_B e^(-i E_B t/hbar)
|Psi|^2 oscillates at (E_B - E_A)/hbar : beat period 2 pi hbar/(E_B - E_A)
The finite well is solved numerically: the Hamiltonian is discretised on 599 grid points (second-order finite differences), giving a tridiagonal matrix. Eigenvalues come from Sturm-sequence bisection and eigenvectors from inverse iteration. Only states with E below V0 are bound. As V0 shrinks the levels drop below n^2 and the wavefunction leaks into the walls as an evanescent tail.
Simplifications: one dimension, rectangular well, no spin, domain truncated to -L...2L with hard outer walls (negligible for the tails shown). Real time is slowed by about 10^15 so femtosecond beating is visible; the playback rate is chosen so one beat lasts about 4 s. A single eigenstate has a static density.
Check: an independent 400-point box-only solve is compared with the closed form n^2 (not with the plotted well).