Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 38 · Particle in a Box and Barriers

Solving the Schrödinger Equation Numerically

Turn the Schrödinger equation into a matrix eigenvalue problem with finite differences, test it on the box and finite well, and study convergence in Python.

Only a handful of potentials have exact solutions. Anything else, such as a double well, a molecule's vibration curve or a quantum dot with a realistic shape, needs a computer. Fortunately the one-dimensional Schrödinger equation is easy to solve numerically. The main idea: replace the continuous function ψ(x) by its values on a grid, and the derivative by differences between neighbors. The equation then becomes a matrix eigenvalue problem, and the eigenvalues are the energy levels.

This lesson builds a small, reliable solver, validates it against results you already know, and uses it on a potential with no pencil-and-paper solution. You will reuse the same solver in later chapters.

From differential equation to matrix

The equation is

Text
-(ħ² / 2m) ψ''(x) + V(x) ψ(x) = E ψ(x)

Divide the region into N interior points x_j = j·Δx for j = 1, ..., N and require ψ = 0 at both ends (walls placed far enough away not to matter for the states you want). The central difference approximation of the second derivative is

Text
ψ''(x_j) ≈ ( ψ_{j+1} - 2ψ_j + ψ_{j-1} ) / Δx²

Insert it into the equation and you get, for every j,

Text
-(ħ²/2m Δx²) ψ_{j-1} + ( ħ²/(m Δx²) + V_j ) ψ_j - (ħ²/2m Δx²) ψ_{j+1} = E ψ_j

That is H ψ = E ψ with a tridiagonal matrix H:

  • diagonal entries ħ²/(m Δx²) + V_j,
  • the two neighboring diagonals -ħ²/(2m Δx²),
  • zeros elsewhere.

Finding the lowest few eigenvalues and eigenvectors of a tridiagonal symmetric matrix is fast and stable; scipy.linalg.eigh_tridiagonal does exactly that. The eigenvalues approximate the energies, and the eigenvectors approximate the wavefunctions (sampled at the grid points, with norm 1 as vectors, so divide by √Δx to get a function normalized as ∫|ψ|² dx = 1).

Work in convenient units. For electrons and nanometer-scale problems, use x in nm and E in eV. Then ħ²/(2m_e) ≈ 0.0381 eV·nm², a number the code computes for you from CODATA constants. For abstract problems use ħ = m = 1.

Test 1: the infinite well

Always test a new solver on a problem with a known answer. With V = 0 inside a box of width L = 1 nm the exact energies are E_n = n² · 0.376 eV (from the first lesson of this chapter). The editor builds H, solves for the lowest five states, and prints errors.

Python A finite-difference solver, tested on the box

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 error is small and grows with n, because higher states oscillate faster and a fixed grid resolves them less well.

Test 2: the finite well, compared with the root finder

In the previous lessons you found the ground-state energy of a 10 eV deep, 1 nm wide well by solving a transcendental equation: E₁ ≈ 0.2976 eV. The matrix method must reproduce it. The potential is a simple array: 10 outside the well, 0 inside. Make the computational box wide enough (here ±3 nm) that the evanescent tails have died away before the grid ends.

Python Finite well: matrix method vs. root finding

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 numeric levels agree with the root-finder values to within about half a percent. The small remaining difference comes from where the sharp edges of the well fall on the grid; a finer grid, or edges placed exactly between grid points, reduces it. Both methods answer the same question, and the matrix method needs no analysis at all, only an array describing V(x).

A potential you cannot solve by hand

A double well has two minima separated by a barrier. It models a particle that can sit in either of two positions, for example an atom between two sites in a crystal or the nitrogen atom in ammonia (above or below the plane of the hydrogens). Its lowest two states are an even and an odd combination of states localized in each well, with an energy splitting that is exponentially sensitive to the barrier: that is tunneling. The editor below uses a smooth model V(x) = V₀ [ (x/a)² - 1 ]² and shows how the splitting E₂ - E₁ shrinks as the barrier grows.

Python Double well: tunnel splitting

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 splitting falls sharply as the barrier rises, the exponential dependence you met in the tunneling lesson. In a symmetric double well, the ground state is always even and the first excited state always odd.

Choosing a grid

Two checks make the numerical answer trustworthy.

  1. Box size. The walls at the ends of the grid must be far from where the wavefunction is non-negligible. Increase the box until the energies stop changing.
  2. Spacing. The error of the central difference scales as Δx²: halve Δx and the error falls by about 4. A quick convergence test with three values of Δx tells you how many digits to trust. Also make sure Δx is much smaller than the shortest wavelength of the states you want, at least ten points per wavelength.

Another warning: the lowest eigenvalues of the matrix are accurate, but the highest ones (near the largest E the grid can represent) are not physical. Only use the lowest few states.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In the finite-difference method, the second derivative ψ'' at grid point j is approximated by

    The central second difference uses three neighboring points and divides by Δx². It is accurate to order Δx².
  2. 2. After discretization, the Schrödinger equation becomes

    Each grid point gives one equation, and the whole set is H ψ = E ψ. The eigenvalues are the energies.
  3. 3. You halve Δx and the ground-state energy barely changes, but the n = 5 energy changes noticeably. What does this suggest?

    Higher states have shorter wavelengths, so they need more points per wavelength to be resolved accurately.
  4. 4. Why does the tunnel splitting of a symmetric double well shrink when the barrier is raised?

    The splitting measures the coupling between the two wells, which is a tunneling effect and decreases roughly as e^(−2κa).

Summary

  • Discretizing x turns the Schrödinger equation into H ψ = E ψ, with a tridiagonal H whose diagonal is ħ²/(mΔx²) + V_j and off-diagonals -ħ²/(2mΔx²).
  • scipy.linalg.eigh_tridiagonal returns the lowest energies and wavefunctions; divide eigenvectors by √Δx to normalize.
  • Validate on known cases (infinite and finite well) before trusting a new potential.
  • Check convergence in box size and grid spacing; error scales as Δx².
  • The same method handles any 1D potential, such as the double well, where it shows an exponentially small tunnel splitting.

Next: Operators and Observables