Tip: This calculator performs a Modified Gram-Schmidt QR decomposition. Works best when rows ≥ columns.
How to use this QR factorization calculator
Enter your matrix in the input box, one row per line. You can separate entries by spaces or commas. Click Calculate QR Factorization and the tool returns:
- Q: a matrix with orthonormal columns (when columns are linearly independent).
- R: an upper triangular matrix.
- Q · R: reconstructed matrix to verify correctness.
- Error diagnostics for reconstruction and orthogonality quality.
What is QR factorization?
QR factorization (also called QR decomposition) rewrites a matrix A as:
A = Q R
where Q has orthonormal columns and R is upper triangular. This decomposition is a workhorse in numerical linear algebra because it is stable and useful for solving least-squares problems, computing eigenvalues, and building robust optimization pipelines.
Economic QR vs full QR
For an m × n matrix with m ≥ n, the reduced (economic) QR is common:
- Q is m × n
- R is n × n
This calculator returns that reduced form, which is what most regression and least-squares workflows need.
Why QR decomposition matters
- Linear regression: Solve least-squares systems without forming unstable normal equations.
- Signal processing: Orthogonalization appears in filtering, coding, and MIMO systems.
- Machine learning: Used in orthogonal projections, dimensional methods, and iterative solvers.
- Scientific computing: Basis construction and numerical stability in large matrix pipelines.
Algorithm used in this tool
Modified Gram-Schmidt (MGS)
This page uses Modified Gram-Schmidt to compute QR. Compared with classical Gram-Schmidt, MGS is generally more numerically stable for finite-precision arithmetic. In simple terms, it orthogonalizes each new column against the already-computed orthonormal basis vectors, then normalizes.
If your matrix is rank-deficient (columns are linearly dependent), some diagonal entries of R become zero (or nearly zero), and corresponding columns of Q cannot be normalized in the usual way. The calculator reports this condition.
How to interpret the results
- Small reconstruction error means Q·R is close to your input matrix.
- Small orthogonality error means QᵀQ is close to identity.
- Near-zero diagonal values in R suggest dependent or nearly dependent columns.
Practical tips
- Use reasonable scaling of data when possible; extreme magnitudes can magnify floating-point effects.
- For tall matrices (many rows, fewer columns), reduced QR is usually the right output form.
- If you suspect ill-conditioning, compare results at different decimal precision settings.
FAQ
Can I use this for non-square matrices?
Yes. QR decomposition is especially useful for rectangular matrices, particularly when rows are greater than columns.
Does this calculator solve linear systems?
Indirectly, yes: once QR is available, least-squares and triangular solves can be performed. This tool focuses on decomposition and diagnostics, not full system solving.
What if I paste commas instead of spaces?
That is supported. You may use either commas or spaces between entries.