Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 39 · The Variational Method

The Rayleigh-Ritz Method and Linear Variational Functions

Turn the variational principle into a matrix eigenvalue problem with a basis set, bound several energy levels, and try it on a box and on hydrogen.

A one-parameter trial function is a start, but real calculations use many parameters. The most useful family is the linear one: write the trial state as a sum of fixed basis functions with adjustable coefficients. Minimizing the energy then becomes a matrix problem that a computer solves in milliseconds. This is the Rayleigh-Ritz method, and it is the engine inside nearly every quantum-chemistry program.

Linear trial functions

Choose basis functions φ₁, φ₂, …, φ_N (not necessarily orthogonal) and write

Text
|ψ⟩ = Σ_k c_k |φ_k⟩

Define two N × N matrices:

Text
H_ij = ⟨φ_i|H|φ_j⟩        S_ij = ⟨φ_i|φ_j⟩

S is the overlap matrix. The energy functional becomes E(c) = c†Hc / c†Sc. Requiring it to be stationary with respect to every c_i gives the generalized eigenvalue problem

Text
H c = E S c

If the basis is orthonormal, S is the identity and this is an ordinary eigenvalue problem. In general you solve it with scipy.linalg.eigh(H, S).

What the eigenvalues mean

  • The smallest eigenvalue E₁⁽ᴺ⁾ is the best energy the span of the basis can give, and E₁⁽ᴺ⁾ ≥ E₀.
  • Adding a function to the basis can only lower it (or leave it unchanged), so the energy decreases monotonically as the basis grows.
  • The second eigenvalue is an upper bound on the first excited energy, the third on the second excited, and so on. This is the Hylleraas-Undheim-MacDonald theorem: the k-th Ritz value satisfies E_k⁽ᴺ⁾ ≥ E_k. All levels converge from above as the basis improves.

Example: a particle in a box with polynomials

Take a particle in an infinite well from x = 0 to x = 1 in units with ħ²/2m = 1, so H = -d²/dx² and the exact levels are E_n = n²π²: 9.8696, 39.478, 88.826, ….

Trial functions must vanish at the walls. Use φ_k = x^{k+1}(1 - x) for k = 0, 1, …. With a single function, φ₀ = x(1 - x), you get E = 10, only 1.3% above π² = 9.8696. After integrating by parts (boundary terms vanish) the matrix elements are H_ij = ∫ φ_i' φ_j' dx and S_ij = ∫ φ_i φ_j dx.

Python Polynomial Rayleigh-Ritz in a 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.

You should see the first value drop toward 9.8696 and the later values appear and settle toward 39.478, 88.826. Each Ritz level approaches its exact partner from above. The second level is within 0.1% of 39.478 already at N = 4.

Example: hydrogen with Gaussians

In atomic units the hydrogen atom has E_n = -1/(2n²): -0.5, -0.125, -0.0556, … hartree. The true 1s orbital is e^{-r}, which has a cusp at the nucleus that Gaussians e^{-a r²} cannot reproduce: they are flat at r = 0. So Gaussians are a hard test, and exactly how real chemistry software works (it uses Gaussians because their integrals are cheap).

For s-type primitives g_a(r) = e^{-a r²} the needed integrals in closed form are:

Text
S_ab = (π/(a + b))^{3/2}
T_ab = 3 a b π^{3/2} / (a + b)^{5/2}        (kinetic, -½∇²)
V_ab = -2π/(a + b)                          (attraction -1/r)

One Gaussian with the best exponent gives E = -4/(3π) = -0.4244 E_h, which is 15% too high. Using several exponents arranged in a geometric progression (an even-tempered basis) the energy converges quickly. Because only s functions are used, the eigenvalues approximate the hydrogen s levels 1s, 2s, 3s.

Python Gaussian basis sets for hydrogen s 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.

Three observations to look for in the output:

  1. The ground state energy decreases as N grows and never drops below -0.5.
  2. With N = 1 only one eigenvalue exists; with larger N extra eigenvalues appear and bound the excited levels from above.
  3. The higher states converge more slowly: they need diffuse (small-exponent) functions, and the 3s state is poorly described by a small basis.

Practical issues

  • Near linear dependence. If basis functions are too similar, S is nearly singular and the eigenproblem loses accuracy. scipy.linalg.eigh raises an error if S is not positive definite.
  • Completeness. The Ritz values only approach exact levels if the basis can approximate the true states. Gaussians struggle with the nuclear cusp; the fix is to include very tight functions.
  • Cost. Building and diagonalizing N × N matrices costs about N³ operations, which is why basis-set choice matters for large molecules.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In H c = E S c, what does the matrix S represent?

    S_ij = ⟨φ_i|φ_j⟩ measures how much the (possibly non-orthogonal) basis functions overlap. For an orthonormal basis it is the identity.
  2. 2. You enlarge a basis by adding one function. What happens to the lowest Ritz eigenvalue?

    The old trial space is contained in the new one, so the minimum over the larger space cannot be higher.
  3. 3. The second Ritz eigenvalue of a basis set is:

    By the Hylleraas-Undheim-MacDonald theorem each Ritz value E_k^(N) is at or above the exact E_k.
  4. 4. Why are Gaussians a hard test for hydrogen's 1s state?

    e^{-r} has a nonzero slope at r = 0 (a cusp), while e^{-a r²} has zero slope. Many Gaussians with different exponents are needed to imitate the cusp.

Summary

  • A linear trial function Σ c_k φ_k turns minimization into H c = E S c.
  • scipy.linalg.eigh(H, S) solves it; the eigenvalues are Ritz values.
  • Adding basis functions lowers (or keeps) each Ritz value, and each E_k^(N) bounds the exact E_k from above.
  • Polynomials work well in a box; Gaussians work for atoms despite the cusp problem.
  • Watch for near linear dependence in S.

Next: LCAO and the Hydrogen Molecule Ion