QR Decomposition Calculator
Factor a matrix into an orthogonal Q and upper-triangular R using Householder reflections, with an orthogonality check and least-squares solving.
Q — orthogonal (3×3)
| 0.8571 | -0.3943 | -0.3314 |
| 0.4286 | 0.9029 | 0.0343 |
| -0.2857 | 0.1714 | -0.9429 |
R — upper triangular (3×3)
| 14 | 21 | -14 |
| 0 | 175 | -70 |
| 0 | 0 | 35 |
Orthogonality check
QᵀQ was multiplied out: the largest deviation from the identity matrix is 3.33e-16, and Q·R differs from A by at most 2.84e-14. Both are floating-point noise, so the factorisation is sound. Q’s columns are an orthonormal basis, and because Householder reflections are themselves orthogonal, that stays true even for badly conditioned matrices where Gram-Schmidt drifts.
What is the QR Decomposition Calculator?
The ByteTools QR Decomposition Calculator factors any matrix with at least as many rows as columns into an orthogonal matrix Q and an upper-triangular R.
- Householder reflections — numerically stable where Gram-Schmidt drifts
- Conventional sign normalisation so R has a non-negative diagonal
- Reports max |QᵀQ − I| and max |QR − A| measured before display rounding
- Optional least-squares solve of A·x ≈ b with the residual norm
- Handles rectangular matrices up to 8×8
- Fully client-side — your data never leaves the browser
How to use the QR Decomposition Calculator
- 1
Enter matrix A with one row per line; it needs at least as many rows as columns.
- 2
Read Q and R side by side, and check the two accuracy tiles for QᵀQ and Q·R.
- 3
Tick 'Solve the least-squares problem' if you want to fit A·x ≈ b.
- 4
Enter the vector b with one value per row of A.
- 5
Read the least-squares solution and its residual norm, then copy what you need.
About the QR Decomposition Calculator
The ByteTools QR Decomposition Calculator factors any matrix with at least as many rows as columns into an orthogonal matrix Q and an upper-triangular R. It uses Householder reflections rather than Gram-Schmidt: for each column it builds v = x + sign(x₁)‖x‖e₁ and applies the reflection H = I − 2vvᵀ/vᵀv. Because each reflection is exactly orthogonal, Q stays orthogonal even for badly conditioned matrices where Gram-Schmidt visibly drifts.
The page checks its own work in two ways: it multiplies QᵀQ out and reports the largest deviation from the identity matrix, and it multiplies Q·R and reports the largest deviation from your original matrix. Both are measured before any display rounding, so the numbers you see are the true accuracy of the factorisation. Signs are normalised so R has a non-negative diagonal, which is the conventional unique choice.
Tick the least-squares option and the tool solves A·x ≈ b by back-substituting R·x = Qᵀb, and reports the residual norm. Everything is computed in your browser with JavaScript — no uploads, no storage, and it works offline.
Frequently asked questions
What is QR decomposition used for?
It is the standard tool for least-squares fitting and a building block of the QR algorithm for eigenvalues. Writing A = QR turns a hard normal-equations problem into a simple triangular back-substitution, without ever forming the poorly conditioned AᵀA.
Is Householder QR better than Gram-Schmidt?
For numerical work, yes. Each Householder reflection is exactly orthogonal, so rounding errors do not accumulate into a loss of orthogonality in Q. Classical Gram-Schmidt can produce visibly non-orthogonal columns on ill-conditioned matrices, which is why libraries such as LAPACK use Householder.
Is QR decomposition unique?
It is unique for a full-rank matrix once you fix a sign convention, because Q and R can each be negated column by column and row by row. This calculator uses the usual convention of a non-negative diagonal on R, which is why its output matches most textbooks.
How does QR solve least squares?
Substituting A = QR into ‖Ax − b‖ and using QᵀQ = I turns the problem into minimising ‖Rx − Qᵀb‖. The top rows can be solved exactly by back substitution, and the rows below the triangle give the residual that no choice of x can remove.
What does it mean if R has a zero on its diagonal?
It means the columns of A are linearly dependent, so A is rank deficient and the least-squares solution is not unique. This tool detects that case and tells you rather than dividing by a near-zero pivot.
Related tools
Gram-Schmidt Calculator
Turn any set of vectors into an orthogonal or orthonormal basis with the modified Gram-Schmidt process, showing every projection subtraction as a step.
LU Decomposition Calculator
Factor a square matrix into P, L and U by Doolittle elimination with partial pivoting, then use the factorisation to get the determinant and solve A·x = b.
Vector Projection Calculator
Project one vector onto another to get the vector projection, scalar projection, orthogonal rejection and the angle between, for 2D or 3D vectors.
Matrix Calculator
Add, subtract and multiply matrices up to 6×6, transpose them or scale by a number. Type matrices as simple rows and get instant, copyable results.
Eigenvalue and Eigenvector Calculator
Find eigenvalues and eigenvectors of 2×2 and 3×3 matrices from the characteristic polynomial, with algebraic and geometric multiplicity spelled out.