QR Decomposition Calculator

Factor a 2 by 2 matrix into orthogonal Q and upper triangular R matrices.

Matrix QR factorization
Enter the four matrix entries in row order, then calculate the Gram-Schmidt decomposition.

About QR decomposition

QR decomposition factors a matrix A into the product Q times R. The columns of Q are orthonormal, meaning each has length one and distinct columns are perpendicular. R is upper triangular, so every entry below its main diagonal is zero. For a full-rank square matrix, multiplying the displayed Q and R matrices reconstructs the original matrix, apart from small differences caused by decimal rounding. This calculator performs that factorization for a real 2 by 2 matrix. The calculation uses the classical Gram-Schmidt process on the columns of A. First, the calculator measures the Euclidean length of the first column. Dividing that column by its length creates the first unit vector in Q, while the length itself becomes the first diagonal entry of R. Next, the second column is projected onto the first unit vector. Subtracting that projection leaves a perpendicular vector, which is normalized to create the second column of Q. The projection coefficient and the second vector's length complete the upper triangular matrix R. QR factorization is a central tool in numerical linear algebra. It supports least-squares fitting, where an overdetermined system has more equations than unknowns, and it appears in algorithms for finding eigenvalues. Orthogonal transformations are numerically attractive because they preserve lengths and tend not to amplify rounding errors as severely as direct manipulation can. Although this page focuses on two dimensions so every step remains easy to inspect, the same column-orthogonalization idea extends to larger rectangular matrices. The input columns must be linearly independent for this calculator to produce two unit vectors. A zero first column cannot be normalized, and a second column that is merely a multiple of the first leaves no perpendicular direction after projection. Such a matrix is rank deficient and does not have the full QR form used here. QR decompositions can also differ by signs: negating one column of Q and the matching row of R leaves their product unchanged. This calculator chooses nonnegative diagonal lengths in R, providing a stable and predictable convention for comparing results.

QR decomposition examples

Matrix AFactorsObservation
[1, 0] [0, 1]Q = identity, R = identityThe columns are already orthonormal
[3, 0] [4, 5]Q = [0.6, -0.8] [0.8, 0.6], R = [5, 4] [0, 3]Gram-Schmidt separates length and direction
[1, 1] [1, -1]Q approximately [0.707107, 0.707107] [0.707107, -0.707107]The input columns are perpendicular but not normalized

How to calculate a QR decomposition

  1. Enter all four entries of matrix A in their labeled row and column positions.
  2. Confirm that the two columns are not zero or scalar multiples of each other.
  3. Select Calculate QR decomposition to apply the Gram-Schmidt process.
  4. Read Q by rows, read R by rows, and multiply them to check the factorization.

Frequently asked questions

What do Q and R represent?

Q contains orthonormal column vectors that describe directions. R is upper triangular and records the lengths and projection coefficients needed to reconstruct the original matrix.

Why must the columns be independent?

Gram-Schmidt needs a nonzero perpendicular remainder for every new Q column. Dependent columns make that remainder zero, so a full two-column orthonormal basis cannot be formed this way.

Is QR decomposition unique?

Sign choices can produce equivalent decompositions because matching signs in Q and R cancel in their product. Requiring nonnegative diagonal entries in R provides a common uniqueness convention.

How can I verify the result?

Multiply Q by R and compare each entry with the original matrix A. You can also check that Q transposed times Q equals the identity matrix.

What is QR decomposition used for?

It is widely used for least-squares problems, eigenvalue algorithms, and stable equation solving. Orthogonal matrices help control numerical error during those calculations.