Euler Hall — free maths guides

Form the normal equation A transpose A x = A transpose b

Multiply both sides of Ax=b by A transpose and state the resulting square system. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.

Plain words first

Ax=bAx=b with a tallAA usually has no solution: more equations than unknowns, and the columns cannot reachbb.

You cannot fix that by row-reducing, because there is nothing to solve. What you can do is change the question slightly: instead of asking whichxx makesAxAx equalbb, ask whichxx makesAxAx as close tobb as possible.

The answer arrives from one move: multiply both sides ofAx=bAx=b byATA^{T}.

ATA x^=ATb.A^{T}A\,\hat{x}=A^{T}b.

These are the normal equations, and the only thing to be careful about is thatATA^{T} must multiply both sides.

Why the shapes work. IfAA ism×km\times k thenATA^{T} isk×mk\times m, so:

| object | shape | meaning | |---|---|---| |AA |m×km\times k | one row per equation | |ATAA^{T}A |k×kk\times k | square, one row per unknown | |ATbA^{T}b |k×1k\times1 | one right-hand entry per unknown |

Thatk×kk\times k is the whole point. The unsolvablem×km\times k system became a squarek×kk\times k system with the same number of equations as unknowns — and if the columns ofAA are independent,ATAA^{T}A is invertible and there is exactly one answer.

Why multiplying by the transpose is the right move

Two derivations give the same equations, and both are worth knowing because the exam asks you to justify the setup.

Geometric. The bestAx^A\hat{x} is the projection ofbb onto the column space ofAA. The projection is the nearest point, so the errore=b−Ax^e=b-A\hat{x} is perpendicular to every column ofAA. Stack those perpendicularity conditions as rows: AT(b−Ax^)=0.A^{T}(b-A\hat{x})=0. Expand and rearrange: ATb=ATAx^.A^{T}b=A^{T}A\hat{x}.

Calculus. Minimise the squared errorE=∥Ax−b∥2E=\|A x-b\|^{2}. Differentiating with respect to each unknown and setting the gradient to zero gives2AT(Ax−b)=02A^{T}(Ax-b)=0, which is the same equation.

The two agree because they are the same statement. "The error is perpendicular to the column space" and "the gradient of the squared error vanishes" both say: no small change inxx can reduce the error. One says it with a right angle, the other with a derivative.

WhyATAA^{T}A is invertible when the columns are independent. IfATAx=0A^{T}Ax=0 thenxTATAx=0x^{T}A^{T}Ax=0, which is∥Ax∥2=0\|Ax\|^{2}=0, soAx=0Ax=0, sox=0x=0 by independence. A square matrix whose only null vector is00 is invertible. This is why the normal equations have exactly one solution — and why dependent columns make the answer non-unique rather than wrong.

Worked example, with the shapes checked at every step

A=[11121314]A=\begin{bmatrix}1&1\\1&2\\1&3\\1&4\end{bmatrix} andb=[1224]b=\begin{bmatrix}1\\2\\2\\4\end{bmatrix}.

Step 1, transpose.AT=[11111234]A^{T}=\begin{bmatrix}1&1&1&1\\1&2&3&4\end{bmatrix} is2×42\times4.

Step 2, left side. ATA=[4101030].A^{T}A=\begin{bmatrix}4&10\\10&30\end{bmatrix}. Check:44 is the number of rows ofAA (the ones dot themselves),10=1+2+3+410=1+2+3+4, and30=1+4+9+1630=1+4+9+16. Shape2×22\times2 ✓.

Step 3, right side. ATb=[1+2+2+41+4+6+16]=[927].A^{T}b=\begin{bmatrix}1+2+2+4\\1+4+6+16\end{bmatrix}=\begin{bmatrix}9\\27\end{bmatrix}. Shape2×12\times1 ✓.

Step 4, the system. [4101030][CD]=[927].\begin{bmatrix}4&10\\10&30\end{bmatrix}\begin{bmatrix}C\\D\end{bmatrix}=\begin{bmatrix}9\\27\end{bmatrix}.

Solve it: the determinant is120−100=20120-100=20, so C=9⋅30−10⋅2720=270−27020=0,D=4⋅27−10⋅920=108−9020=910.C=\frac{9\cdot30-10\cdot27}{20}=\frac{270-270}{20}=0,\qquad D=\frac{4\cdot27-10\cdot9}{20}=\frac{108-90}{20}=\frac{9}{10}.

So the best line isy=910ty=\frac{9}{10}t. Sanity: the points(1,1),(2,2),(3,2),(4,4)(1,1),(2,2),(3,2),(4,4) average around2.252.25 at an average time of2.52.5, and910⋅2.5=2.25\frac{9}{10}\cdot2.5=2.25 ✓ — the line passes through the centroid, which a least-squares line always does.

Step 5, the check that settles it.Ax^=(910,1810,2710,3610)A\hat{x}=\left(\frac{9}{10},\frac{18}{10},\frac{27}{10},\frac{36}{10}\right) ande=b−Ax^=(110,210,−710,410)e=b-A\hat{x}=\left(\frac{1}{10},\frac{2}{10},-\frac{7}{10},\frac{4}{10}\right). Then ATe=[1+2−7+4101+4−21+1610]=[00] ✓.\def\arraystretch{1.6}A^{T}e=\begin{bmatrix}\frac{1+2-7+4}{10}\\\frac{1+4-21+16}{10}\end{bmatrix}=\begin{bmatrix}0\\0\end{bmatrix}\ ✓. The errors sum to zero, which isATe=0A^{T}e=0 read on the first row.

By the end you can
  • Multiply both sides of Ax=b by A transpose and state the resulting square system
  • Check the shapes: A transpose A is square in the unknowns, A transpose b has one entry per unknown
  • Say what the normal equations mean geometrically: the residual is perpendicular to every column
  • Decide when A transpose A is invertible and what happens when it is not
Test yourself without looking back

A=[12101210]A=\begin{bmatrix}1&2\\1&0\\1&2\\1&0\end{bmatrix}.

  1. 1. What isATAA^{T}A?
  2. 2. Is it invertible?
  3. 3. What does your answer to (2) mean for the fit?
Answers
  1. 1.ATA=[4448]A^{T}A=\begin{bmatrix}4&4\\4&8\end{bmatrix}: the ones give44, the times give2+0+2+0=42+0+2+0=4 twice, and the squares give4+0+4+0=84+0+4+0=8.
  2. 2.det⁡=32−16=16≠0\det=32-16=16\neq0, so yes. (The columns are(1,1,1,1)(1,1,1,1) and(2,0,2,0)(2,0,2,0), and the second is not a multiple of the first.)
  3. 3. The least-squares coefficients are unique. But note that the data are not: times22 and00 each appear twice, so four points sit on only two distinct times. Uniqueness of the coefficients needs independent columns, not distinct data — and here they happen to be independent even though the times repeat.
Work out where to start — free, no accountAnswer six real questions — free, no account