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.

Cholesky decomposition for SPD systems

Cholesky decomposition for SPD systems

Classical matrix theory#

Cramer’s rule and the Cayley-Hamilton theorem: the determinant-era results that predate numerical linear algebra.

Cramer’s rule vs. elimination

Cramer's rule vs. elimination

The Cayley-Hamilton theorem

The Cayley-Hamilton theorem

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

Cauchy's spectral theorem: principal axes of a quadratic form

Von Mises power iteration and Wielandt inverse iteration

Von Mises power iteration and Wielandt inverse iteration

Gershgorin discs

Gershgorin discs

Lanczos: a few eigenvalues of a very large matrix

Lanczos: a few eigenvalues of a very large matrix

The QR algorithm and the Schur form

The QR algorithm and the Schur form

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).

Conjugate gradient and GMRES convergence

Conjugate gradient and GMRES convergence

Jacobi, Gauss-Seidel, and successive over-relaxation

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

Elimination in the Nine Chapters: the three grades of grain

LU decomposition with partial pivoting

LU decomposition with partial pivoting

QR decomposition#

Householder reflections vs. classical/modified Gram-Schmidt, and the orthogonality each preserves for an ill-conditioned matrix.

Householder vs. Gram-Schmidt QR

Householder vs. Gram-Schmidt QR

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

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

Eckart-Young: the best low-rank approximation from the SVD

The Moore-Penrose pseudoinverse

The Moore-Penrose pseudoinverse

Gallery generated by Sphinx-Gallery