Skip to content
Glacius
Linear algebraConcept reference

QR factorization

A reduced QR factorization expresses a real matrix with independent columns as an orthonormal-column matrix times an invertible upper-triangular matrix.

On this page 8 sections
  1. Overview
  2. Understand the idea
  3. In Rx=Q^Tb, the right side is known but x is still unknown
  4. For A with m rows and n independent columns, Qᵀ takes b to n pattern coordinates
  5. A closer look
  6. Key takeaway
  7. Sources & further reading
  8. Concept connections

01Understand the idea#

QR factorization rewrites a matrix using perpendicular unit patterns in QQ and a triangular mixing rule in RR. It helps solve least-squares problems by separating “find the target’s pattern coordinates” from “recover the original feature weights.”

You already know dot products, orthonormal columns, and back substitution. QR connects them: use dot products with QQ to find desired pattern coordinates, then solve the upper-triangular system involving RR. The supplied factors save you from constructing an orthonormal basis in this lesson.

A reduced QR factorization writes A=QR. For a matrix with independent columns, Q has orthonormal columns and R is square, upper triangular, with nonzero diagonal entries. The factors are supplied here; use them to fit a target b.

Let Q have columns (1,0,0) and (0,1,0), with target b=(5,3,2). Dot each column with b. The orthonormal-pattern coordinates are 5 and 3.

QTb=(5,3)TQ^Tb=(5,3)^T

Q’s columns span the attainable outputs. Their dot products with b are the coordinates of its projection. Since Ax=Q(Rx), the input must satisfy this triangular system:

Rx=QTbRx=Q^Tb
Check your reasoning

Reduced QR: Q=(0,1,0)TQ=(0,1,0)^T, R=[2]R=[2], b=(4,6,1)b=(4,6,1). Find the scalar xx.

Show answer and explanation
3

QTb=6Q^Tb=6; 2x=62x=6.

02In Rx=Q^Tb, the right side is known but x is still unknown#

In Rx=QTbRx=Q^Tb, the right side is known but xx is still unknown. For rows of RR equal to (2,1)(2,1) and (0,3)(0,3) and right side (5,3)(5,3), the bottom row gives 3x2=33x_2=3. Set x2=1x_2=1, substitute it into 2x1+x2=52x_1+x_2=5, and solve x1=2x_1=2. Pattern coordinates (5,3)(5,3) and feature weights (2,1)(2,1) differ.

Suppose Qᵀb=(5,3) and R has rows (2,1), (0,3). Solve from the bottom: 3x₂=3 gives x₂=1. Then 2x₁+1=5 gives x₁=2.

x=(2,1)Tx=(2,1)^T
Check your reasoning

QTb=(4,6)Q^Tb=(4,6), R=[1103]R=\begin{bmatrix}1&1\\0&3\end{bmatrix}. Claim: x=QTbx=Q^Tb. Correct xx.

  1. A(4,2)(4,2)
  2. B(2,2)(2,2)
  3. C(4,6)(4,6)
Show answer and explanation
(2,2)(2,2)

x2=6/3=2x_2=6/3=2; x1=2x_1=2.

03For A with m rows and n independent columns, Qᵀ takes b to n pattern coordinates#

For A with m rows and n independent columns, Qᵀ takes b to n pattern coordinates. R mixes the input weights into those coordinates. Back substitution recovers the weights.

For A=QR with independent columns, target b has m entries. Multiplication by Qᵀ gives n orthonormal-pattern coordinates. Solving R x = Qᵀb gives n original input weights x; coordinates and weights need not be equal.For A=QR with independent columns, target b has m entries. Multiplication by Qᵀ gives n orthonormal-pattern coordinates. Solving R x = Qᵀb gives n original input weights x; coordinates and weights need not be equal.
Figure 1For A=QR with independent columns, target b has m entries. Multiplication by Qᵀ gives n orthonormal-pattern coordinates. Solving R x = Qᵀb gives n original input weights x; coordinates and weights need not be equal.
Link to this figure ↗Download SVGDownload PNG

Q can be rectangular, so no square inverse of Q is needed. Its transpose extracts coordinates. A least-squares input still may leave a nonzero residual: the chosen output is the closest one the matrix can produce.

Check your reasoning

Fit bb with A=QRA=QR. The pattern is Q=(0,1,0)TQ=(0,-1,0)^T, R=[3]R=[3], b=(4,6,2)b=(4,-6,2). Find input xx.

Show answer and explanation
2

QTb=6Q^Tb=6; divide by 3.

04A closer look#

In a regression fit with independent feature columns, QR lets software find coefficients without explicitly forming an inverse of ATAA^TA. A residual can remain because the target may have a component outside the columns’ span. A solvable triangular system does not imply an exact fit to every measurement.

Key takeaway

Compute Qᵀb, then solve the triangular system Rx=Qᵀb by back substitution. The result gives input weights for the closest attainable output.

  • Use supplied QR factors to find least-squares input weights.

Sources & further reading

  1. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “QR factorization.” Math behind ML. /learn/la-qr