Factor any matrix into an orthogonal matrix Q and an upper triangular matrix R using the Gram-Schmidt process. Get detailed step-by-step solutions instantly.
Enter a matrix and click Decompose
or press Enter
QR decomposition (also known as QR factorization) expresses a matrix A as the product of two matrices: an orthogonal (or unitary) matrix Q and an upper triangular matrix R. Every real m×n matrix with linearly independent columns admits such a factorization.
Here Q is an m×m orthogonal matrix (QTQ = I), meaning its columns form an orthonormal basis, and R is an m×n upper triangular matrix whose diagonal entries are non-negative when the decomposition is made unique (the so-called reduced or thin QR).
QR decomposition is one of the most numerically stable factorization methods and sits at the heart of many algorithms in scientific computing, statistics, and machine learning.
The matrix Q produced by QR decomposition has several powerful properties that make it invaluable in numerical computations:
The classical Gram-Schmidt algorithm is the most intuitive way to compute the QR decomposition. It works by orthogonalizing the columns of A one at a time:
The modified Gram-Schmidt variant improves numerical stability by re-orthogonalizing against the already-updated vectors rather than the original columns. In exact arithmetic both produce the same result, but modified Gram-Schmidt is preferred in floating-point computation.
For large or ill-conditioned matrices, the Householder method is the standard production algorithm. Instead of building Q column by column, it applies a sequence of orthogonal reflections that zero out sub-diagonal entries:
dgeqrf), NumPy (numpy.linalg.qr), and MATLAB (qr).A third approach uses Givens rotations — 2×2 orthogonal rotations embedded in the larger matrix — to selectively zero out individual entries below the diagonal. Givens rotations are particularly useful for:
The cost of computing a QR decomposition of an m×n matrix (m ≥ n) depends on the algorithm:
2mn² floating-point operations (flops).2mn² − (2/3)n³ flops, with excellent cache behavior.3mn² − n³ flops, higher constant but advantageous in special cases.For a square n×n matrix, all methods scale as O(n³). The Householder method is generally fastest in practice due to BLAS-3 (blocked) implementations in libraries like LAPACK.
QR decomposition is one of the most widely used matrix factorizations in applied mathematics and engineering:
Choosing the right decomposition depends on the problem structure:
Every real m×n matrix A with m ≥ n has a QR decomposition A = QR. If A has full column rank (rank n), then the thin QR decomposition (where Q is m×n with orthonormal columns and R is n×n upper triangular) is unique provided we require the diagonal entries of R to be positive.
When A is rank-deficient, the decomposition still exists but is not unique — some diagonal entries of R will be zero, and the corresponding columns of Q can be chosen arbitrarily from the orthogonal complement.
Column-pivoted QR decomposition computes AP = QR, where P is a permutation matrix that reorders the columns of A so that the diagonal entries of R are non-increasing in absolute value: |r11| ≥ |r22| ≥ … This provides a rank-revealing factorization and can be used as a cheaper alternative to SVD for estimating numerical rank.
Explore other matrix decomposition methods with dedicated calculators and step-by-step explanations.
Factor a matrix into Lower and Upper triangular matrices. Essential for solving systems of linear equations efficiently.
Open calculator →The most general matrix decomposition. Factorize any matrix into U, Σ, Vᵀ. Powers recommendation systems and data compression.
Open calculator →Efficient factorization for symmetric positive definite matrices into LLᵀ. Widely used in Monte Carlo simulations and optimization.
Open calculator →Find eigenvalues and eigenvectors. Fundamental to PCA, quantum mechanics, vibration analysis, and stability theory.
Open calculator →Every calculation shows the full Gram-Schmidt derivation, not just the answer. Learn the algorithm as you go.
All computations run in your browser. No server round-trips, no waiting, no sign-up.
Every QR decomposition is verified by checking that Q is orthogonal and QR reconstructs the original matrix.
Responsive design works on phones, tablets, and desktops. Factor matrices on the go.