Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 38 · The Schrödinger Equation

Solving the Schrödinger Equation Numerically

Build a finite-difference Schrödinger solver in Python: find energy eigenvalues with a tridiagonal Hamiltonian and evolve wave packets in time with Crank-Nicolson.

Exact solutions exist only for a handful of potentials. For everything else, you need a computer. Fortunately, a simple method on a grid gets you surprisingly far: turn the Hamiltonian into a matrix, then either find its eigenvalues (stationary states) or step the wavefunction forward in time. This lesson builds both tools in a few lines of Python, and checks them against known results.

Throughout we use dimensionless units ħ = m = 1. Then lengths are in units of some chosen length scale and energies in units of ħ²/(m·scale²). This keeps numbers of order one. Converting back to SI is a single multiplication, as in the Chapter 1 toolkit lesson.

The discretized Hamiltonian

On a grid with spacing dx, the Hamiltonian Ĥ = -(1/2) d²/dx² + V(x) becomes a tridiagonal matrix:

  • Diagonal: 1/dx² + V(xⱼ)
  • Off-diagonals: -1/(2 dx²)

The matrix is real and symmetric (so Hermitian), which guarantees real eigenvalues. We assume the wavefunction is zero at both ends of the grid ("hard walls"), which is accurate if the grid extends far beyond the region where the state lives.

Step 1: Energy eigenvalues

As a test, use the harmonic oscillator V = x²/2 (with ħ = m = ω = 1). Its exact energy levels are Eₙ = n + 1/2 for n = 0, 1, 2, … (derived in Chapter 7).

Python Eigenvalues of the harmonic oscillator on a grid

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The numerical eigenvalues agree with n + 1/2 to about four decimals for the lowest levels (the error grows for higher levels); a finer grid improves it. (The sign of an eigenvector is arbitrary.)

A different potential: the double well

Now a potential with no closed-form solution, V(x) = (x² - 4)² / 8: two wells at x = ±2 separated by a barrier. The lowest two energy levels form a close pair (a "doublet"): the symmetric and antisymmetric combinations of states in the left and right wells. The small splitting measures how easily the particle tunnels between wells (more in Chapter 5).

Python Double-well levels and states

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The ground state is symmetric about 0 and the first excited state is antisymmetric, as theory predicts for a symmetric potential. Numerically their energies differ by only about 0.05, much less than the spacing to the next level.

Step 2: Time evolution with Crank–Nicolson

To evolve in time, we need ψ(t + Δt) = e^{-iĤΔt} ψ(t) (with ħ = 1). The Crank–Nicolson scheme approximates the exponential by

(1 + iĤΔt/2) ψ(t + Δt) = (1 - iĤΔt/2) ψ(t)

This is a tridiagonal linear system solved at every step. The scheme is accurate to second order in Δt and, crucially, it is exactly unitary for a Hermitian H: the norm is preserved to rounding error, no matter how large the step. Simpler schemes, such as forward Euler, make the norm grow without bound and are useless here.

Python Crank-Nicolson: a displaced packet in a harmonic well

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The expected position follows the classical oscillation x₀ cos t (Ehrenfest's theorem, Chapter 6 shows why), the Gaussian keeps its shape (a "coherent state"), and the norm stays equal to 1 to many digits.

Choosing grid and step sizes

  • Grid range: large enough that ψ is essentially zero at the edges.
  • Grid spacing dx: small compared with the shortest wavelength in the problem 2π/k_max. Packets with high momentum need fine grids.
  • Time step Δt: for Crank–Nicolson, the error is O(Δt²). Halve Δt and see if results change.
  • Test. Always compare against a known case first: harmonic oscillator levels, free-particle spreading, or conservation of norm and energy.

Do not rely on a plot that "looks right". Check the numbers: norm, energy and convergence when you refine the grid. Numerical errors in quantum simulations often look like smooth, plausible physics.

Other methods

  • Split-step Fourier: alternate e^{-iVΔt/2} in x-space and e^{-ik²Δt/2} in k-space using FFTs. Very fast and accurate for smooth potentials.
  • Shooting method: integrate the TISE from one side and adjust E until the boundary condition is met.
  • Basis expansions: write ψ in a convenient basis (for example harmonic-oscillator states) and diagonalize a small matrix.

You will use the matrix approach again in later chapters.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In the finite-difference Hamiltonian with ħ = m = 1, the off-diagonal elements are

    From -(1/2) d²/dx², the three-point stencil gives off-diagonals -1/(2dx²) and diagonal 1/dx² + V.
  2. 2. Why is Crank–Nicolson preferred over forward Euler for the Schrödinger equation?

    Forward Euler multiplies the norm by a factor greater than 1 each step; Crank–Nicolson preserves it.
  3. 3. For the harmonic oscillator with ħ = m = ω = 1, the energy levels are

    Eₙ = ħω(n + 1/2) for n = 0, 1, 2, …
  4. 4. Which check best builds confidence in a numerical solution?

    Validation against exact results and convergence under refinement are the standard tests.

Summary

  • On a grid, Ĥ is a symmetric tridiagonal matrix: diagonal 1/dx² + V, off-diagonals -1/(2dx²) (units ħ = m = 1).
  • Eigenvalues and eigenvectors (eigh_tridiagonal) give stationary states and energies.
  • Crank–Nicolson steps the wavefunction in time while preserving the norm exactly.
  • Validate with known cases (harmonic oscillator), conservation laws and grid refinement.

Next: back to the Quantum Mechanics track