Free Online Tool

QR Decomposition Calculator

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

What is QR Decomposition?

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.

A = Q R

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.

Properties of Orthogonal Matrices

The matrix Q produced by QR decomposition has several powerful properties that make it invaluable in numerical computations:

The Gram-Schmidt Process

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:

  1. Start with the first column — Set u1 = a1, then normalize: e1 = u1 / ‖u1‖.
  2. Subtract projections — For each subsequent column ak, remove the components along all previously computed orthonormal vectors: uk = ak − ∑j=1k-1 (ejT ak) ej.
  3. Normalize — Compute ek = uk / ‖uk‖.
  4. Build Q and R — The orthonormal vectors e1, e2, … form the columns of Q. The entries of R are the projection coefficients: rjk = ejT ak for j ≤ k, and rjk = 0 for j > k.

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.

Householder Reflections

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:

Givens Rotations

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:

Computational Complexity

The cost of computing a QR decomposition of an m×n matrix (m ≥ n) depends on the algorithm:

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.

Applications of QR Decomposition

QR decomposition is one of the most widely used matrix factorizations in applied mathematics and engineering:

QR vs. Other Decompositions

Choosing the right decomposition depends on the problem structure:

Existence and Uniqueness

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.

QR with Column Pivoting

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.

Other Decomposition Types

Explore other matrix decomposition methods with dedicated calculators and step-by-step explanations.

LU

LU Decomposition

Factor a matrix into Lower and Upper triangular matrices. Essential for solving systems of linear equations efficiently.

Open calculator →
SVD

Singular Value Decomposition

The most general matrix decomposition. Factorize any matrix into U, Σ, Vᵀ. Powers recommendation systems and data compression.

Open calculator →
LL

Cholesky Decomposition

Efficient factorization for symmetric positive definite matrices into LLᵀ. Widely used in Monte Carlo simulations and optimization.

Open calculator →
λ

Eigendecomposition

Find eigenvalues and eigenvectors. Fundamental to PCA, quantum mechanics, vibration analysis, and stability theory.

Open calculator →

Why Decomposition.ai?

📐

Step-by-Step Solutions

Every calculation shows the full Gram-Schmidt derivation, not just the answer. Learn the algorithm as you go.

Instant Results

All computations run in your browser. No server round-trips, no waiting, no sign-up.

Verified Results

Every QR decomposition is verified by checking that Q is orthogonal and QR reconstructs the original matrix.

📱

Works Everywhere

Responsive design works on phones, tablets, and desktops. Factor matrices on the go.