Skip to content

Matrix Diagonalization

Matrix diagonalization turns a finite matrix representation of a Hamiltonian or observable into numerical eigenvalues and eigenvectors. The library call is usually one line. Trustworthy use requires more: choose a solver that respects Hermiticity, understand what degeneracy makes nonunique, validate the returned subspaces, and separate eigensolver error from errors already present in the matrix model.

This page treats dense standard and generalized Hermitian eigenproblems. The algebraic conditions for diagonalizability live in Diagonalization. Large problems for which only part of the spectrum is needed belong to Sparse Eigensolvers.

For a standard Hermitian eigenproblem,

Hvn=Envn,H†=H.Hv_n=E_nv_n, \qquad H^\dagger=H.

A complete solver returns an ordered vector of real eigenvalues and a unitary matrix of eigenvectors,

Λ=diag⁡(E0,…,EN−1),V=(v0 ⋯ vN−1),\Lambda = \operatorname{diag}(E_0,\ldots,E_{N-1}), \qquad V=(v_0\ \cdots\ v_{N-1}),

such that

HV=VΛ,V†V=I,H=VΛV†.HV=V\Lambda, \qquad V^\dagger V=I, \qquad H=V\Lambda V^\dagger.

Many numerical libraries store eigenvectors as columns of VV. Verify that convention rather than guessing from the array shape.

For a Hermitian matrix, the mathematical eigenvalues are real. Tiny imaginary parts in quantities reconstructed by floating-point arithmetic should be judged against a scale-aware tolerance, not deleted without diagnosis.

If H=H†H=H^\dagger, use a Hermitian eigensolver. It exploits the matrix structure and is designed to return:

  • real eigenvalues;
  • orthonormal eigenvectors;
  • better efficiency and storage use than a general nonsymmetric solver;
  • error behavior appropriate to a normal matrix.

General eigensolvers solve a harder problem and may return small spurious imaginary parts or less orthogonal vectors. Calling one on a Hermitian Hamiltonian discards valuable information.

Do not silently replace an imperfect input by

Hsym=12(H+H†)H_{\mathrm{sym}} = \frac12(H+H^\dagger)

unless that operation is part of the mathematical model. First measure

ηH=∥H−H†∥max⁡(∥H∥,ϵscale).\eta_{\mathrm H} = \frac{\lVert H-H^\dagger\rVert} {\max(\lVert H\rVert,\epsilon_{\mathrm{scale}})}.

A large ηH\eta_{\mathrm H} may expose an assembly error, a missing complex conjugate, an inconsistent boundary term, or a genuinely non-Hermitian model. Symmetrization can hide each of these.

Production routines do not usually find roots of the characteristic polynomial. For a dense Hermitian matrix they typically:

  1. reduce HH by unitary transformations to a real symmetric or complex Hermitian tridiagonal problem;
  2. solve the tridiagonal eigenproblem using a QR-family, divide-and-conquer, bisection/inverse-iteration, or relatively robust representation method;
  3. back-transform the eigenvectors when they are requested.

The exact path depends on the library and selected driver. For an N×NN\times N dense matrix, storing the matrix requires O(N2)O(N^2) memory and a complete eigendecomposition requires O(N3)O(N^3) arithmetic. Computing eigenvalues without eigenvectors can reduce constants and memory, but it does not change dense asymptotic scaling.

This scaling is the practical boundary of dense diagonalization. A tensor-product Hilbert space can make NN grow exponentially even when each local subsystem is small.

Mathematical taskAppropriate numerical family
All eigenpairs of dense Hermitian HHDense Hermitian eigensolver
Eigenvalues onlyHermitian eigenvalue-only routine
Selected interval of a dense Hermitian spectrumHermitian subset-capable driver
Hc=EScHc=ESc with positive-definite SSGeneralized Hermitian eigensolver
A few extremal eigenpairs of large sparse HHLanczos or another sparse Hermitian method
Singular values, rank, or least squaresSingular-value decomposition
Genuinely non-Hermitian operatorGeneral or structure-specific non-Hermitian solver

NumPy’s current eigh interface solves real symmetric or complex Hermitian problems, returns eigenvalues in ascending order, and places the associated normalized eigenvectors in columns. SciPy’s eigh additionally supports generalized Hermitian problems and selected eigenvalue subsets. Treat these as interface facts to verify in the installed library documentation, not as universal conventions shared by every language.

A reproducible dense calculation has four stages.

Assemble. Fix basis ordering, units, dtype, boundary conditions, and every normalization factor before diagonalization.

Inspect. Check shape, finiteness, Hermiticity, expected sparsity or block structure, and a few known matrix elements.

Solve. Use the structure-aware routine. Request only eigenvalues when vectors are unnecessary.

Validate and interpret. Scale residuals, test orthogonality and reconstruction, handle degenerate subspaces, and compare against analytic or convergence benchmarks.

The eigensolver only answers the finite matrix problem it receives. A tiny residual cannot prove that a basis truncation or spatial discretization represents the intended continuum operator.

Consider

H=(Δgg∗−Δ).H = \begin{pmatrix} \Delta & g\\ g^* & -\Delta \end{pmatrix}.

The characteristic equation gives

E±=±Δ2+∣g∣2.E_\pm = \mathord\pm\sqrt{\Delta^2+\lvert g\rvert^2}.

This model is a useful unit test because it exercises complex Hermitian input while retaining an exact answer. Choose Δ=0.6\Delta=0.6 and g=0.8ig=0.8i. Then E±=±1E_\pm=\mathord\pm1.

import numpy as np
H = np.array(
[[0.6, 0.8j],
[-0.8j, -0.6]],
dtype=np.complex128,
)
energies, vectors = np.linalg.eigh(H)
Lambda = np.diag(energies)
residual = H @ vectors - vectors @ Lambda
orthogonality = vectors.conj().T @ vectors - np.eye(2)
reconstruction = H - vectors @ Lambda @ vectors.conj().T
print(energies)
print(np.linalg.norm(residual, ord="fro"))
print(np.linalg.norm(orthogonality, ord="fro"))
print(np.linalg.norm(reconstruction, ord="fro"))

The expected eigenvalue array is (−1,1)(-1,1) up to rounding. The three norms should be small compared with the scale of HH. The individual eigenvector phases may differ across libraries or runs without changing any physical prediction.

For an approximate eigenpair (E~,v~)(\widetilde E,\widetilde v), the residual is

r=Hv~−E~v~.r = H\widetilde v-\widetilde E\widetilde v.

An absolute residual has units and changes if HH is rescaled. A dimensionless normwise backward-error indicator is

η=∥r∥2∥H∥2∥v~∥2+∣E~∣∥v~∥2.\eta = \frac{\lVert r\rVert_2} {\lVert H\rVert_2\lVert\widetilde v\rVert_2 +\lvert\widetilde E\rvert \lVert\widetilde v\rVert_2}.

Small η\eta means the returned pair is an exact eigenpair of a nearby matrix problem. It does not, by itself, guarantee a small forward error in the eigenvector. Forward sensitivity also depends on spectral gaps.

For a complete eigensystem, useful matrix-level diagnostics are

R=HV−VΛ,O=V†V−I,D=H−VΛV†.\begin{aligned} R&=HV-V\Lambda,\\ O&=V^\dagger V-I,\\ D&=H-V\Lambda V^\dagger. \end{aligned}

Report scaled norms such as

∥R∥F∥H∥F,∥O∥F,∥D∥F∥H∥F,\frac{\lVert R\rVert_{\mathrm F}} {\lVert H\rVert_{\mathrm F}}, \qquad \lVert O\rVert_{\mathrm F}, \qquad \frac{\lVert D\rVert_{\mathrm F}} {\lVert H\rVert_{\mathrm F}},

with a stated treatment for the exceptional case ∥H∥F=0\lVert H\rVert_{\mathrm F}=0.

For any nonzero trial vector vv, the Rayleigh quotient is

ρ(v)=v†Hvv†v.\rho(v) = \frac{v^\dagger Hv}{v^\dagger v}.

For normalized vv and Hermitian HH, the residual formed with ρ(v)\rho(v) obeys

∥(H−ρ)v∥22=⟨H2⟩v−⟨H⟩v2=(ΔvH)2.\begin{aligned} \lVert(H-\rho) v\rVert_2^2 &=\langle H^2\rangle_v-\langle H\rangle_v^2\\ &=(\Delta_v H)^2. \end{aligned}

Thus the energy variance is exactly the squared residual norm for a normalized trial state evaluated at its Rayleigh quotient. This links a standard numerical diagnostic to a physical statement: an exact energy eigenstate has zero energy variance.

A small variance confirms proximity to some spectral subspace. If several eigenvalues are clustered, it need not identify a unique eigenvector inside that subspace.

If an eigenvalue EE has multiplicity dd, every orthonormal basis of its eigenspace is valid. If VDV_D contains one numerical basis for that subspace and W∈U(d)W\in U(d), then

VD⟼VDWV_D \longmapsto V_DW

changes the returned vectors but not the eigenspace. Comparing individual vectors in an exactly or nearly degenerate cluster is therefore unreliable.

Compare the spectral projector instead:

PD=VDVD†.P_D=V_DV_D^\dagger.

Two computations agree on the subspace when their projectors agree. Principal angles provide a more detailed comparison: the singular values of VD†V~DV_D^\dagger \widetilde V_D are the cosines of the principal angles between the two subspaces.

If an additional Hermitian symmetry QQ commutes with HH, diagonalizing the restriction of QQ inside the degenerate eigenspace can select physically meaningful labels. This is a basis choice supplied by extra structure, not by HH alone.

Let an isolated eigenvalue or cluster be separated from the rest of the spectrum by a gap gg. A perturbation δH\delta H can rotate its invariant subspace by an amount controlled schematically by

sin⁡Θ≲∥δH∥g.\sin\Theta \lesssim \frac{\lVert\delta H\rVert}{g}.

When gg is small, eigenvectors can change substantially even though eigenvalues and the combined clustered subspace remain accurate. This is why a tiny residual and a visually different eigenvector are not contradictory near degeneracy.

Do not decide degeneracy from a fixed number of decimal places. Compare the observed splitting with relevant scales:

  • matrix norm and machine precision;
  • estimated assembly or discretization error;
  • symmetry expectations;
  • convergence under basis or grid refinement.

An isolated normalized eigenvector is defined only up to phase:

vn⟼eiϕnvn.v_n\longmapsto e^{i\phi_n}v_n.

Real symmetric solvers show the same freedom as an arbitrary sign. Component-by-component comparison can therefore fail even for identical physical states.

For a parameter-dependent Hamiltonian H(s)H(s), a simple phase alignment for an isolated state is

vn(s+δs)⟼e−iarg⁡⟨vn(s),vn(s+δs)⟩vn(s+δs).v_n(s+\delta s) \longmapsto e^{-i\arg\langle v_n(s),v_n(s+\delta s)\rangle} v_n(s+\delta s).

Near crossings, sorting by eigenvalue alone can swap state labels. Match states by overlaps, symmetry quantum numbers, or continuity of spectral projectors. For a degenerate block, align whole subspaces with a unitary Procrustes or singular-value-decomposition step rather than aligning columns independently.

This local gauge fixing aids plotting and differentiation. It does not remove global geometric effects such as Berry phase.

A nonorthogonal basis produces

Hc=ESc,Hc=ESc,

where the overlap matrix satisfies

S=S†>0.S=S^\dagger>0.

The eigenvectors are normalized in the SS metric:

cm†Scn=δmn.c_m^\dagger S c_n=\delta_{mn}.

If S=LL†S=LL^\dagger is a Cholesky factorization, define y=L†cy=L^\dagger c. Then

(L−1HL−†)y=Ey,c=L−†y.\left(L^{-1}HL^{-\dagger}\right)y=Ey, \qquad c=L^{-\dagger}y.

In software, use a generalized Hermitian driver or triangular solves; do not explicitly form matrix inverses. If SS is not positive definite or is extremely ill-conditioned, the basis may contain exact or near linear dependencies. That is a modeling and conditioning problem, not merely an eigensolver inconvenience.

Validation must use the generalized residual and metric:

R=HC−SCΛ,C†SC≈I.R=HC-SC\Lambda, \qquad C^\dagger SC\approx I.

If a Hermitian operator QQ commutes with HH,

[H,Q]=0,[H,Q]=0,

the Hilbert space can often be decomposed into invariant sectors before solving. Block diagonalization:

  • reduces time and memory;
  • prevents mixing between distinct symmetry labels;
  • makes degeneracies easier to interpret;
  • supplies more stable state labels across parameter sweeps.

Numerically check the commutator relative to matrix scales. A purported symmetry that fails this test may have been broken by boundary conditions, truncation, or an assembly error.

Never sort eigenvalues without applying the same permutation to eigenvector columns. If pp is the sorting permutation,

En⟼Ep(n),vn⟼vp(n).E_n\longmapsto E_{p(n)}, \qquad v_n\longmapsto v_{p(n)}.

Ascending energy is often useful, but it is not always the best label. Near exact crossings, states can be tracked by symmetry sectors. Near avoided crossings, overlap continuation may better preserve identity. When a reported state is defined by an observable AA, record

⟨A⟩n=vn†Avn\langle A\rangle_n=v_n^\dagger A v_n

alongside its energy rather than relying on array position alone.

Four distinct error sources should be separated:

SourceTypical diagnostic
Matrix assemblyHermiticity, units, known entries, symmetry commutators
Basis truncation or discretizationConvergence under basis size, grid spacing, or domain size
Floating-point conditioningScale changes, precision changes, gap estimates
EigensolverResidual, orthogonality, reconstruction

A backward-stable eigensolver can solve the wrong discretized Hamiltonian extremely accurately. Conversely, physically converged low-energy observables may remain useful even when high-energy grid states are poor.

On an interior uniform grid with spacing Δx\Delta x and Dirichlet endpoints, the centered finite-difference oscillator Hamiltonian has

Hjj=ℏ2m(Δx)2+12mω2xj2,Hj,j±1=−ℏ22m(Δx)2.\begin{aligned} H_{jj} &=\frac{\hbar^2}{m(\Delta x)^2} +\frac12m\omega^2x_j^2,\\ H_{j,j\mathord\pm1} &=-\frac{\hbar^2}{2m(\Delta x)^2}. \end{aligned}

Its low eigenvalues should approach

En=ℏω(n+12).E_n=\hbar\omega\left(n+\frac12\right).

A credible convergence study varies both the grid spacing and the finite domain size. Decreasing Δx\Delta x at fixed box size reduces discretization error but not boundary truncation error. Increasing the box at fixed number of points can make the grid coarser. Coordinate the two limits and monitor several low-lying levels.

The construction belongs to Finite Difference Methods. Imaginary-Time Projection Notebook uses the resulting eigensystem as an independent benchmark for an iterative ground-state calculation.

Record enough information to rerun and audit the calculation:

  • basis and basis ordering;
  • physical units and nondimensionalization;
  • matrix dimension and dtype;
  • symmetry sectors and truncation rules;
  • library and backend versions;
  • routine and nondefault solver options;
  • whether eigenvectors were requested;
  • residual, orthogonality, and reconstruction tolerances;
  • convergence data for the physical discretization;
  • the rule used to sort, phase-align, or track states.

Bitwise-identical eigenvectors are not a reasonable portability requirement, especially in degenerate spaces. Reproducible eigenvalues, residuals, projectors, and observables are stronger scientific targets.

  • Using a general eigensolver for a Hermitian matrix.
  • Trusting the input triangle without checking how the library interprets it.
  • Silently symmetrizing a matrix before diagnosing the anti-Hermitian part.
  • Comparing degenerate eigenvectors column by column instead of comparing subspaces.
  • Forgetting that eigenvectors are arbitrary up to phase or sign.
  • Sorting eigenvalues without permuting the corresponding eigenvectors.
  • Treating a small residual as proof of continuum or basis convergence.
  • Using a fixed absolute tolerance across differently scaled Hamiltonians.
  • Forming A†AA^\dagger A to replace an SVD and thereby squaring the condition number.
  • Forming explicit inverses in a generalized eigenproblem.
  • Applying dense diagonalization when only a few eigenpairs of a large sparse matrix are needed.

This page owns the workflow for dense Hermitian matrix eigenproblems. It does not duplicate the mathematical spectral theorem, the construction of a particular Hamiltonian, or large-scale iterative methods. See Spectral Decomposition for the algebra, Discretization for continuum-to-matrix modeling, and Sparse Eigensolvers for selected eigenpairs at scale.

  • G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins University Press, 2013.
  • L. N. Trefethen and D. Bau III, Numerical Linear Algebra, SIAM, 1997.
  • G. W. Stewart and J.-G. Sun, Matrix Perturbation Theory, Academic Press, 1990.
  • E. Anderson et al., LAPACK Users’ Guide, 3rd ed., SIAM, 1999.
  • J. M. Thijssen, Computational Physics, 2nd ed., Cambridge University Press, 2007.
  • NumPy documentation: numpy.linalg.eigh.
  • SciPy documentation: scipy.linalg.eigh.
  1. Derive the eigenvalues of the two-level benchmark and check them using trace and determinant.
Solution

The characteristic determinant is

det⁡(H−EI)=(Δ−E)(−Δ−E)−∣g∣2=E2−Δ2−∣g∣2.\begin{aligned} \det(H-EI) &=(\Delta-E)(-\Delta-E)-\lvert g\rvert^2\\ &=E^2-\Delta^2-\lvert g\rvert^2. \end{aligned}

Therefore

E±=±Δ2+∣g∣2.E_\pm=\mathord\pm\sqrt{\Delta^2+\lvert g\rvert^2}.

Their sum is zero, matching Tr⁡H=0\operatorname{Tr}H=0, and their product is

E+E−=−Δ2−∣g∣2=det⁡H.E_+E_- =-\Delta^2-\lvert g\rvert^2 =\det H.
  1. Prove that energy variance equals squared residual norm at the Rayleigh quotient.
Solution

Let vv be normalized and set ρ=v†Hv\rho=v^\dagger Hv. Since HH is Hermitian, ρ\rho is real. Then

∥(H−ρ)v∥22=v†(H−ρ)2v=v†H2v−2ρ v†Hv+ρ2=⟨H2⟩v−ρ2=(ΔvH)2.\begin{aligned} \lVert(H-\rho)v\rVert_2^2 &=v^\dagger(H-\rho)^2v\\ &=v^\dagger H^2v -2\rho\,v^\dagger Hv+\rho^2\\ &=\langle H^2\rangle_v-\rho^2\\ &=(\Delta_vH)^2. \end{aligned}
  1. Show why individual vectors are not invariant inside a degenerate eigenspace.
Solution

Let HVD=EVDHV_D=EV_D for a dd-column orthonormal basis VDV_D, and let W∈U(d)W\in U(d). Then

H(VDW)=(HVD)W=E(VDW).H(V_DW) =(HV_D)W =E(V_DW).

Also,

(VDW)†(VDW)=W†W=Id.(V_DW)^\dagger(V_DW) =W^\dagger W=I_d.

Thus VDWV_DW is another valid orthonormal eigenbasis. Its projector is unchanged:

(VDW)(VDW)†=VDWW†VD†=VDVD†.(V_DW)(V_DW)^\dagger =V_DWW^\dagger V_D^\dagger =V_DV_D^\dagger.
  1. Reduce a generalized Hermitian eigenproblem to a standard one.
Solution

For S>0S>0, take S=LL†S=LL^\dagger and define y=L†cy=L^\dagger c, so c=L−†yc=L^{-\dagger}y. Substituting into Hc=EScHc=ESc gives

HL−†y=ELL†L−†y=ELy.HL^{-\dagger}y =ELL^\dagger L^{-\dagger}y =ELy.

Multiplying by L−1L^{-1} yields

(L−1HL−†)y=Ey.\left(L^{-1}HL^{-\dagger}\right)y=Ey.

The transformed matrix is Hermitian. If the yy vectors are orthonormal, then

cm†Scn=ym†yn=δmn.c_m^\dagger Sc_n =y_m^\dagger y_n =\delta_{mn}.
  1. Design a convergence test for the finite-difference harmonic oscillator.
Solution

Choose several box half-widths LL and several grid spacings Δx\Delta x. For each pair, build the Hermitian tridiagonal matrix, compute a fixed number of low eigenvalues, and record:

∣Ennum−Enexact∣Enexact,∥Hvn−Envn∥2∥H∥2.\frac{\lvert E_n^{\mathrm{num}}-E_n^{\mathrm{exact}}\rvert} {E_n^{\mathrm{exact}}}, \qquad \frac{\lVert Hv_n-E_nv_n\rVert_2} {\lVert H\rVert_2}.

At fixed sufficiently large LL, refine Δx\Delta x to expose discretization convergence. At fixed sufficiently small Δx\Delta x, enlarge LL to expose boundary truncation. A level is credible only when both studies stabilize it and the eigensolver residual remains much smaller than the physical discretization error.