Skip to content

QR Decomposition Calculator

Factor a matrix into Q and R with Householder reflections, with rank, error checks and steps.

AvailableRuns in your browserFree · No sign-up

QR Decomposition Calculator

Matrix A (3 × 3)
Rows3
Columns3
Method

Calculations use full double precision; this only affects display.

Q (orthonormal columns)
0.8571-0.3943-0.3314
0.42860.90290.0343
-0.28570.1714-0.9429

3 × 3

R (upper triangular)
1421-14
0175-70
0035

3 × 3

Numerical rank
3 of 3
full rank
Reconstruction error
1.60e-16
‖A − QR‖ / ‖A‖
Orthogonality error
5.71e-16
‖QᵀQ − I‖
Rank tolerance
1.17e-13
Check: Q × R
QR (should equal A)
12-514
6167-68
-424-41

3 × 3

Step by step (2 Householder reflections)
  1. Step 1. Reflect column 1 (rows 1–3) onto the axis with H1 = I − 2vvᵀ, v = [0.9636, 0.2224, -0.1482]. This zeroes the entries below the diagonal.

    After step 1
    -14-2114
    0173.9231-65.6923
    019.3846-42.5385

    3 × 3

  2. Step 2. Reflect column 2 (rows 2–3) onto the axis with H2 = I − 2vvᵀ, v = [0.9985, 0.0555]. This zeroes the entries below the diagonal.

    After step 2
    -14-2114
    0-17570
    00-35

    3 × 3

Finally, rows of R with a negative diagonal entry are multiplied by −1 (and the matching columns of Q), so R's diagonal is non-negative.

What A = QR means

A = QR,   QᵀQ = I,   R upper triangular

Householder QR applies reflections Hk = I − 2vkvkᵀ that zero out each column below the diagonal: R = Hp…H1A and Q = H1…Hp. It is backward stable, so Q stays orthonormal to machine precision even for ill-conditioned matrices. Modified Gram–Schmidt orthogonalizes the columns one at a time and is easier to follow by hand, but loses orthogonality as the condition number grows.

Numbers are IEEE double precision (about 16 significant digits). The rank is estimated with column-pivoted QR, counting diagonal entries larger than max(m, n) × machine epsilon × the largest one.

Your data is processed locally in your browser and is not uploaded to OZVILO servers.

How to use the QR Decomposition Calculator

  1. 1Enter the matrix in the grid, paste it as text, or load an example (square, tall, wide or rank-deficient).
  2. 2Choose Householder (recommended) or modified Gram–Schmidt, and thin or full QR for tall matrices.
  3. 3Read Q and R, the numerical rank and the reconstruction and orthogonality errors.
  4. 4Open the steps to see each Householder reflection, and copy or download Q and R as CSV.

Examples

  • Classic 3 × 3

    Input
    [[12, −51, 4], [6, 167, −68], [−4, 24, −41]]
    Result
    R = [[14, 21, −14], [0, 175, −70], [0, 0, 35]] · Q columns orthonormal
  • Rank-deficient

    Input
    [[1, 2, 3], [2, 4, 6], [1, 0, 1]]
    Result
    Numerical rank 2 of 3 — flagged, with A = QR still verified

QR Decomposition Calculator features

  • Householder reflections (backward stable)
  • Modified Gram–Schmidt for learning
  • Thin and full QR
  • Rank detection, error checks, step-by-step reflections
  • CSV download

Frequently asked questions

What is QR decomposition?

It writes a matrix A as Q × R, where Q has orthonormal columns (QᵀQ = I) and R is upper triangular. It's used to solve least-squares problems, compute eigenvalues and orthonormalize vectors.

Why Householder instead of Gram–Schmidt?

Householder reflections are numerically stable: Q stays orthogonal to about machine precision even for ill-conditioned matrices. Gram–Schmidt is easier to follow by hand but can lose orthogonality badly — compare the orthogonality error on a near-singular matrix.

Is the QR decomposition unique?

For a full-rank matrix it's unique once R's diagonal is required to be positive, which this tool enforces. For a rank-deficient matrix some columns of Q aren't determined by A, and the tool tells you so.

How accurate are the results?

Calculations use double-precision floating point (about 16 significant digits). Tiny values like 1e-16 are rounding noise and display as 0 at normal precision; the reconstruction error ‖A − QR‖/‖A‖ shows how close the factorization is.