87. QR Decomposition

Every 𝑚×𝑛 matrix 𝐴 with 𝑚𝑛 can be factored as:

𝐴=𝑄𝑅

where:

If 𝐴 is full column rank, the decomposition is unique up to signs on the diagonal of 𝑅.

For square 𝐴 (full rank), 𝑄 is a full orthogonal matrix and 𝑅 is square upper triangular.

87.1. Construction via Gram–Schmidt

The columns of 𝑄 are the result of applying Gram–Schmidt orthogonalization to the columns of 𝐴:

Explicitly, 𝑅𝑖𝑗=𝑞𝑖𝑇𝑎𝑗 for 𝑖𝑗 and 0 for 𝑖>𝑗.

Example
𝐴=[101101]

Apply Gram–Schmidt to columns:

  • 𝑞1=𝑎1𝑎1=12[110]
  • Project 𝑎2 off 𝑞1: 𝑎2(𝑞1𝑇𝑎2)𝑞1=[011]1212[110]=[12121]
  • 𝑞2= that, normalized: 16[112]
𝑄=[12161216026]𝑅=𝑄𝑇𝐴=[212032]

87.2. Why it matters

QR is the workhorse for least-squares problems:

Given 𝐴𝑥=𝑏 overdetermined (more equations than unknowns), the least-squares solution

𝑥̂=argmin𝑥𝐴𝑥𝑏2

solves the normal equations 𝐴𝑇𝐴𝑥=𝐴𝑇𝑏. Using 𝐴=𝑄𝑅:

𝑅𝑥=𝑄𝑇𝑏

Then back-substitute on the upper-triangular 𝑅 — much more numerically stable than forming 𝐴𝑇𝐴 directly.

Other uses:

87.3. Computation methods

87.4. See also