QR Decomposition Calculator

Enter the four entries of your 2×2 matrix.

How it is calculated

The matrix is entered row by row as [a, b; c, d], so its columns are v1 = (a, c) and v2 = (b, d). Gram-Schmidt first sets r11 = |v1| and q1 = v1 ÷ r11. Then r12 = q1 · v2, the part of v2 along q1, is removed to give u2 = v2 − r12 × q1, and r22 = |u2| with q2 = u2 ÷ r22. The result satisfies A = Q × R, where Q holds q1 and q2 as columns and R = [r11, r12; 0, r22]. The diagonal of R is always positive here. Matrices whose columns are linearly dependent (determinant 0), or whose first column is zero, have no QR result in this tool and return nothing. Entries are shown to four decimals.

Worked example

Take A = [3, 1; 4, 2]. First column (3, 4) has length √(9 + 16) = 5, so r11 = 5 and q1 = (0.6, 0.8). Then r12 = 0.6 × 1 + 0.8 × 2 = 2.2. Subtract 2.2 × q1 = (1.32, 1.76) from the second column (1, 2) to get (−0.32, 0.24), whose length is 0.4. That is r22, and q2 = (−0.8, 0.6). The tool shows Q = [0.6000, -0.8000; 0.8000, 0.6000] and R = [5.0000, 2.2000; 0.0000, 0.4000]. Multiplying Q by R gives back A, and 5 × 0.4 = 2 equals the absolute value of the determinant of A.

Try this example →

Common mistakes

  • Typing the matrix by columns instead of rows. The fields are the rows [a, b; c, d], so the second row is c and d, not the second column.
  • Entering a singular matrix, such as [1, 2; 2, 4], where one column is a multiple of the other. No second orthogonal direction exists and the tool returns nothing.
  • Expecting the same signs as another program. Q and R are not unique up to sign; this tool keeps the diagonal of R positive, while NumPy or MATLAB may return a negative diagonal with flipped Q columns.
  • Reading the output as Q and R columns rather than rows. Each matrix is written row by row, with rows separated by semicolons.
  • Using the result for larger systems. Only 2×2 matrices are handled, and the four-decimal display is rounded, so small rounding differences appear if you multiply Q and R back by hand.

About this calculator

QR decomposition factors a matrix A into the product of an orthogonal matrix Q (whose columns are unit vectors, mutually perpendicular) and an upper-triangular matrix R. For a 2×2 matrix, this calculator applies the Gram-Schmidt process to the column vectors: the first column is normalized to form Q's first column, then the second column has its projection onto the first removed and is normalized to form the second — the projection coefficients and remaining lengths become the entries of R.

QR decomposition is a workhorse of numerical linear algebra, underpinning the least-squares method used to fit regression lines and curves to data, and forming the basis of the QR algorithm used to compute eigenvalues of a matrix. It's also more numerically stable than solving normal equations directly, which is why statisticians, engineers, and scientific-computing libraries such as LAPACK use it for solving linear systems and fitting models in practice.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Two quick checks make the output trustworthy. First, the two columns of Q should be perpendicular with length 1, so their dot product should be zero. Second, multiplying Q by R should give back your matrix. If the bottom right entry of R shows 0.0000, your columns are almost dependent and the second column of Q means nothing, so do not rely on it. Which matrix sizes beyond 2 by 2 would you like to see here?

Popular calculators

All Calculators