Advertisement

QR decomposition calculator

Choose the size and enter the matrix row by row. The calculator uses Householder reflections and shows Q, R and the product Q R as a check.

Calculator

Orthogonal matrix Q
0.6, 0.8; 0.8, -0.6
Upper triangular matrix R
5, 0; 0, 5
Q times R
3, 4; 4, -3
Q transpose times Q
1, 0; 0, 1

Advertisement

How this calculator works

QR decomposition writes a matrix as Q R, where Q has orthonormal columns and R is upper triangular. Householder reflections zero out entries below the diagonal one column at a time while keeping Q orthogonal. This calculator chooses each reflection so the diagonal of R is positive; the signs of the columns of Q are then fixed. For a square matrix, Q is square and R has the same shape. The product Q R always returns the original matrix.

Formula

A = Q R, with Q^T Q = I and R upper triangular. The diagonal of R holds the lengths of the orthogonalized columns.

Worked example

For the matrix with rows 3, 4 and 4, -3, the columns already have length 5 and are perpendicular. Its QR factors are Q equal to 0.6, 0.8; 0.8, -0.6 and R equal to 5, 0; 0, 5. An upper triangular matrix is already in QR form with Q equal to the identity.

Advertisement

Frequently asked questions

What is the difference from Gram-Schmidt?

Both produce an orthonormal basis, but Householder QR is more stable numerically because it uses reflections instead of subtracting projections one at a time.

Why is the diagonal of R positive?

A QR factor is unique only up to signs. Choosing positive diagonal entries fixes one convention, which this calculator follows.

Can QR solve least squares?

Yes. For an overdetermined system, solving R x = Q transpose b avoids forming the normal equations and loses less precision.

Sources

Advertisement