Linear Algebra
Chapter 5/Orthogonality

5.3Least Squares Problems

Overdetermined systems are usually inconsistent, and 'no solution' is a useless answer for real data. Least squares asks the next best question: which makes as close to as possible?

What you must be able to do

  • Minimise . The minimiser makes the residual orthogonal to .
  • Normal equations: — always consistent, and exact-arithmetic friendly.
  • is nonsingular (full column rank), giving the unique .
  • Projection with ; is symmetric and . is always unique even when isn't.
Definition · Least squares solution
For of size () and , a least squares solution minimises the residual in the sense that is as small as possible.

Geometrically: ranges over the column space as varies, so we're asking for the point of closest to — the orthogonal projection . The minimising residual is perpendicular to , i.e. lies in :

Theorem 5.3.2
The normal equations are always consistent, and every solution is a least squares solution. If then is nonsingular and is the unique least squares solution.

If there are infinitely many , but they all give the same projection .

Fitting data by least squares

  1. 1
    Write the model with unknown coefficients

    Line: . Quadratic: . The unknowns are the , and the model must be linear in the coefficients is not, directly.

  2. 2
    Build by plugging each data point into the model

    Row holds the values that multiply each coefficient at ; holds the observed .

  3. 3
    Form and , then solve

    is small () and symmetric; solve by elimination.

  4. 4
    Check the residual is orthogonal to the columns of

    For a fit with a constant term, the first column of is all ones, so the residuals must sum to zero. That's a fast free check.

Curve fitting is always the same three moves: build from the model, solve the normal equations, interpret the coefficients.
Worked example

Best-fit line through three points

0/4 steps
Find the least squares line through , , .
!Exam trap
is not unique when , but the projection always is. If a question asks for the closest point in , the answer is unique regardless; if it asks for the coefficients, uniqueness needs full column rank.
Check your work

Least squares via the normal equations

Enter the augmented matrix (A | b) — one row per equation, last column is b. Everything stays exact because AᵀA and Aᵀb are rational.

A =
11
-23
2-1
b =
3
1
2
Normal equations AᵀA x̂ = Aᵀb
9-7
-711
x̂ =
5
4
x̂ =
83/50
71/50
p = Ax̂ =
77/25
47/50
19/10
‖r‖ ≈ 0.1414

If the last column of A is a column of x-powers, these are the coefficients of the best-fit polynomial, in the order the columns appear.

Check yourself

Q1
The least squares solution of an overdetermined system is found by solving:
T / F
If is with , the least squares solution is unique and equals .
T / F
The projection matrix satisfies .