The Least-Squares Solution of a Linear System (Without Collinearity)

Compute the least-squares solution of an overdetermined linear system using the normal equations, and apply it to fit a line through data points.

Step 1 of 119%

Tutorial

The Normal Equations

An overdetermined linear system is a system Ax=bA\mathbf{x}=\mathbf{b} with more equations than unknowns. In general, no vector x\mathbf{x} satisfies every equation exactly. Instead, we look for the vector x^\hat{\mathbf{x}} that makes AxA\mathbf{x} as close to b\mathbf{b} as possible. This vector is the least-squares solution -- it minimizes

Axb2.\|A\mathbf{x}-\mathbf{b}\|^2.

The least-squares solution satisfies the normal equations

AT ⁣Ax^=ATb.A^T\!A\,\hat{\mathbf{x}}=A^T\mathbf{b}.

When the columns of AA are linearly independent (the "no collinearity" condition), AT ⁣AA^T\!A is invertible. Solving for x^\hat{\mathbf{x}} gives

  x^=(AT ⁣A)1ATb.  \boxed{\;\hat{\mathbf{x}}=(A^T\!A)^{-1}A^T\mathbf{b}.\;}

To use this formula, we just need four steps: form AT ⁣AA^T\!A, form ATbA^T\mathbf{b}, invert the 2×22\times 2 (or larger) matrix AT ⁣AA^T\!A, and multiply.

navigate · Enter open · Esc close · ⌘K/Ctrl K toggle