Least Squares
Solutions
Learn how to find the best approximate solution when a system \( A\mathbf{x} = \mathbf{b} \) has no exact solution: the foundation of data fitting and regression.
What Is an Overdetermined System?
An overdetermined system \( A\mathbf{x} = \mathbf{b} \) has more equations than unknowns: the matrix \( A \) is \( m \times n \) with \( m > n \). Typically, no vector \( \mathbf{x} \) satisfies every equation simultaneously.
The Geometric Picture
Why Least Squares Matters
Whenever real-world data doesn't perfectly fit a model, least squares gives us the best fit. It underpins statistics, engineering, machine learning, and every line-of-best-fit you've ever drawn.
The Normal Equation
This equation comes directly from the condition that the residual \( \mathbf{b} - A\hat{\mathbf{x}} \) must be orthogonal to every column of \( A \): that is, \( A^T(\mathbf{b} - A\hat{\mathbf{x}}) = \mathbf{0} \).
Deriving the Normal Equation
Exact vs. Least Squares
| Exact Solution | Least Squares Solution | |
|---|---|---|
| System | \( A\mathbf{x} = \mathbf{b} \) | \( A^T A \, \hat{\mathbf{x}} = A^T \mathbf{b} \) |
| When it exists | \( \mathbf{b} \in \text{Col}(A) \) | Always (for any \( \mathbf{b} \)) |
| Residual | \( \mathbf{0} \) | Minimized \( \| \mathbf{b} - A\hat{\mathbf{x}} \| \) |
| Uniqueness | Depends on \( \text{null}(A) \) | Unique when cols of \( A \) are independent |
How to Solve a Least Squares Problem
Worked Example: Simple System
Find the least squares solution of \( A\mathbf{x} = \mathbf{b} \) where:
Step 1: Compute \( A^T A \):
Example 1: Completing the Solve
Step 2: Compute \( A^T \mathbf{b} \):
Step 3: Solve \( A^T A \, \hat{\mathbf{x}} = A^T \mathbf{b} \):
Visualizing the Best Fit Line
Example 2: Larger System
Find the least squares solution of:
The Projection Matrix
The matrix that projects any vector onto \( \text{Col}(A) \) is:
The Residual Vector
Common Mistakes
Summary of Key Formulas
| Concept | Formula | Meaning |
|---|---|---|
| Normal equation | \( A^T A\,\hat{\mathbf{x}} = A^T\mathbf{b} \) | Defines \( \hat{\mathbf{x}} \) |
| Explicit solution | \( \hat{\mathbf{x}} = (A^T A)^{-1}A^T\mathbf{b} \) | When cols independent |
| Projection | \( \hat{\mathbf{b}} = A\hat{\mathbf{x}} \) | Closest point in Col(\(A\)) |
| Residual | \( \mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}} \) | \( \mathbf{r} \perp \text{Col}(A) \) |
| Projection matrix | \( P = A(A^T A)^{-1}A^T \) | \( P^2 = P \), \( P^T = P \) |
Question 1 of 5
The least squares solution \( \hat{\mathbf{x}} \) of \( A\mathbf{x} = \mathbf{b} \) satisfies which equation?
Question 2 of 5
If \( A \) is a \( 5 \times 3 \) matrix, what is the size of \( A^T A \)?
Question 3 of 5
The residual vector \( \mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}} \) is orthogonal to which subspace?
Question 4 of 5
Given \( A = \begin{bmatrix} 1 \\ 2 \end{bmatrix} \) and \( \mathbf{b} = \begin{bmatrix} 3 \\ 1 \end{bmatrix} \), what is \( \hat{x} \)?
Question 5 of 5
Which property does the projection matrix \( P = A(A^T A)^{-1}A^T \) always satisfy?