1 2 3What is QR decomposition?
QR decomposition factors a matrix A into two pieces:
- Q: a matrix with orthonormal columns (columns are perpendicular and have unit length),
- R: an upper triangular matrix.
In compact form, this is written as A = Q R. It is one of the most important matrix factorizations in numerical linear algebra.
How this QR decomposition calculator works
This tool uses the Modified Gram-Schmidt process to compute a thin QR decomposition for matrices where rows are greater than or equal to columns (m ≥ n). The algorithm orthogonalizes each column step-by-step and builds:
- Q from normalized orthogonal vectors,
- R from projection coefficients.
The calculator also reports:
- estimated matrix rank,
- orthogonality error (
||QᵀQ − I||F), - reconstruction error (
||A − QR||F).
Input format and quick tips
Accepted matrix format
- Rows separated by new lines or semicolons.
- Entries separated by spaces or commas.
- All rows must have the same number of columns.
Examples:
1 2; 3 4; 5 61,2,3 4,5,6 7,8,9
Why QR decomposition is useful
1) Solving least squares problems
When a system is overdetermined (more equations than unknowns), QR decomposition is the standard stable method to compute best-fit solutions.
2) Linear regression and data fitting
Many regression methods rely on least squares under the hood. QR avoids directly forming normal equations, which can amplify numerical errors.
3) Eigenvalue algorithms
The QR algorithm is a cornerstone of practical eigenvalue computation in scientific software.
4) Numerical stability in scientific computing
Compared to naive elimination approaches for certain tasks, orthogonal transformations are often more robust in floating-point arithmetic.
Interpreting the results
If your matrix has independent columns, diagonal entries of R should be nonzero (up to rounding). If a diagonal entry is very close to zero, the columns may be linearly dependent and the estimated rank drops.
In exact arithmetic, Q is perfectly orthogonal and A equals QR exactly. In real computation, you should expect tiny errors due to rounding—typically around machine precision for well-conditioned problems.
Practical notes
- This calculator is educational and ideal for small-to-medium matrices.
- For large matrices or production pipelines, use optimized numerical libraries.
- If your matrix has more columns than rows, use a different form (LQ / full QR) or transpose-based workflows.