This solves the real time-dependent Schrödinger equation on a 2D grid, ħ∂ψ/∂t = −ħ²/2m ∇²ψ + Vψ (ħ=m=1), by splitting ψ into real and imaginary parts and stepping them with a staggered (leapfrog) finite-difference scheme so no complex arithmetic library is needed:
ψ_im += dt·(0.5∇²ψ_re − V·ψ_re)
ψ_re −= dt·(0.5∇²ψ_im − V·ψ_im)
A Gaussian wavepacket is launched at a vertical potential wall. When the barrier height V₀ exceeds the packet's kinetic energy k²/2, classical mechanics forbids crossing — but the "Transmitted P" readout (the probability integrated past the barrier) climbs above zero anyway: that is genuine quantum tunneling, not decoration. The Δx and ⟨pₓ&rangle readouts are computed live from the wavefunction itself (position variance and the momentum expectation value −iψ*∂ψ/∂x, integrated) so you can watch Δx grow as the packet disperses — the position-momentum trade-off behind the Heisenberg uncertainty principle. "Measure" performs a real projective measurement: it samples a position from the |ψ|² distribution and collapses the wavefunction into a narrow packet there, exactly as the measurement postulate describes.
- Color — probability density |ψ|² (brighter = more likely to find the particle there).
- Dashed line — the potential barrier; its brightness follows V₀.
- Total probability — should stay near 1.000; it is the numerical-integrity check for the solver itself.