QR Decomposition Calculator

Enter your matrix values into the QR Decomposition Calculator and factorize any matrix A into an orthogonal matrix Q and an upper triangular matrix R such that A = QR. Set the matrix size (up to 4×4), fill in the matrix entries, and get back the complete Q matrix and R matrix computed via the Gram-Schmidt orthogonalization process.

Select the number of rows and columns. Columns must be linearly independent.

Results

Decomposition Status

--

Orthogonal Matrix Q

--

Upper Triangular Matrix R

--

Verification ||A - QR|| (should be ≈ 0)

--

Column Norms of Q (should all equal 1)

Results Table

Frequently Asked Questions

What is QR decomposition?

QR decomposition (also called QR factorization) breaks a matrix A into the product of two matrices: Q (an orthogonal matrix whose columns are orthonormal) and R (an upper triangular matrix), so that A = QR. It is widely used in numerical linear algebra for solving linear systems, computing eigenvalues, and performing least-squares fitting.

What algorithm does this calculator use?

This calculator uses the classical Gram-Schmidt orthogonalization process to compute the Q and R matrices. Starting from the columns of A, it iteratively orthogonalizes and normalizes each vector to build Q, then recovers R as R = Qᵀ·A. Note that classical Gram-Schmidt can lose numerical precision for nearly dependent columns; modified Gram-Schmidt or Householder reflections are more stable for production use.

What is required for QR decomposition to exist?

The columns of the input matrix must be linearly independent. If two or more columns are linearly dependent (or nearly so), the Gram-Schmidt process will encounter a zero-norm vector, making it impossible to normalize. The calculator will alert you if this condition is detected.

What are the properties of the Q matrix?

Q is an orthogonal matrix, meaning its columns are mutually orthogonal unit vectors. As a result, Qᵀ·Q = I (the identity matrix), and the inverse of Q equals its transpose. This makes Q very useful in numerical computations because it preserves vector norms.

What does the R matrix look like?

R is an upper triangular matrix — all entries below the main diagonal are zero. The diagonal entries of R equal the norms of the intermediate (un-normalized) orthogonalized vectors from the Gram-Schmidt process. If A has full column rank, all diagonal entries of R are nonzero.

How can I verify the result is correct?

Multiply Q by R and confirm you recover the original matrix A. The calculator provides a verification norm ||A − QR||, which should be extremely close to zero (within floating-point precision, typically less than 1e-10). The column norms of Q should all equal 1, and Q·Qᵀ should approximate the identity matrix.

What is QR decomposition used for in practice?

QR decomposition is used for solving least-squares problems, computing the eigenvalues of a matrix via the QR algorithm, solving linear systems more stably than LU decomposition in some cases, and performing principal component analysis (PCA). It is a foundational tool in scientific computing, statistics, and machine learning.

What is the difference between QR and LU decomposition?

LU decomposition factors A into a lower triangular matrix L and upper triangular matrix U, and is primarily used for solving square linear systems. QR decomposition factors A into an orthogonal matrix Q and upper triangular matrix R, which is more numerically stable and applies to rectangular matrices. QR is preferred when solving least-squares problems or when orthogonality properties are needed.

More Math Tools