Examples#
This gallery walks through every public feature of mathematicskit.linalg:
LU/QR/Cholesky decompositions, symmetric eigenvalue algorithms, SVD,
iterative Krylov solvers, and least-squares stability.
See also the narrative tutorial:
Each script in this gallery is self-contained and can be run directly with
python examples/linalg/<section>/<script>.py.
Sections#
classical – Cramer’s rule and the Cayley-Hamilton theorem.
lu – elimination in the Nine Chapters, LU decomposition with partial pivoting, and solving/computing determinants from it.
qr – Householder vs. Gram-Schmidt QR, and why Householder stays orthogonal for ill-conditioned matrices.
cholesky – Cholesky decomposition for SPD matrices.
eigen – Cauchy’s spectral theorem via numpy.linalg.eigh/eig, power iteration, inverse iteration, Gershgorin discs, Lanczos, and the QR algorithm / Schur form.
svd – the SVD and Eckart-Young low-rank approximation, and the Moore-Penrose pseudoinverse.
iterative – conjugate gradient and GMRES convergence; Jacobi, Gauss-Seidel, and SOR.
stability – the condition number, and why least squares via the normal equations squares it while QR does not.
Cholesky decomposition#
Cholesky decomposition for symmetric positive-definite matrices, and solving linear systems from it.
Classical matrix theory#
Cramer’s rule and the Cayley-Hamilton theorem: the determinant-era results that predate numerical linear algebra.
Eigenvalue algorithms#
Cauchy’s spectral theorem for symmetric matrices, and hand-rolled power iteration and inverse iteration – two routes to a single eigenpair when the full spectrum isn’t needed.
Also: Gershgorin discs, Lanczos iteration for a few eigenpairs of a large sparse matrix, and the QR algorithm converging to the Schur form.
Cauchy’s spectral theorem: principal axes of a quadratic form
Von Mises power iteration and Wielandt inverse iteration
Iterative solvers#
Conjugate gradient (SPD systems) and GMRES (general systems): Krylov subspace methods that never form a dense factorization.
Also the classical stationary iterations: Jacobi, Gauss-Seidel, and successive over-relaxation (SOR).
Jacobi, Gauss-Seidel, and successive over-relaxation
LU decomposition#
Elimination as the Nine Chapters did it, and Gauss’s elimination recorded as a partial-pivoted LU decomposition for solving systems and computing determinants from a single factorization.
Elimination in the Nine Chapters: the three grades of grain
QR decomposition#
Householder reflections vs. classical/modified Gram-Schmidt, and the orthogonality each preserves for an ill-conditioned matrix.
Numerical stability#
The condition number: how much a linear system amplifies errors in its data, and why least squares via the normal equations squares it while QR does not.
Turing’s condition number: how much a linear system amplifies error
Singular value decomposition#
SVD via numpy.linalg.svd() and the Eckart-Young best low-rank approximation.
Also the Moore-Penrose pseudoinverse and minimum-norm least squares.
Eckart-Young: the best low-rank approximation from the SVD