Decompose a matrix into an orthogonal Q and upper-triangular R via Gram-Schmidt.
QR decomposition expresses a matrix A as Q·R where Q has orthonormal columns and R is upper triangular. This implementation uses the modified Gram-Schmidt process. The matrix must have at least as many rows as columns (m ≥ n), and its columns must be linearly independent.
QR Factorisation
A = Q·R, where QᵀQ = I
Gram-Schmidt
qⱼ = (aⱼ − Σᵢ₌₁ʲ⁻¹ ⟨qᵢ,aⱼ⟩qᵢ) / ||...||
It is used for solving least-squares problems, computing eigenvalues (QR algorithm), and as a numerically stable alternative to Gaussian elimination for overdetermined systems.
Yes, as long as the matrix has more rows than columns (m ≥ n) and the columns are linearly independent.