Companion Website

Computational Physics

From Equations to Simulation

Chapter 8

Linear Systems and Eigenvalue Problems

The first four programs solve linear systems by Gaussian elimination, successive over-relaxation, and the Thomas algorithm, or compute a small matrix inverse by repeated solves. The remaining programs find one dominant eigenvalue, one eigenvalue near a chosen shift, or all eigenvalues of a real symmetric matrix, together with their eigenvectors. Each program is available in MATLAB, Python, C++, and Fortran. Start with the matrix structure and the quantity the physics problem requires: a solution, a selected eigenmode, or the full spectrum. These seven programs are a focused selection from the chapter. The matrices in other printed examples can also be studied with the library routines listed on the resources page, although their iteration histories may differ.

The linear-system programs report a residual or an inverse check against the original matrix. A small residual does not by itself guarantee an accurate solution when the matrix is ill-conditioned. The eigenvalue programs check Av − λv; Jacobi also checks eigenvector orthogonality. The Thomas and matrix inverse examples do not pivot, so their chosen matrices are important. The Chapter 8 resources give further guidance on choosing a solver and checking results. Several default matrices, including those for SOR, inversion, and eigenvalues, differ from the book’s printed examples. Compare each program with its own documented input and reference result.

Program MATLAB Python C++ Fortran
Gaussian elimination Solves a general small linear system by elimination with scaled row pivoting and back substitution. Download Download Download Download
Successive over-relaxation (SOR) Iteratively solves a strictly diagonally dominant system with a selectable relaxation parameter and a residual stopping test. Download Download Download Download
Thomas algorithm Solves a tridiagonal system by forward elimination and back substitution without pivoting. Download Download Download Download
Matrix inverse Computes the inverse of a small matrix by reusing a no-pivot LU factorization for several right-hand sides. Download Download Download Download
Power method Finds the eigenvalue of largest magnitude and a corresponding eigenvector. Download Download Download Download
Shifted inverse iteration Finds an eigenvalue near a chosen shift and a corresponding eigenvector by repeatedly solving with a pivoted LU factorization. Download Download Download Download
Jacobi eigenvalue method Uses plane rotations to find all eigenvalues and orthonormal eigenvectors of a real symmetric matrix. Download Download Download Download

← Back to Chapter 8