Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

DEMO: Numerical Schrödinger Solver

From differential equation to matrix problem

We want the bound states of the time-independent Schrödinger equation on 0xL0 \le x \le L with hard walls, the same boundary conditions as the particle in a box:

22md2ψdx2+V(x)ψ(x)=Eψ(x),ψ(0)=ψ(L)=0-\frac{\hbar^2}{2m}\frac{d^2\psi}{dx^2} + V(x)\,\psi(x) = E\,\psi(x), \qquad \psi(0) = \psi(L) = 0

Instead of guessing a functional form for ψ(x)\psi(x), we store its values ψ1,ψ2,,ψN\psi_1, \psi_2, \dots, \psi_N at NN evenly spaced grid points, as sketched in Figure 1. On the grid, the second derivative at point jj is approximated by the classic three-point formula Press et al., 2007:

d2ψdx2xjψj+12ψj+ψj1Δx2\frac{d^2\psi}{dx^2}\bigg|_{x_j} \approx \frac{\psi_{j+1} - 2\psi_j + \psi_{j-1}}{\Delta x^2}
A smooth wavefunction sampled at evenly spaced grid points between two hard walls

Figure 1:A wavefunction sampled on a uniform grid between hard walls. The curvature at point jj is built from the point and its two neighbors (red circles), which turns the differential equation into a matrix problem.

Substituting (2) into (1) gives one linear equation per grid point. Collecting them produces a matrix eigenvalue problem Hψ=Eψ\mathbf{H}\,\boldsymbol{\psi} = E\,\boldsymbol{\psi} with a tridiagonal Hamiltonian: kinetic energy couples each point only to its two neighbors, and the potential sits on the diagonal.

H=22mΔx2(2112112)+(V1V2VN)\mathbf{H} = \frac{\hbar^2}{2m\,\Delta x^2} \begin{pmatrix} 2 & -1 & & \\ -1 & 2 & -1 & \\ & \ddots & \ddots & \ddots \\ & & -1 & 2 \end{pmatrix} + \begin{pmatrix} V_1 & & & \\ & V_2 & & \\ & & \ddots & \\ & & & V_N \end{pmatrix}

Diagonalizing H\mathbf{H} hands us energies and wavefunctions in one shot. The LAPACK routines that do this are the same machinery running inside every modern quantum chemistry package.

A box with a barrier inside

As a test system we take the unit box and drop a rectangular barrier of height V0V_0 and width L/4L/4 into the middle. With =m=L=1\hbar = m = L = 1, the natural energy unit is the ground-state energy of the empty box from the particle in a box lecture:

E1=π222mL2=h28mL2E_1 = \frac{\pi^2 \hbar^2}{2mL^2} = \frac{h^2}{8mL^2}

For V0=0V_0 = 0 the solver must reproduce En=n2E1E_n = n^2 E_1 exactly, which is a good sanity check. As V0V_0 grows, the box splits into two weakly coupled half-boxes, and pairs of levels squeeze together into doublets: a symmetric state with no node at the center and an antisymmetric partner with one. Their tiny energy difference is the tunneling splitting, the standard textbook route to double-well physics Griffiths & Schroeter, 2018.

The live solver

We need only the course’s standard scientific stack: NumPy for arrays, SciPy for the tridiagonal eigensolver, and Matplotlib for plots.

The solver builds the two diagonals of H\mathbf{H} and asks SciPy for the lowest few eigenpairs. Dividing the eigenvectors by Δx\sqrt{\Delta x} normalizes them so that ψ2dx=1\int |\psi|^2\,dx = 1.

Drag the slider to raise or lower the barrier. Everything below it reacts.

With the barrier at zero you should read off E/E1=1,4,9,16E/E_1 = 1, 4, 9, 16, the exact particle in a box ladder. Raise the barrier and watch n=1,2n = 1, 2 collapse onto each other while keeping opposite symmetry about the center.

Tunneling doublets across all barrier heights

A single click of the slider solves one Hamiltonian. The cell below instead sweeps the full range of barrier heights, a moderately expensive computation: 51 diagonalizations of a 2000×20002000 \times 2000 matrix, tracking the six lowest states. Because it does not read the slider, marimo executes it once and reuses the cached result no matter how much you play with the plots.

The correlation diagram replots instantly when you move the slider, because only the cheap plotting cell reruns, not the sweep.

References
  1. Press, W. H., Teukolsky, S. A., Vetterling, W. T., & Flannery, B. P. (2007). Numerical Recipes: The Art of Scientific Computing (3rd ed.). Cambridge University Press.
  2. Griffiths, D. J., & Schroeter, D. F. (2018). Introduction to Quantum Mechanics (3rd ed.). Cambridge University Press. 10.1017/9781316995433