Skip to main content

Physics V course sequence · Interactive lesson

Matrix Hamiltonians and numerical eigenvalues

Almost no potential you will meet has a closed-form spectrum, so you will diagonalise. This lesson is about doing it honestly: naming which matrix you actually built, why it is symmetric, and how to quote an eigenvalue with an error bar instead of fifteen digits of borrowed confidence.

UPV-04.09 · Lesson 9 of 9 in this unit. Position is not a completion score.
Starting model: Matrix Hamiltonians and numerical eigenvaluesEnergy levels of a particle in a box, ħ = m = L = 1, against level index n. Dashed: the exact spectrum n²π²/2. Solid: what a three-point finite-difference Hamiltonian on N = 20 interior points returns, 2(N+1)² sin²(nπ/(2N+2)). Filled dot exact, open dot grid, at n = 10, where the grid runs 17.3 per cent low.box spectrum: exact vs three-point gridN = 20, h = 0.0476 Ldashed = exact n²π²/2solid = grid ceiling 882n = 10level index n7200
Start with a picture. Change the model in the lab below.
1

Build the model

Every discretisation biases the spectrum. The skill is knowing which way.

The key idea

A matrix Hamiltonian is the finite Hermitian matrix you get by sampling H on a grid or projecting it onto N basis states, real symmetric when V and the basis are real, so that H|ψ⟩ = E|ψ⟩ becomes an ordinary matrix eigenvalue problem a computer solves to rounding precision.

Example. On [0, 1] with ħ = m = 1, V = 0 and four interior points (h = 0.2), H is the 4×4 tridiagonal matrix with 25 on the diagonal and −12.5 beside it; its lowest eigenvalue is 4.7746 against the exact π²/2 = 4.9348.

The complete physical model and assumptions

Every eigenvalue a computer returns belongs to a different operator from the one you wrote down, and the whole skill is knowing which way it differs. Sampling ψ on a grid replaces d²/dx² by a three-point difference, whose eigenvalue on the mode e(ikx) is not −k² but −(4/h²)sin²(kh/2); that is smaller in magnitude for every k, short by k⁴h²/12, so grid levels sit below the truth and the deficit grows as the fourth power of the wavenumber. Expanding instead in N basis functions and diagonalising ⟨φₘ|H|φₙ⟩ does the opposite: you are minimising the true quadratic form over a subspace of the true Hilbert space, so by the Rayleigh–Ritz theorem every root is an upper bound, falling monotonically as the basis grows. Cutting the domain at finite walls is a third and independent lie, turning the continuum above the well into a ladder of invented levels and squeezing the genuine ones upward. Both matrices are Hermitian, and real symmetric whenever V and the basis functions are real, which is why scipy.linalg.eigh rather than eig is the right call and why the eigenvectors come back orthogonal for free. What all this costs is a second run: the method of this subject is not "diagonalise" but "diagonalise again with a different h, a different basis size and a wider box, and quote only the digits that did not move."

1From a wavefunction to a column vector

Choose a window, place N interior points at xⱼ = xₘᵢₙ + jh with h = (xₘₐₓ − xₘᵢₙ)/(N + 1), and let ψⱼ = ψ(xⱼ). The three-point second difference ψ″(xⱼ) ≈ (ψ(j−1) − 2ψⱼ + ψ(j+1))/h² turns −ħ²ψ″/2m + Vψ = Eψ into a matrix equation with diagonal ħ²/(mh²) + V(xⱼ) and both off-diagonals −ħ²/(2mh²). The walls enter as ψ₀ = ψ(N+1) = 0, which is why those terms simply drop out of the first and last rows: the Dirichlet condition is built into the matrix, not imposed on the answer afterwards. For a real V the matrix is real symmetric, so scipy.linalg.eigh returns real eigenvalues and an orthogonal eigenvector matrix by construction; scipy.linalg.eig returns the same numbers as a complex array, with nothing to guarantee that the imaginary parts vanish or that the eigenvectors are orthogonal. Because this H is tridiagonal, scipy.linalg.eigh_tridiagonal costs O(N²) against dense eigh's O(N³), which on N = 4000 is the difference between a second and a minute.

2What the three-point Laplacian actually diagonalises

Feed the difference operator a plane wave ψⱼ = e(ikxⱼ). Then (ψ(j−1) − 2ψⱼ + ψ(j+1))/h² = ψⱼ(e(−ikh) − 2 + e(ikh))/h² = −ψⱼ (4/h²) sin²(kh/2). So the grid's kinetic energy is (2ħ²/mh²)sin²(kh/2), not ħ²k²/2m. Expanding, (4/h²)sin²(kh/2) = k² − k⁴h²/12 + …, so every mode is short by ħ²k⁴h²/24m: the bias is negative and grows as the fourth power of the wavenumber. Two consequences you should carry away as numbers. Demanding 1% accuracy needs k²h²/12 < 0.01, i.e. kh < 0.35, which is about 18 grid points per de Broglie wavelength — the answer to "how fine a grid?". And the kinetic energy saturates at 2ħ²/mh², a hard ceiling. For the box on [0, L] the result is exact rather than asymptotic, Eₙ(h) = (2ħ²/mh²)sin²(nπh/2L), so on N = 12 points the twelfth level comes back 53% low while the first is only 0.49% low.

3Basis truncation errs the other way, and provably

The alternative is to keep the operator and shrink the space: pick N functions φ₁…φN obeying the boundary conditions, form Hₘₙ = ⟨φₘ|H|φₙ⟩ and Sₘₙ = ⟨φₘ|φₙ⟩, and solve Hc = ESc. This is Rayleigh–Ritz, and the Hylleraas–Undheim–MacDonald theorem says the k-th root is an upper bound on the k-th exact eigenvalue and decreases monotonically as functions are added, because you are minimising the same quadratic form over a subspace of the true Hilbert space. On [0, 1] with ħ = m = 1, the single trial function x(1 − x) gives ⟨φ|H|φ⟩/⟨φ|φ⟩ = (1/6)/(1/30) = 5.0000 against the exact 4.93480 — high by 1.3%, as it must be. Add x²(1 − x)² and the 2×2 generalised problem drops it to 4.93487. Two warnings. With a non-orthogonal basis you must pass S, or the roots bound nothing; and a nearly linearly dependent basis makes S ill-conditioned, at which point the extra digits are numerical noise rather than physics.

4The walls invent a spectrum of their own

A grid needs a finite window, and that window is a third approximation entirely independent of h. Put walls a distance W apart around a well supporting, say, three bound states, and eigh will hand back several hundred eigenvalues. Only those below V(∞) are candidates for bound states; everything above is the continuum chopped into a ladder set by the box, with rungs roughly ħ²π²j²/(2mW²) above V(∞). The test is not to stare at the number but to move the wall: a genuine bound state's energy stops moving once W exceeds a few decay lengths κ⁻¹ = ħ/√(2m(V(∞) − E)), while an artefact level falls as 1/W². The walls also bias the genuine levels, and they bias them upward, because clipping the exponential tail is extra confinement. So the grid pushes levels down and the box pushes them up, and for one unlucky pair of h and W the two can cancel: a single run cannot tell you which error you are looking at.

5Convergence is a two-parameter study, not just a fine grid

Report an eigenvalue the way you report a measurement. Halve h with the box fixed and watch the change: for the three-point Laplacian E(h) = E − Ch² + O(h⁴), so the error should fall by a factor of four, and if it does you have earned the right to Richardson-extrapolate, E ≈ [4E(h/2) − E(h)]/3. On the box that took the ground state from 4.89435 at h = 0.1 (error 4 × 10⁻²) to 4.93427 (error 5 × 10⁻⁴) for no extra matrix. Then widen the box with h fixed and watch again. The two studies must be run separately precisely because their errors have opposite signs. Quote only the digits that survive both. Three cheap assertions belong in the same script: check the matrix equals its own transpose to machine precision, count the nodes of eigenvector n and confirm you get n − 1, and evaluate the residual ‖Hψ − Eψ‖ instead of trusting the solver's return value.

6Reading the eigenvector the solver hands back

eigh returns eigenvectors as columns of unit Euclidean norm, Σⱼ |ψⱼ|² = 1, which is not the quantum normalisation. The discrete inner product carries the measure: ⟨ψ|ψ⟩ = h Σⱼ |ψⱼ|², so divide the returned column by √h before computing ⟨x⟩ or overlaying an analytic ψ(x). The overall sign is arbitrary — eigh may equally hand you −ψ — so fix a convention, such as making the first nonzero component positive, before comparing two runs. Degeneracy needs the same care: inside a degenerate block the solver returns some orthonormal basis of the eigenspace, not the one your symmetry argument chose, so label states by a commuting observable rather than by whatever order came back. And a pair split by less than the grid error is not resolved at all, however many digits the printout shows.

2

Key equations

Read the units, assumptions and limits before substituting.

Three-point Hamiltonian matrix

Hⱼⱼ = ħ²/(mh²) + V(xⱼ), H(j, j±1) = −ħ²/(2mh²)

Real, symmetric and tridiagonal: hand it to eightridiagonal at O(N²) rather than dense eigh at O(N³).

xⱼ = xₘᵢₙ + jh for j = 1…N; h the grid spacing in m, V in J, entries in J

Grid dispersion relation

Tgrid(k) = (2ħ²/mh²) sin²(kh/2)

The grid's own kinetic spectrum. It saturates at 2ħ²/mh², so no eigenvalue above that ceiling can exist at all.

k in rad m⁻¹, h in m; the exact operator gives ħ²k²/2m, equal only as kh → 0

Leading grid error, signed

Eₙ(h) = Eₙ − ħ²kₙ⁴h²/24m + O(h⁴)

Halving h quarters the error, and every level is biased low, never high — the grid gives no upper bound.

Eₙ in J, h in m, kₙ = nπ/L in rad m⁻¹ for the box; the sign is fixed, the deficit is never negative

Richardson extrapolation

E ≈ [4E(h/2) − E(h)]/3

Two runs buy an h⁴ answer: 4.77458 and 4.89435 combine to 4.93427 against the exact 4.93480.

E(h) the eigenvalue computed on spacing h, in J; valid while the h² term dominates

Rayleigh-Ritz upper bound

Eₖ(N) ≥ Eₖ(N+1) ≥ Eₖ

Basis truncation errs upward while the grid errs downward, so running both brackets the exact level.

Eₖ(N), in J, is the k-th root of Hc = ESc over N nested basis functions; Eₖ the exact k-th level

Non-orthogonal basis: the overlap matrix

H c = E S c, Sₘₙ = ⟨φₘ|φₙ⟩

Pass S to scipy.linalg.eigh(H, S), or the roots are not variational bounds on anything.

Hₘₙ and E in J; S is dimensionless and positive definite; S = I only for an orthonormal basis
3

Interactive lab

Predict first. Explore the model. Compare the result.

Explore the model

20
12 to 60; steps of 1.
10
1 to 12; steps of 1.

Try this. Drag N down to 12 and step n up: the grid tracks the exact parabola while there are more than about 18 points per wavelength, then peels away, the top level landing at under half its true energy. Push N to 60 and that same level climbs back to within a few per cent.

Live results

EXACT Eₙ
493.48 ħ²/mL²
GRID Eₙ
408.04 ħ²/mL²
GRID DEFICIT
17.31 % low
POINTS PER WAVELENGTH
4.2

Results follow this lesson’s model and assumptions. Displayed values are rounded.

Interactive Physics V modelEnergy levels of a particle in a box, ħ = m = L = 1, against level index n. Dashed: the exact spectrum n²π²/2. Solid: what a three-point finite-difference Hamiltonian on N = 20 interior points returns, 2(N+1)² sin²(nπ/(2N+2)). Filled dot exact, open dot grid, at n = 10, where the grid runs 17.3 per cent low.box spectrum: exact vs three-point gridN = 20, h = 0.0476 Ldashed = exact n²π²/2solid = grid ceiling 882n = 10level index n7200
Energy levels of a particle in a box, ħ = m = L = 1, against level index n. Dashed: the exact spectrum n²π²/2. Solid: what a three-point finite-difference Hamiltonian on N = 20 interior points returns, 2(N+1)² sin²(nπ/(2N+2)). Filled dot exact, open dot grid, at n = 10, where the grid runs 17.3 per cent low.

Predict → change one variable → check

Plan a change before running it. Every other input stays at the saved baseline.

Saved baseline. Interior grid points N: 20; Level index n: 10

Baseline 20; choose 12 to 60, in steps of 1.
4. Compared with the saved baseline, this result will…

This experiment is kept only while this page is open. It does not change saved course progress.

4

Catch the common trap

The error to name is "my computed levels are upper bounds, because diagonalising is variational." That is true of Rayleigh–Ritz and false of a finite-difference grid. Rayleigh–Ritz restricts the true H to a subspace of the true Hilbert space, so a minimum taken over a smaller set can only come out larger, and every root sits above its exact level. A grid does not restrict H; it substitutes a different operator whose kinetic part obeys (4/h²)sin²(kh/2) ≤ k², strictly smaller on every mode, so its levels come out below. Worse, the finite box the grid lives in pushes those same levels up, so for one unlucky choice of h and box width the two errors partly cancel and a badly converged number looks converged. Vary h and the box width separately, or you will not know which digit you are reading.

5

Practice & worked examples

3 authored examples. Make an attempt, then reveal the reasoning one step at a time.

EasyExample 1

Take the infinite well on [0, 1] with ħ = m = 1 and V = 0 inside, and put four interior grid points on it. Write down the 4×4 finite-difference Hamiltonian, then find its lowest eigenvalue using the standard result that a tridiagonal matrix of size N with diagonal d and off-diagonals −c has eigenvalues d − 2c cos(jπ/(N + 1)). Compare with the exact ground state.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 4 steps revealed.

MediumExample 2

Keep the same box but use nine interior points, h = 0.1, with the closed form Eₙ(h) = (2ħ²/mh²)sin²(nπh/2L) for the grid eigenvalues. Show that the error in E₁ scales as h², combine the two grids into a better value, then work out what the same grid does to the top level, n = 9.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 4 steps revealed.

HardExample 3

Bracket the ground state of the same box from both sides, with ħ = m = L = 1. (a) Take the h = 0.1 grid value as the low estimate. (b) Compute the Rayleigh quotient of the trial function φ(x) = x(1 − x), which satisfies both boundary conditions. (c) Explain why the two numbers must straddle the exact energy, verify that they do, and then tighten the upper bound with a second trial function φ₂(x) = x²(1 − x)².

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 5 steps revealed.

6

Quick check

Select an answer and explain it before checking.

The infinite well on [0, L] is solved by diagonalising a three-point finite-difference Hamiltonian on a uniform grid of N interior points, spacing h = L/(N + 1). Compared with the exact Eₙ = n²π²ħ²/(2mL²), where do the computed levels sit, and which of them are worst?
7

Review & continue

A matrix Hamiltonian is the finite Hermitian matrix you get by sampling H on a grid or projecting it onto N basis states, real symmetric when V and the basis are real, so that H|ψ⟩ = E|ψ⟩ becomes an ordinary matrix eigenvalue problem a computer solves to rounding precision.

  • Explain the relationship without looking at the equation.
  • Check a sign, a unit and a model assumption in your working.
  • Return to the lab or worked example if a step is still unclear.

Extra challenging questions

Connect several ideas, explore supplied data, and compare your reasoning with a worked solution.