QR Decomposition Calculator

Factor a 3 by 3 matrix into an orthonormal Q and an upper triangular R.

Math and PercentUpdated 2026-11-202 min read
QR Decomposition Calculator
Q(1,1)
...
Q(1,2)...
Q(1,3)...
Q(2,1)...
Q(2,2)...
Q(2,3)...
Q(3,1)...
Q(3,2)...
Q(3,3)...
R(1,1)...
R(1,2)...
R(1,3)...
R(2,2)...
R(2,3)...
R(3,3)...

What it does

QR decomposition writes a matrix as the product of an orthonormal matrix Q and an upper triangular matrix R. It is one of the workhorses of numerical linear algebra, used in least squares fitting, eigenvalue algorithms and solving systems of equations.

University of Waterloo lecture notes describe the Gram-Schmidt route to QR: take the columns of A as the proposed vectors, orthogonalise each one against the previously built q vectors, then normalise it. The projection coefficients become the entries of R.

A later Waterloo lecture notes that Householder reflections and Givens rotations are alternative ways to build the same factorisation. Those methods are more stable in floating point arithmetic, while Gram-Schmidt is the easiest to follow by hand.

This tool applies classical Gram-Schmidt to the columns of a 3 by 3 matrix. It prints all nine entries of Q and the six nonzero entries of R, each to six decimal places. If the columns are dependent, it reports the problem instead of dividing by zero.

The result is a factorisation, not a solution to a system. Once you have Q and R, solving A x = b becomes the triangular solve R x = Q transpose b.

How to use

  1. Enter the nine entries of the matrix row by row.
  2. Read the Q entries, which form an orthonormal matrix with Q transpose Q equal to the identity.
  3. Read the R entries, which are zero below the diagonal.
  4. Check that the diagonal of R contains the lengths of the successive orthogonalised columns.
  5. Multiply Q by R on paper to confirm that you recover the input matrix.
  6. If the tool reports dependent columns, change one entry and try again.

Formula

q1 = a1 / |a1|. r(1,j) = q1 dot a(j). For j = 2, 3: v(j) = a(j) minus the sum of r(i,j) q(i) for i less than j, q(j) = v(j) / |v(j)|, and r(j,j) = |v(j)|.
a(j)
Column j of the input matrix.
q(j)
Column j of Q, a unit vector orthogonal to the earlier q vectors.
r(i,j)
Entry of R, the coefficient of q(i) in column j of A.
dot
The dot product used to compute each projection coefficient.

The engine stores the input in column order, orthogonalises and normalises each column, and rejects a column whose remaining length is effectively zero. That check is what detects linear dependence.

Worked example

Example: factoring a small 3 by 3 matrix

A has columns (1, 1, 0), (1, 0, 1) and (0, 1, 1).

  1. The first column has length sqrt(2) = 1.414214, so r11 = 1.414214 and q1 = (0.707107, 0.707107, 0).
  2. Projecting the second column onto q1 gives r12 = 0.707107.
  3. Subtracting that projection leaves a vector of length 1.224745, so r22 = 1.224745 and q2 = (0.408248, -0.408248, 0.816497).
  4. Projecting the third column gives r13 = 0.707107 and r23 = 0.408248.
  5. The remaining vector has length 1.154701, giving r33 = 1.154701 and q3 = (-0.577350, 0.577350, 0.577350).
  6. The tool reports those six R entries and all nine entries of Q.
  7. Multiplying Q by R returns the original matrix.

Reference table

Factors for the worked matrix
MatrixColumn 1Column 2Column 3
Q(0.707107, 0.707107, 0)(0.408248, -0.408248, 0.816497)(-0.577350, 0.577350, 0.577350)
R column(1.414214, 0, 0)(0.707107, 1.224745, 0)(0.707107, 0.408248, 1.154701)

Limits

  • The tool handles 3 by 3 matrices only.
  • Classical Gram-Schmidt can lose accuracy for nearly dependent columns.
  • Householder or Givens methods are preferred in production numerical software.
  • Results are rounded to six decimal places for display.

Common mistakes

  • Entering the matrix in row order when you are thinking in columns.
  • Using dependent columns and expecting a factor anyway.
  • Assuming R has entries below the diagonal. It does not.
  • Forgetting that Q has unit columns, not unit rows.
  • Multiplying R by Q instead of Q by R when checking the product.

Try it yourself

Quick checks. Answers sit tucked under each question.

What is r11 for the worked matrix?

1.414214, the length of the first column (1, 1, 0).

What property does Q satisfy?

Its columns are orthonormal, so Q transpose times Q is the identity matrix.

What happens if two columns are the same?

The second orthogonalised column is zero, and the tool reports that the columns are dependent.

Questions

What is QR decomposition used for?

Least squares regression, eigenvalue algorithms, solving linear systems and orthogonalising bases.

How is it different from LU?

LU uses a unit lower triangular L and an upper triangular U without requiring orthonormal columns.

How is it different from Cholesky?

Cholesky needs a symmetric positive definite matrix and returns L L transpose. QR works for general matrices with independent columns.

Why does Q have orthonormal columns?

Because the construction normalises each vector after removing its components along earlier ones.

Is Gram-Schmidt the only method?

No. Householder reflections and Givens rotations are more stable alternatives used in numerical libraries.

Can I use this for a 2 by 2 matrix?

Not on this page. The tool is built for 3 by 3 inputs.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.