Write the normal equations for a data-fitting least-squares problem
Build A transpose A for a line fit from m and the sums of t and t squared. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.
You have the design matrix and the height vector. The normal equations are
For a line fit, has two columns — the ones and the times — so you never need to write the matrix out. Just take the four dot products:
So the system is
Read it as two facts:
- - * is made of dot products of columns with columns**, so it is symmetric — the off-diagonal entries are the same number twice.
- - * is made of dot products of columns with the heights**, so its first entry is a plain sum (because the first column is all ones) and its second weights every height by its own time.
Five numbers plus the count, and the setup is complete. Then — and only then — solve.
Because has only two columns, and every entry of is one dot product of two columns.
Write the columns out: column 1 is and column 2 is. Then:
- - entry is;
- - entry is;
- - entry is, the same sum, which is why the matrix is symmetric;
- - entry is.
And for the right-hand side:
- - entry 1 is;
- - entry 2 is.
Nothing else can appear, because there are only two columns. This is the concrete form of the general rule "each entry of is a dot product of two columns of" — and it is why a parabola fit gives a system: three columns, so nine dot products, and the powers climb to.
When the system is diagonal. If the two columns are orthogonal, is diagonal, and and decouple: and separately. Shifting the times to have mean zero is therefore not a trick but a way of removing the coupling.
Fit to,,.
Step 1, the five numbers.;;;;.
Step 2, assemble.
Step 3, the cheap checks. Top-left is ✓. The matrix is symmetric ✓. The right-hand side has one plain sum and one weighted sum ✓.
Step 4, solve (only because the fit is asked for here)., so
The best line is.
Step 5, the check that proves it. and. Then
Notice that here — the best line passes through the origin. That happens with these numbers rather than by design, and it is worth not "correcting" it: the data asked for it.
- Build A transpose A for a line fit from m and the sums of t and t squared
- Build A transpose b from the sum of y and the sum of t y
- Check the result: the top-left entry is m, the matrix is symmetric, and the right-hand side has one plain and one weighted sum
- Say when the two equations decouple and why that happens
Points,,.
- 1. Write the normal equations.
- 2. What is the top-left entry, and why must it be that?
- 3. Without solving, is diagonal here? How do you know at a glance?
Answers
1.,,,,: 2., the number of data points. It is, and the ones column has one entry per row. 3. No — the off-diagonal is. A diagonal needs, which cannot happen with three positive times.