Β§0.3The Hamiltonian as a Matrix

Toolkit Site-original β€” not in the book Β· ~17 min read

  • Hamiltonian
  • eigenfunction
  • stationary state
  • finite difference
  • natural units

The SchrΓΆdinger operator only ever touches neighbouring points. That locality is why its matrix has three diagonals, why the energies come out real, and why the whole thing runs in a browser.

Here is the single most valuable thing on this site.

Chapters 3 through 6 of Phillips work out the energy levels of a particle in a box, then a finite well, then a barrier, then a harmonic oscillator β€” each with its own boundary conditions, its own transcendental equation, its own special functions. It is worth following that algebra, and the site will follow it.

But all four are the same computation, and it is four lines long:

Put xx on a grid. Build H^\hat H as a matrix β€” a finite-difference second derivative plus V(x)V(x) down the diagonal. Diagonalize it. The eigenvalues are the energy levels and the eigenvectors are the stationary states.

Learn it once here and every later chapter becomes a check on something you can already compute. Every interactive plot on this site is produced by this recipe, running live in your browser.

Where the matrix comes from

A state of definite energy β€” a stationary state β€” satisfies the time-independent SchrΓΆdinger equation, in which the Hamiltonian H^\hat H is the total-energy operator :

H^ψ=Eψ,H^=βˆ’β„22md2dx2+V(x)\hat H \psi = E \psi, \qquad \hat H = -\frac{\hbar^2}{2m}\frac{d^2}{dx^2} + V(x)

That is already an eigenvalue equation β€” it says β€œapplying H^\hat H to ψ\psi gives back ψ\psi, scaled”. The only obstacle is that H^\hat H contains a derivative, and you cannot hand a derivative to numpy.linalg.eigh. So we replace it with something we can.

Substitute the stencil and the operator becomes a matrix. Writing t=ℏ2/2m(Ξ΄x)2t = \hbar^2/2m(\delta x)^2, the row for grid point ii reads

βˆ’tβ€‰Οˆiβˆ’1+(2t+V(xi))ψiβˆ’tβ€‰Οˆi+1=Eβ€‰Οˆi-t\,\psi_{i-1} + \big(2t + V(x_i)\big)\psi_i - t\,\psi_{i+1} = E\,\psi_i

which is one row of Hψ=Eψ\mathbf{H}\boldsymbol\psi = E\boldsymbol\psi with

H=(2t+V1βˆ’tβˆ’t2t+V2βˆ’tβˆ’t2t+V3β‹±β‹±β‹±)\mathbf{H} = \begin{pmatrix} 2t + V_1 & -t & & \\ -t & 2t + V_2 & -t & \\ & -t & 2t + V_3 & \ddots \\ & & \ddots & \ddots \end{pmatrix}

Almost every entry is zero. Only three diagonals survive, and that is the whole shape of the problem:

000000000000000000000000000000000000000000grid point j β†’grid point i β†’Γ—Οˆ=Eψdiagonal: 2t + V(xα΅’)the potential energy β€” the only placethe specific problem entersoff-diagonals: βˆ’tthe kinetic energy β€” the price ofhopping to the neighbouring pointeverything else: exactly zero, because thestencil only ever touches nearest neighbourssymmetric β‡’ real eigenvalues β‡’ the energies you measure are real numbers

The discretized Hamiltonian. Three diagonals carry everything: the potential sits on the main one, the kinetic coupling on its two neighbours.

The discretized Hamiltonian, piece by piece

symbol
is
the grid spacing β€” how finely you chop up space. The one number you choose; everything else follows from the physics.
units
type
real scalar

Click any symbol to see what it is, what units it carries, and what kind of object it is once you put it in an array.

The four lines

To solve a different problem, change one line. Replace V = np.zeros(N) with V = np.where(abs(x) < w/2, -V0, 0) and you have the finite well of chapter 5. Replace it with V = 0.5*m*omega**2*x**2 and you have the harmonic oscillator of chapter 6. Nothing else moves.

Try it

Every curve below is computed by exactly the recipe above, live, as you drag.

Potential explorer β€” drag a knob, re-solve, watch the levels move

-8-6-4-202468-10-50position x (natural units, Δ§ = m = 1)energyE0E1E2E3E4
  • V(x)
  • energy level Eβ‚™
  • Οˆβ‚™(x)
  • classically forbidden (V > E)
selected level
E0 = -11.5791
nodes in ψ
0
bound states
5
E₁ βˆ’ Eβ‚€
1.2549

Make the well shallower or narrower and watch the top level rise to zero and vanish into the continuum. Note that ψ does not stop at the wall β€” it leaks into the shaded forbidden region, which is tunnelling in its simplest form.

Click any gold line to select that level. Every number here comes from building H as a tridiagonal matrix on a 700-point grid and diagonalizing it β€” the same four lines of NumPy shown on this page, and the count of bound states comes free from a Sturm sequence without computing a single eigenvalue.

Things worth doing before you move on:

  • Shrink the finite well’s depth. Watch the top level climb towards zero and then vanish. The counter tells you how many bound states are left. Chapter 5 derives the condition for this; you can find it here by dragging.
  • Switch to the infinite well. Levels go as n2n^2 β€” the gaps get wider.
  • Switch to the harmonic oscillator. Levels are evenly spaced, and the lowest one is not at the bottom of the well. That leftover 12ℏω\frac{1}{2}\hbar\omega is the zero-point energy, and chapter 6 shows it is forced by the uncertainty principle.
  • Switch to the barrier and raise it. The levels pair up into doublets. The splitting inside each pair is a direct measure of the tunnelling rate through the wall.
  • Count the nodes of any selected state. State nn crosses zero exactly nn times, in every potential. That is a theorem, not a coincidence.

Natural units, and how to get back

You will have noticed every number above is of order 1, with no 10βˆ’3410^{-34} in sight. That is deliberate: we set ℏ=m=1\hbar = m = 1 and measure lengths in a unit aa we choose. Doing arithmetic with 10βˆ’3410^{-34} and 10βˆ’3110^{-31} in floating point is a good way to lose precision for nothing.

The conversion back is one line. With ℏ=m=1\hbar = m = 1 and lengths in units of aa, one unit of energy is

Eunit=ℏ2ma2E_{\text{unit}} = \frac{\hbar^2}{m a^2}

Two things you get for free

The widget above reports β€œbound states: 3” the instant you move a slider, and it does so without computing a single eigenvalue. Both of the tricks behind that are worth knowing.

Counting without solving. For a symmetric tridiagonal matrix, one O(n)O(n) sweep β€” a Sturm sequence β€” counts how many eigenvalues lie below any energy you name. Since a bound state is precisely an eigenvalue below the potential at infinity, β€œhow many bound states does this well have?” is one cheap pass, no eigensolver required. It is also what makes the sliders feel instant: the site’s solver finds each level by bisecting on that count, which is O(n)O(n) per level instead of O(n3)O(n^3) for the whole matrix.

The node theorem. The nn-th eigenfunction of a one-dimensional problem crosses zero exactly nn times, always, in any potential. Count the wiggles and you know which level you are looking at. It is also a debugging tool: if your β€œground state” has a node in it, your solver has converged to the wrong thing.

Check yourself

0 / 7 answered

  1. 1.In the discretized Hamiltonian, where does the potential energy end up?

  2. 2.Why does leaving the two endpoints out of the grid impose at the walls?

  3. The stencil is accurate to .

    3.You compute with and get 4.9347; with you get 4.9348. What should you conclude?

  4. 4.A finite well has a bound state at in natural units. You solve it in a box running from to . What is the risk?

  5. 5.Why are the eigenvalues of this matrix guaranteed to be real?

  6. Try it above.

    6.In the explorer, switching from the infinite well to the harmonic oscillator changes the level spacing. How?

  7. 7.What does the Sturm-sequence count give you that an eigensolve does not?