Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 39 · Getting Started

Matrix Methods for Hamiltonians

Turn the Schrödinger equation into an eigenvalue problem with grids and basis sets, test convergence, and build a numerical toolkit for the whole track.

A computer cannot store a function on a continuous line, but it can store a vector of numbers. Once you choose how to represent a state as a vector, the Hamiltonian becomes a matrix and the time-independent Schrödinger equation H ψ = E ψ becomes the eigenvalue problem you know from linear algebra.

This lesson builds two numerical tools that you will use throughout the track: a grid method (finite differences) and a basis-set method (expansion in known functions). It also teaches the habit that separates reliable numerics from wishful thinking: always test convergence.

Method 1: the position grid

Choose N equally spaced points xᵢ = x₀ + iΔx. A wave function becomes the vector ψᵢ = ψ(xᵢ). The potential is diagonal: V multiplies each ψᵢ by V(xᵢ). The kinetic operator needs the second derivative, approximated by

Text
ψ''(xᵢ) ≈ (ψᵢ₊₁ − 2ψᵢ + ψᵢ₋₁) / Δx²

With ħ = m = 1, the kinetic energy −½ d²/dx² becomes a tridiagonal matrix with 1/Δx² on the diagonal and −1/(2Δx²) on the two neighbouring diagonals. The Dirichlet boundary (ψ = 0 at the ends of the grid) is built in, so the box must be large enough that the true wave function has died away there.

Python Finite-difference harmonic oscillator

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 grid error shrinks like Δx². If you double the number of points, the error drops by about a factor of four, so you can check that your answer is converged.

Python Convergence with grid spacing

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.

Each time you halve Δx (roughly doubling N), the error ratio should approach 4. When the ratio stops behaving that way, the box size or round-off becomes the limit instead.

Method 2: the basis set

Instead of sampling at points, expand in a set of known functions |φₙ⟩: |ψ⟩ = Σ cₙ |φₙ⟩. Then

Text
Σₘ Hₙₘ cₘ = E cₙ,   where Hₙₘ = ⟨φₙ|H|φₘ⟩

If the basis is orthonormal, this is an ordinary matrix eigenvalue problem. In the Dirac notation of Chapter 2, this is the statement that an operator is a matrix whose entries are matrix elements.

A good basis makes the matrix nearly diagonal. For a nearly harmonic system, use harmonic-oscillator eigenstates: the position operator is x = (a + a†)/√2 with a the lowering matrix (⟨n−1|a|n⟩ = √n). Any polynomial potential becomes a polynomial in the matrices a and a†.

Python Double-well in the oscillator basis

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.

Here H = H₀ + ½(k − 1)x² + λx⁴, which equals p²/2 + ½ k x² + λx⁴; with k = −0.8 and λ = 0.1 the potential has two minima at V = −0.4, separated by a barrier whose top is at V = 0. This is a shallow well, so the lowest level sits just below the barrier top. Watch how the numbers stabilize as N grows. If the first digits keep changing, the basis is too small or poorly matched to the problem.

Choosing between the methods

Grid Basis set
Matrix Large, very sparse Small, dense
Accuracy Slow (power of Δx) Fast if the basis suits the problem
Strength Any potential, no analytic work Matrix elements analytic, few states needed
Weakness Many points Bad basis can converge slowly

When a new problem arrives, solve a case you know exactly first (a pure harmonic oscillator, a particle in a box) to validate your code. Only then add the difficult term.

Common pitfalls

  1. Box too small. If the wave function is not essentially zero at the boundary, the artificial wall changes the energies.
  2. Truncation too small. Higher-order terms like x⁴ couple level n to n ± 4; the top of the spectrum is unreliable.
  3. Forgetting units. Decide once whether you are in oscillator units or atomic units.
  4. Trusting eigenvectors blindly. The sign (and for degenerate levels the choice of basis within the subspace) is arbitrary.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In a finite-difference grid, what matrix represents the potential energy?

    The potential multiplies the wave function point by point, so it is diagonal in the position-grid representation.
  2. 2. If halving the grid spacing reduces the error by about a factor of four, the error scales as

    The three-point second-derivative formula has error proportional to Δx².
  3. 3. Why is the top part of a truncated oscillator-basis spectrum unreliable?

    Terms of the Hamiltonian connect states up to the cutoff to ones outside it, so the highest states are poorly represented.
  4. 4. What is the best first test of a new numerical Hamiltonian code?

    Reproducing a known analytic result validates the discretization and the units before you trust results for new problems.

Summary

  • A Hamiltonian becomes a matrix once you pick a grid or a basis; energies are its eigenvalues.
  • Finite differences give a sparse matrix with Δx² error; a basis set gives a small dense matrix with fast convergence when well chosen.
  • Always test against an exact case and check convergence in the box size and basis size.
  • Oscillator-basis matrices let you build any polynomial potential from the ladder operators.

Next: The Postulates of Quantum Mechanics Revisited