Skip to content

Normal Equations

When AA is not square, we cannot solve Ax=bAx = b directly. The normal equations transform the overdetermined system into a square one by multiplying both sides by ATA^T. This produces an n×nn \times n system that always has a unique solution when AA has full column rank.


Derivation

Start with the overdetermined system:

Am×n xn×1=bm×1A_{m \times n}\, x_{n \times 1} = b_{m \times 1}

Multiply both sides on the left by ATA^T (an n×mn \times m matrix):

ATA x=ATbA^T A\, x = A^T b

Examining the dimensions:

AT⏟n×mA⏟m×nx⏟n×1=AT⏟n×mb⏟m×1\underbrace{A^T}_{n \times m} \underbrace{A}_{m \times n} \underbrace{x}_{n \times 1} = \underbrace{A^T}_{n \times m} \underbrace{b}_{m \times 1}

The product ATAA^T A is an n×nn \times n square matrix. This is the system we solve to find the least squares solution.


Worked Example 1: Polynomial Fitting

Problem: Given the data f(−3)=0f(-3) = 0, f(0)=0f(0) = 0, f(6)=2f(6) = 2, find the least squares polynomial P1(x)=a0+a1xP_1(x) = a_0 + a_1 x of degree 1 that best fits these three points.

Step 1 — Set up the overdetermined system

Substituting each data point into P1(x)=a0+a1xP_1(x) = a_0 + a_1 x:

P1(−3)=a0−3a1=0P_1(-3) = a_0 - 3a_1 = 0 P1(0)=a0+0⋅a1=0P_1(0) = a_0 + 0 \cdot a_1 = 0 P1(6)=a0+6a1=2P_1(6) = a_0 + 6a_1 = 2

In matrix form Ax=bAx = b:

A=[1−31016],x=[a0a1],b=[002]A = \begin{bmatrix} 1 & -3 \\ 1 & 0 \\ 1 & 6 \end{bmatrix}, \qquad x = \begin{bmatrix} a_0 \\ a_1 \end{bmatrix}, \qquad b = \begin{bmatrix} 0 \\ 0 \\ 2 \end{bmatrix}

Three equations, two unknowns. This is overdetermined — no exact solution exists in general.

Step 2 — Form the normal equations ATAx=ATbA^T A x = A^T b

[111−306][1−31016][a0a1]=[111−306][002]\begin{bmatrix} 1 & 1 & 1 \\ -3 & 0 & 6 \end{bmatrix} \begin{bmatrix} 1 & -3 \\ 1 & 0 \\ 1 & 6 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \end{bmatrix} = \begin{bmatrix} 1 & 1 & 1 \\ -3 & 0 & 6 \end{bmatrix} \begin{bmatrix} 0 \\ 0 \\ 2 \end{bmatrix}

Compute ATAA^T A:

ATA=[1+1+1−3+0+6−3+0+69+0+36]=[33345]A^T A = \begin{bmatrix} 1+1+1 & -3+0+6 \\ -3+0+6 & 9+0+36 \end{bmatrix} = \begin{bmatrix} 3 & 3 \\ 3 & 45 \end{bmatrix}

Compute ATbA^T b:

ATb=[0+0+20+0+12]=[212]A^T b = \begin{bmatrix} 0+0+2 \\ 0+0+12 \end{bmatrix} = \begin{bmatrix} 2 \\ 12 \end{bmatrix}

The normal equations become:

[33345][a0a1]=[212]\begin{bmatrix} 3 & 3 \\ 3 & 45 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \end{bmatrix} = \begin{bmatrix} 2 \\ 12 \end{bmatrix}

Step 3 — Solve by inverse matrix

[a0a1]=[33345]−1[212]\begin{bmatrix} a_0 \\ a_1 \end{bmatrix} = \begin{bmatrix} 3 & 3 \\ 3 & 45 \end{bmatrix}^{-1} \begin{bmatrix} 2 \\ 12 \end{bmatrix}

The determinant is det⁡=3×45−3×3=135−9=126\det = 3 \times 45 - 3 \times 3 = 135 - 9 = 126. The inverse is:

[33345]−1=1126[45−3−33]\begin{bmatrix} 3 & 3 \\ 3 & 45 \end{bmatrix}^{-1} = \frac{1}{126} \begin{bmatrix} 45 & -3 \\ -3 & 3 \end{bmatrix}

Therefore:

[a0a1]=1126[45−3−33][212]=1126[90−36−6+36]=1126[5430]\begin{bmatrix} a_0 \\ a_1 \end{bmatrix} = \frac{1}{126} \begin{bmatrix} 45 & -3 \\ -3 & 3 \end{bmatrix} \begin{bmatrix} 2 \\ 12 \end{bmatrix} = \frac{1}{126} \begin{bmatrix} 90 - 36 \\ -6 + 36 \end{bmatrix} = \frac{1}{126} \begin{bmatrix} 54 \\ 30 \end{bmatrix}

Step 4 — Solution

a0=54126=37,a1=30126=521\boxed{a_0 = \frac{54}{126} = \frac{3}{7}, \qquad a_1 = \frac{30}{126} = \frac{5}{21}}

The best-fit line is:

P1(x)=37+521 xP_1(x) = \frac{3}{7} + \frac{5}{21}\,x

Worked Example 2: Four-Equation System

Problem: The following overdetermined system has 4 equations and 3 unknowns. Find the least squares solution.

a0+2a1+4a2=3a_0 + 2a_1 + 4a_2 = 3

a0+3a1+9a2=5a_0 + 3a_1 + 9a_2 = 5

a0+5a1+25a2=12a_0 + 5a_1 + 25a_2 = 12

a0+6a1+36a2=15a_0 + 6a_1 + 36a_2 = 15

Step 1 — Identify the coefficient matrix and right-hand side

A=[12413915251636],b=[351215]A = \begin{bmatrix} 1 & 2 & 4 \\ 1 & 3 & 9 \\ 1 & 5 & 25 \\ 1 & 6 & 36 \end{bmatrix}, \qquad b = \begin{bmatrix} 3 \\ 5 \\ 12 \\ 15 \end{bmatrix}

AA is 4×34 \times 3. We cannot solve directly — apply the normal equations.

Step 2 — Form ATAA^T A and ATbA^T b

ATA=[11112356492536][12413915251636]A^T A = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 3 & 5 & 6 \\ 4 & 9 & 25 & 36 \end{bmatrix} \begin{bmatrix} 1 & 2 & 4 \\ 1 & 3 & 9 \\ 1 & 5 & 25 \\ 1 & 6 & 36 \end{bmatrix}

The 3×43 \times 4 matrix multiplied by the 4×34 \times 3 matrix yields a 3×33 \times 3 matrix:

ATA=[416741674376743762018]A^T A = \begin{bmatrix} 4 & 16 & 74 \\ 16 & 74 & 376 \\ 74 & 376 & 2018 \end{bmatrix} ATb=[11112356492536][351215]=[35171879]A^T b = \begin{bmatrix} 1 & 1 & 1 & 1 \\ 2 & 3 & 5 & 6 \\ 4 & 9 & 25 & 36 \end{bmatrix} \begin{bmatrix} 3 \\ 5 \\ 12 \\ 15 \end{bmatrix} = \begin{bmatrix} 35 \\ 171 \\ 879 \end{bmatrix}

The normal equations:

[416741674376743762018][a0a1a2]=[35171879]\begin{bmatrix} 4 & 16 & 74 \\ 16 & 74 & 376 \\ 74 & 376 & 2018 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \\ a_2 \end{bmatrix} = \begin{bmatrix} 35 \\ 171 \\ 879 \end{bmatrix}

Step 3 — Apply Gaussian elimination

Write the augmented matrix:

[41674351674376171743762018879]\left[\begin{array}{ccc|c} 4 & 16 & 74 & 35 \\ 16 & 74 & 376 & 171 \\ 74 & 376 & 2018 & 879 \end{array}\right]

Apply R2←R2−164 R1R_2 \leftarrow R_2 - \dfrac{16}{4}\,R_1 and R3←R3−744 R1R_3 \leftarrow R_3 - \dfrac{74}{4}\,R_1:

[41674350108031080649231.5]\left[\begin{array}{ccc|c} 4 & 16 & 74 & 35 \\ 0 & 10 & 80 & 31 \\ 0 & 80 & 649 & 231.5 \end{array}\right]

Apply R3←R3−8010 R2R_3 \leftarrow R_3 - \dfrac{80}{10}\,R_2:

[41674350108031009−16.5]\left[\begin{array}{ccc|c} 4 & 16 & 74 & 35 \\ 0 & 10 & 80 & 31 \\ 0 & 0 & 9 & -16.5 \end{array}\right]

Step 4 — Back substitution

From row 3:

9a2=−16.5  ⟹  a2=−16.59≈−1.8339a_2 = -16.5 \implies a_2 = -\frac{16.5}{9} \approx -1.833

From row 2:

10a1+80a2=3110a1=31−80(−1.833)=31+146.67=177.67a1≈17.767\begin{aligned} 10a_1 + 80a_2 & = 31 \\ 10a_1 & = 31 - 80(-1.833) \\ & = 31 + 146.67 \\ & = 177.67 \\ a_1 & \approx 17.767 \end{aligned}

From row 1:

4a0+16a1+74a2=354a0=35−16(17.767)−74(−1.833)=35−284.27+135.67=−113.6a0≈−28.4\begin{aligned} 4a_0 + 16a_1 + 74a_2 & = 35 \\ 4a_0 & = 35 - 16(17.767) - 74(-1.833) \\ & = 35 - 284.27 + 135.67 \\ & = -113.6 \\ a_0 & \approx -28.4 \end{aligned} a0≈−28.4a_0 \approx -28.4

Step 5 — Solution

a0≈−28.4,a1≈17.77,a2≈−1.83\boxed{a_0 \approx -28.4, \qquad a_1 \approx 17.77, \qquad a_2 \approx -1.83}