🧮
🧮 Math & statistics

QR Decomposition Calculator (A = Q·R by Gram–Schmidt)

Results update as you type.

Your numbers

Understanding the QR decomposition calculator — concept and principle

This calculator factors a matrix with independent columns as A = Q·R, where Q has orthonormal columns and R is upper triangular with a positive diagonal. It also shows the sizes and |det A| for square matrices. Use it for linear algebra courses, solving least-squares problems stably, and as the basic step of eigenvalue algorithms.

QR decomposition of a 3×3 matrixGram–Schmidt builds Q, records RQ6/7−69/175−58/1753/7158/1756/175−2/76/35−33/35R1421−140175−700035‖a₁‖ = 14 · new part of a₂ = 175 · of a₃ = 35|det A| = 14 × 175 × 3585,750
Q has orthonormal columns; R is upper triangular with the lengths 14, 175 and 35 on its diagonal.

How it is calculated

The calculator applies Gram–Schmidt to the columns a₁, …, aₙ of A:

  1. q₁ = a₁ ÷ ‖a₁‖.
  2. For each next column, subtract its projections onto the previous q's, then divide by the length: q_k = (a_k − Σ (q_j·a_k) q_j) ÷ ‖…‖.
  3. R = QᵀA, so r_jk = q_j · a_k for j ≤ k and 0 below the diagonal.

The thin (reduced) form is returned: Q is m × n and R is n × n. Projections are repeated once to improve numerical accuracy. For a square matrix, |det A| = product of R's diagonal.

The principle

Gram–Schmidt turns any set of independent vectors into an orthonormal set spanning the same space, one vector at a time. Each original column can then be rebuilt from the q's using only the q's that came before it, which is why R is upper triangular. Orthonormal columns make QᵀQ = I, so solving Ax = b in the least-squares sense reduces to Rx = Qᵀb, solved by back-substitution. Because Q preserves lengths, this route avoids the loss of accuracy that comes with forming AᵀA.

Worked example

Default: A = [12 −51 4; 6 167 −68; −4 24 −41].

  1. ‖a₁‖ = √(144 + 36 + 16) = 14, so q₁ = (6/7, 3/7, −2/7) ≈ (0.857143, 0.428571, −0.285714).
  2. r₁₂ = q₁·a₂ = 21. a₂ − 21q₁ = (−69, 158, 30), length 175, so q₂ ≈ (−0.394286, 0.902857, 0.171429).
  3. r₁₃ = −14 and r₂₃ = −70; what is left of a₃ has length 35, giving q₃ ≈ (−0.331429, 0.0342857, −0.942857).
  4. R = [14 21 −14; 0 175 −70; 0 0 35].
  5. |det A| = 14 × 175 × 35 = 85,750.

How to read the result

The diagonal entries of R are the lengths of the parts of each column that are new compared with the earlier columns. A very small diagonal entry means that column is nearly a combination of the earlier ones. QᵀQ should be the identity; you can check by multiplying. The factorisation is unique once R's diagonal is required to be positive.

Common mistakes

Keep in mind: Classical Gram–Schmidt can lose orthogonality with nearly dependent columns; the repeated projection here helps, but for very ill-conditioned data Householder-based methods are more robust.

Frequently asked questions

What is QR decomposition used for?

Stable least-squares solving, the QR eigenvalue algorithm, and building orthonormal bases.

Is QR unique?

Yes, for independent columns, once the diagonal of R is required to be positive.

How does it relate to Gram–Schmidt?

Q contains the Gram–Schmidt vectors and R records the coefficients used to build them.

Sources: Coordinated Linear Algebra (University of Nebraska–Lincoln), §7.6 QR Factorization and Least Square Approximations

Checked 9 Nov 2026. Coordinated Linear Algebra (University of Nebraska–Lincoln), §7.6 Extra Topic: QR Factorization and Least Square Approximations — Theorem 7.6.2 (every m×n matrix with linearly independent columns has A = QR, Q with orthonormal columns, R upper triangular with positive diagonal; R = QᵀA), Gram–Schmidt construction.

🧮 All math & statistics tools →🌍 Calculators by country →