QR Decomposition Calculator - Q R Factor Solver for 2x2 and 3x3 Matrices

QR decomposition calculator that returns Q and R for 2x2 and 3x3 matrices, with Q^T Q = I, an upper triangular R, and a built-in verification step.

Updated: June 16, 2026 • Free Tool

QR Decomposition Calculator

Pick 2x2 for a small matrix or 3x3 for the canonical worked example.

Row 1, column 1 entry of A.

Row 1, column 2 entry of A.

Row 1, column 3 entry of A.

Row 2, column 1 entry of A.

Row 2, column 2 entry of A.

Row 2, column 3 entry of A.

Row 3, column 1 entry of A.

Row 3, column 2 entry of A.

Row 3, column 3 entry of A.

Results

Q factor (orthonormal)
0
R factor (upper triangular) 0
Q[1,1] 0
Q[1,2] 0
Q[1,3] 0
Q[2,1] 0
Q[2,2] 0
Q[2,3] 0
Q[3,1] 0
Q[3,2] 0
Q[3,3] 0
R[1,1] 0
R[1,2] 0
R[1,3] 0
R[2,2] 0
R[2,3] 0
R[3,3] 0
det(A) from R diagonal 0
Rank of A 0
Verification error ||QR - A|| 0

What Is a QR Decomposition Calculator?

A QR decomposition calculator rewrites a 2x2 or 3x3 matrix A as the product A = Q R, where Q is an orthogonal matrix (Q^T Q = I) and R is an upper triangular matrix. It runs the classical Gram-Schmidt process on the columns of A, normalizes each orthogonalized column, and reports Q and R as bracket matrices alongside a verification step. Use it for linear-algebra homework, for an orthogonal basis of the column space, for solving least-squares problems, or for building a numerically stable solve.

  • Linear-algebra homework and exams: Verify the canonical QR example A = [[12, -51, 4], [6, 167, -68], [-4, 24, -41]] from a textbook against the published Q and R.
  • Least-squares and regression fits: Replace the normal equations A^T A x = A^T b with the triangular solve R x = Q^T b for better numerical stability.
  • Eigenvalue and SVD building blocks: QR is the iteration step of the QR algorithm for eigenvalues and an intermediate step in the SVD.

The QR decomposition is defined for any real matrix with full column rank, square or not, and it is the workhorse behind the QR algorithm, the SVD, and most modern least-squares solvers.

For a symmetric positive definite A the upper triangular R of the thin QR equals the Cholesky factor from the Cholesky Decomposition Calculator, so the two factorizations describe the same matrix from two different angles.

How the QR Decomposition Calculator Works

The calculator reads the matrix shape, pulls the nine entries of A, and runs classical Gram-Schmidt on the columns of A. The first column of Q is the normalized first column of A, and each subsequent column of Q is the normalized projection of the corresponding column of A onto the orthogonal complement of the previous columns of Q. R is filled in lockstep from the dot products that the algorithm collects along the way.

A = Q R with Q^T Q = I, R upper triangular, R_ii = ||u_i||, R_ij = <e_i, a_j> for i < j, R_ij = 0 for i > j; u_0 = a_0, e_0 = u_0 / ||u_0||, u_k = a_k - sum_{j<k} <e_j, a_k> e_j, e_k = u_k / ||u_k||
  • A: The square input matrix with nine entries a11..a33 read in row-major order from the form.
  • Q: The orthogonal output matrix whose columns e_0, e_1, ... are the orthonormalized columns of A.
  • R: The upper triangular output matrix whose diagonal equals ||u_k|| and whose off-diagonal entries are dot products of e_i with a_j.
  • u_k: The k-th intermediate orthogonalized column of A produced by Gram-Schmidt before normalization.
  • e_k: The normalized column u_k / ||u_k|| that becomes the k-th column of Q.

The algorithm is identical for 2x2 and 3x3 inputs: classical Gram-Schmidt runs three inner-product steps for 3x3 and two for 2x2, and the R factor fills in lockstep. When a column of A is the zero vector or a multiple of an earlier column, the affected entries of Q and R are zeroed and the rank output reflects the drop.

Worked 3x3 example: canonical Wikipedia matrix

A = [[12, -51, 4], [6, 167, -68], [-4, 24, -41]]

e_0 = (12, 6, -4) / 14 = (6/7, 3/7, -2/7). After subtracting the projection of the second and third columns onto e_0, e_1, the algorithm produces e_1 = (-69/175, 158/175, 6/35) and e_2 = (-58/175, 6/175, -33/35).

Q matches the Wikipedia QR decomposition, and R = [[14, 21, -14], [0, 175, -70], [0, 0, 35]] with verification error 0.

R collects the column norms on the diagonal and the running inner products in the upper triangle, and the verification error is at machine precision.

According to Wikipedia, QR decomposition, a QR decomposition of a real square matrix A is the factorization A = Q R where Q is an orthogonal matrix (Q^T Q = I) and R is an upper triangular matrix; if A is invertible and the diagonal of R is required to be positive, the factorization is unique.

Each diagonal entry R_ii equals the Euclidean norm of an intermediate vector u_k from Gram-Schmidt, which is the same column length that the Vector Magnitude Calculator reports for a single vector.

Key Concepts Behind the QR Decomposition

Four ideas cover the full QR pipeline, and they are the same ideas a linear-algebra textbook uses for the chapter on orthogonalization.

Orthogonal matrix Q

A real matrix Q is orthogonal when Q^T Q = I, which means the columns of Q are orthonormal: each column has unit norm and distinct columns are perpendicular.

Upper triangular R

R is upper triangular, so the strict lower triangle is zero. The diagonal of R collects the running column norms from Gram-Schmidt and is non-negative by construction.

Classical Gram-Schmidt

Classical Gram-Schmidt builds Q one column at a time. Each later column of Q is the corresponding column of A minus its projections onto all previous columns of Q, then normalized.

Verification step Q R - A

The verification error is the largest absolute entry of the difference Q R - A. For a clean factorization on a well-conditioned matrix the error is at machine precision.

These four concepts are the only bookkeeping the algorithm does, and they line up with the structure of the result panel.

The off-diagonal entries of R are dot products of the orthonormal columns e_i with the original columns a_j, and the Dot Product Calculator computes the same inner product for a single pair of columns on demand.

How to Use This QR Decomposition Calculator

Pick the matrix shape, type the nine entries of A, and read Q and R from the result panel.

  1. 1 Choose the matrix size: Select 2x2 for a small matrix or 3x3 for the canonical worked example.
  2. 2 Type the matrix entries: Real numbers, decimals allowed. In 2x2 mode the a13, a21..a23, a31..a33 cells can be left at zero.
  3. 3 Read the Q bracket matrix: Q has orthonormal columns and satisfies Q^T Q = I. The bracket matrix is the top-line summary.
  4. 4 Read the R bracket matrix: R is upper triangular with the strict lower triangle shown as zeros.
  5. 5 Check the verification error: The verification error is the largest absolute value of Q R - A. For a clean factorization it should be at or below 1e-12.
  6. 6 Handle a rank-deficient input: If the rank output drops below the matrix size, the dependent column of A is shown as zeros in Q and R.

To verify the canonical QR example from Wikipedia, pick 3x3, leave the default values, and the result panel shows Q and R that match the published factorization with a verification error of zero.

After the QR decomposition is in hand, the least-squares solution x = A^+ b falls out of the triangular solve R x = Q^T b, which is the same A^+ that the Pseudoinverse Calculator returns from the (A^T A)^-1 A^T identity for full column rank A.

Benefits of This QR Decomposition Calculator

The QR decomposition is one of the most useful matrix factorizations in numerical linear algebra, and the calculator makes the same algorithm usable in seconds.

  • Numerical stability over LU: Classical Gram-Schmidt is the textbook algorithm and gives the right answer on well-conditioned inputs without pivoting.
  • Direct least-squares link: The QR decomposition converts A x = b into the triangular solve R x = Q^T b in a single step, which avoids the catastrophic cancellation that forming A^T A can introduce.
  • Built-in verification step: The Q R - A error is reported next to the bracket matrices, so the user can trust the factorization without a separate cross-multiplication.
  • Per-entry readability: Every Q and R entry is reported individually, so the user can read off a single coefficient for a downstream solve or feed a single column of Q into a projection.
  • Bracket-matrix display: Q and R are rendered as copy-friendly bracket-matrix strings, so the user can paste them straight into a homework answer or a downstream script.

The result panel mirrors the structure of the algorithm: Q and R as bracket matrices, individual entries underneath, verification error at the bottom.

When A is square and invertible, the QR decomposition lets the user solve A x = b by replacing it with the triangular system R x = Q^T b, which is the same class of linear solve that the System of Equations Calculator handles with Cramer's rule for 2x2 and 3x3 systems.

Factors That Affect Your QR Decomposition Result

A handful of input choices and structural facts decide whether the QR decomposition exists and how accurate the factor pair is.

Column rank of A

QR exists when the columns of A span the full column space. A zero column or a linear combination produces a zero intermediate vector u_k, the rank output drops.

Numerical conditioning

Matrices with a very small minimum singular value lose precision. Classical Gram-Schmidt is more sensitive than Householder QR on ill-conditioned inputs.

Sign convention for R

Classical Gram-Schmidt produces R with a non-negative diagonal by construction. To flip a sign, multiply the corresponding column of Q by -1 and R by -1.

Decimal precision

Output is rounded to four decimal places for display, but the calculation uses full double precision internally.

  • The calculator is restricted to 2x2 and 3x3 square matrices. For larger A a production Householder QR is the right next step because it is numerically more stable than classical Gram-Schmidt.
  • The output is rounded for display, so an entry that is mathematically zero can show as 0.0000 next to a near-zero noise term.
  • Classical Gram-Schmidt is simple to teach but is known to lose orthogonality in finite precision for ill-conditioned inputs.

Classical Gram-Schmidt is the right choice for the calculator because it is short enough to fit in a small form factor, the columns of Q are built one at a time in a way the user can audit, and the verification error catches the cases where numerical drift would otherwise go unnoticed.

According to Wolfram MathWorld, QR Decomposition, the reduced QR factorization A = Q_1 R_1 has Q_1 with orthonormal columns and R_1 upper triangular, and is unique when the diagonal of R_1 is positive.

According to MIT OpenCourseWare 18.06 Linear Algebra (Strang), the QR decomposition is the matrix-level rewrite of Gram-Schmidt, where Q is the matrix of orthonormal columns and the least-squares solution to A x = b is the triangular solve R x = Q^T b.

The QR decomposition trades the cofactor-style structure that the Adjoint Matrix Calculator returns for an orthogonal times upper triangular split, and the choice between them comes down to whether the downstream use is an inverse, a solve, or a stable least-squares fit.

QR decomposition calculator showing a 3x3 input matrix A with the orthonormal Q and upper triangular R output, plus the verification error panel
QR decomposition calculator showing a 3x3 input matrix A with the orthonormal Q and upper triangular R output, plus the verification error panel

Frequently Asked Questions

Q: What is the QR decomposition of a matrix?

A: The QR decomposition of a real square matrix A is the factorization A = Q R, where Q is an orthogonal matrix (Q^T Q = I) and R is an upper triangular matrix. If A is invertible and the diagonal of R is required to be positive, the factorization is unique and Q has orthonormal columns built by the classical Gram-Schmidt process.

Q: How do you compute the QR decomposition of a 3x3 matrix?

A: Apply classical Gram-Schmidt to the columns of A: set u_0 = a_0 and e_0 = u_0 / ||u_0||, then for k = 1, 2 compute u_k = a_k - sum_{j<k} <e_j, a_k> e_j and e_k = u_k / ||u_k||. The matrix Q has columns e_0, e_1, e_2 and R_ij = <e_i, a_j> for i <= j, with R_ii = ||u_i|| and a zero strict lower triangle.

Q: What is the difference between the QR decomposition and the LU decomposition?

A: LU decomposition factors a general square matrix A as A = L U with L lower triangular and U upper triangular, and it requires pivoting for numerical stability. QR factorization A = Q R replaces L with an orthogonal Q, costs roughly twice as much, but is numerically far more stable and is the standard tool for least-squares problems.

Q: Can the QR decomposition be used for least squares problems?

A: Yes. The least-squares solution to an over-determined system A x = b is x = (A^T A)^-1 A^T b, but the same answer is obtained by solving the triangular system R x = Q^T b after the QR decomposition. The QR route is preferred for ill-conditioned A because it avoids forming A^T A, which can amplify numerical error.

Q: What is the difference between full QR and thin QR decomposition?

A: The full QR decomposition writes an m x n matrix A as Q R with Q m x m orthogonal and R m x n upper triangular. The thin (or reduced) QR decomposition drops the last m - n columns of Q and the last m - n rows of R, leaving an m x n Q_1 and an n x n upper triangular R_1. For a square A both forms give a square Q and a square R.

Q: Does this QR decomposition calculator work for rectangular matrices?

A: This calculator focuses on 2x2 and 3x3 square matrices for a clean display. For rectangular A the same classical Gram-Schmidt process applies column by column, the R factor is m x n upper trapezoidal, and the thin Q has orthonormal columns. The same algorithm and the same identity A = Q R hold for any rectangular A with full column rank.