Skip to main content
Skip to calculator
Advertisement

Last updated: August 5, 2026

QR Decomposition Calculator

Quick Answer

The QR Decomposition Calculator factors a 2x2 matrix into an orthogonal matrix Q and an upper triangular matrix R using the Gram-Schmidt process. It normalizes the first column, projects and orthogonalizes the second, and returns all seven entries needed to verify A = QR.

QR decomposition splits a matrix into an orthogonal matrix and an upper triangular matrix using the Gram-Schmidt process.

Key Takeaways

  • QR decomposition factors a matrix A into an orthogonal matrix Q and an upper triangular matrix R, so A = QR.
  • The Gram-Schmidt process builds Q one column at a time by normalizing and orthogonalizing successive columns of A.
  • Q's columns are unit vectors that are mutually perpendicular, satisfying QᵀQ = I.
  • R is upper triangular; for a 2x2 matrix, its bottom-left entry is always zero.
  • QR decomposition provides a numerically stable way to solve least-squares regression and eigenvalue problems.
Helpful
Not helpful
Save as image
Share
Embed
Cite
Write feedback

Formula

q1 = v1 / ‖v1‖; r12 = q1 · v2; u2 = v2 − r12·q1; q2 = u2 / ‖u2‖ (Gram-Schmidt process, A = QR)

Where:

  • A=Original 2x2 matrix
  • Q=Orthogonal matrix
  • R=Upper triangular matrix
QR Decomposition Calculator illustrationA teaching diagram for the QR Decomposition Calculator. It labels the inputs, shows a flow from setup to simplification, and highlights the Gram-Schmidt process that factors a 2 by 2 matrix into an orthogonal matrix Q and an upper triangular matrix R.QR Decomposition CalculatorInputsEnter matrix entries a, b, c, dKeep columns independentTreat A as a 2\u00d72 matrixFormulaSee full formula belowOutputsRead orthogonal matrix QRead triangular matrix RVerify Q columns are unitFormulaq1 = v1 / \u2016v1\u2016; r12 = q1 \u00b7 v2; u2 = v2 \u2212 r12\u00b7q1q2 = u2 / \u2016u2\u2016 (Gram-Schmidt process, A = QR)Reliable workflow1. Normalize column 12. Project column 23. Orthogonalize it4. Normalize column 2
This illustration summarizes the thinking behind the QR Decomposition Calculator: normalize the first column, project and orthogonalize the second, then normalize it to build Q and R.

Watch & Learn

Gilbert Strang explains how the Gram-Schmidt process orthogonalizes the columns of a matrix to produce the QR factorization A = QR.

Worked Examples

Decompose a simple 2x2 matrix

Columns (4, 3) and (1, 2) produce clean, easily verified Q and R matrices.

  1. 1Column 1 is (4, 3); its norm is √(16+9) = 5, so q1 = (0.8, 0.6) and r11 = 5.
  2. 2Project column 2 (1, 2) onto q1: r12 = 0.8×1 + 0.6×2 = 2.0.
  3. 3Subtract the projection: u2 = (1 − 2×0.8, 2 − 2×0.6) = (-0.6, 0.8).
  4. 4Normalize u2: ‖u2‖ = 1, so q2 = (-0.6, 0.8) and r22 = 1.
Final Answer: Q = [[0.8,-0.6],[0.6,0.8]], R = [[5,2],[0,1]]

Decompose the identity matrix

The identity matrix already has orthonormal columns, so Q equals A and R equals the identity.

  1. 1Column 1 is (1, 0), already unit length, so q1 = (1, 0) and r11 = 1.
  2. 2Column 2 (0, 1) has zero projection onto q1: r12 = 0.
  3. 3u2 = (0, 1), already unit length, so q2 = (0, 1) and r22 = 1.
Final Answer: Q = identity, R = identity

Decompose a matrix with a larger first column

A first column with a bigger norm shows how r11 scales accordingly.

  1. 1Column 1 is (6, 8); its norm is √(36+64) = 10, so q1 = (0.6, 0.8) and r11 = 10.
  2. 2Project column 2 (2, 4) onto q1: r12 = 0.6×2 + 0.8×4 = 4.4.
  3. 3Subtract the projection and normalize the remainder to get q2 and r22.
Final Answer: r11 = 10, r12 = 4.4

Introduction

The QR Decomposition Calculator factors any invertible 2×2 matrix into the product of an orthogonal matrix Q and an upper triangular matrix R, using the Gram-Schmidt orthogonalization process taught in every linear algebra course. This factorization is a workhorse of numerical linear algebra, used to solve least-squares problems, compute eigenvalues, and stabilize matrix computations, and this tool walks through every step of building Q and R from a simple 2×2 matrix.

QR Decomposition Calculator - Illustration
QR Decomposition Calculator

What is QR decomposition?

QR decomposition expresses a matrix A as the product of an orthogonal matrix Q (whose columns are unit vectors, all perpendicular to each other) and an upper triangular matrix R (with zeros below the main diagonal). This factorization exists for any matrix with linearly independent columns.

  • Q has orthonormal columns: each has length 1 and all are mutually perpendicular.

  • R is upper triangular, with a zero in the bottom-left entry for a 2x2 matrix.

  • A = QR reconstructs the original matrix exactly.

How the Gram-Schmidt process works

The Gram-Schmidt process builds Q one column at a time. The first column of Q is simply the first column of A, normalized to unit length. The second column of Q is found by subtracting the part of the second column of A that points in the direction of the first Q column (the projection), then normalizing what remains.

  • Normalize the first column to get q1; its length becomes r11.

  • Project the second column onto q1; that projection length becomes r12.

  • Subtract the projection from the second column to get an orthogonal remainder.

  • Normalize the remainder to get q2; its length becomes r22.

Using the inputs correctly

Enter the four entries of a 2×2 matrix, read as A = [[a, b], [c, d]] with columns (a, c) and (b, d). The two columns must be linearly independent (not parallel) for the decomposition to exist.

  • a, b, c, d can be any finite numbers.

  • The two columns (a,c) and (b,d) must not be parallel/dependent.

  • The first column cannot be the zero vector.

Reading the outputs

The Q entries form an orthogonal matrix whose columns are unit vectors at right angles to each other. The R entries form an upper triangular matrix, with r11 and r22 representing the lengths involved in building each Q column, and r12 capturing the projection between them.

q11, q21:

the first column of Q (unit vector).

q12, q22:

the second column of Q (unit vector, perpendicular to the first).

r11, r12, r22:

the upper triangular matrix R.

A dependable step-by-step workflow

These four steps mirror exactly how the calculator builds Q and R using Gram-Schmidt.

  • Normalize the first column of A.

  • Project the second column onto the first, normalized column.

  • Subtract the projection to orthogonalize the second column.

  • Normalize the orthogonalized second column.

Common mistakes and how to avoid them

A common mistake is forgetting to subtract the projection before normalizing the second column, which would leave Q non-orthogonal. Another is assuming any matrix works — columns that are parallel (linearly dependent) have no valid QR decomposition with a non-singular R.

  • Always subtract the projection before normalizing the second column.

  • Check that the two columns aren't parallel or the decomposition fails.

  • Remember Q's columns must be perpendicular unit vectors, not just any vectors.

Where QR decomposition shows up

QR decomposition is central to solving least-squares regression problems numerically, computing eigenvalues via the QR algorithm, and providing numerically stable alternatives to direct matrix inversion in engineering and data science software.

  • Solving least-squares regression problems numerically.

  • The QR algorithm for computing matrix eigenvalues.

  • Numerically stable solutions to linear systems in engineering software.

  • Signal processing and computer vision matrix computations.

Reference patterns to remember

A quick reference table shows how simple matrices decompose, useful for checking your own hand calculations.

  • The identity matrix decomposes into Q = I and R = I.

  • A diagonal matrix decomposes into Q = I (or a sign-flipped identity) and R equal to itself.

  • Orthonormal check: each Q column should have length 1, and the two columns' dot product should be 0.

Matrix AQR
[[1,0],[0,1]]identityidentity
[[4,1],[3,2]][[0.8,-0.6],[0.6,0.8]][[5,2],[0,1]]

Quick Reference Card

QR Decomposition Cheat Sheet

Quick referenceQR Decomposition Calculator

A = QR via Gram-Schmidt

Valid range: 2x2 matrices with linearly independent columns

Common Values

Identity matrixQ=I, R=I
[[4,1],[3,2]]Q=[[0.8,-0.6],[0.6,0.8]], R=[[5,2],[0,1]]
Quick check 1Use a small valid input to confirm the workflow.
Quick check 2Compare a symmetric or balanced case when possible.

Watch Out

  • Parallel (linearly dependent) columns have no valid QR decomposition.
  • Always subtract the projection before normalizing the second column.
  • R's bottom-left entry must always be zero for a correct decomposition.
  • Check domain restrictions before trusting the final value.

Pro Tips

  • Verify orthogonality by checking Q's columns have length 1 and dot product 0.
  • Multiply Q by R to confirm you recover the original matrix A.
  • Use positive diagonal entries in R for a unique, standard decomposition.
  • Estimate the answer mentally first so large errors stand out.

FAQs

What does it mean for Q to be orthogonal?

An orthogonal matrix has columns that are unit vectors (length 1) and mutually perpendicular to each other. This means QᵀQ equals the identity matrix, a property that makes Q numerically stable to work with.

Why is R upper triangular?

The Gram-Schmidt process builds each column of Q using only the current and previous columns of A, which naturally produces zeros below the diagonal in R — for a 2x2 matrix, that means the bottom-left entry of R is always zero.

What happens if the two columns of A are parallel?

If the columns are linearly dependent (parallel), the second orthogonalized vector would have zero length, making normalization (division by zero) impossible, so no valid QR decomposition with an invertible R exists.

How do I verify a QR decomposition is correct?

Multiply Q by R and confirm you get back the original matrix A. You can also verify Q is orthogonal by checking that its columns have length 1 and their dot product is 0.

Is QR decomposition unique?

For a matrix with linearly independent columns, the QR decomposition is unique if you require the diagonal entries of R to be positive, which is the convention this calculator follows.

How is QR decomposition used in least-squares regression?

QR decomposition transforms the normal equations of a least-squares problem into a simpler triangular system that can be solved by back-substitution, avoiding the numerical instability of directly inverting AᵀA.

Does this calculator work for matrices larger than 2x2?

This calculator focuses on the clean, fully worked 2x2 case for teaching purposes. Larger matrices follow the same Gram-Schmidt logic extended to additional columns, but require more computation steps.