Set up A and b for a straight-line fit
Write one equation C+D ti = yi per data point and read A and b off them. The idea in plain words, a worked example, and a check with the answers shown — part of the free Linear Algebra guides.
You have points and you want the line that passes as close as possible to all of them.
Start from what "the point is on the line" would mean. For point it would mean
That is one equation per point, in the two unknowns and. Gather the equations:
Now read them as a matrix. The unknowns are ordered, so column 1 holds the coefficients of and column 2 holds the coefficients of. The coefficient of is in every equation. The coefficient of is that point's time:
Two things to notice, because they are the two marks on a "set up" question:
- - One row per point. The number of rows is the number of data points, never the number of unknowns.
- - One column per coefficient. A line has two, so has two columns whatever the number of points.
And holds the observed heights, in the same order as the rows. Reordering while leaving alone is invisible in every shape check and wrong in every answer.
Each row of is one dot product, and that dot product must reproduce one equation.
Row of dotted with gives. For this to equal — which is what the data point demands — we need. Matching coefficients: and.
So the row is forced. There is no choice to make once the model and the unknown order are fixed. That is why "set up" is a markable question: it has exactly one right answer, and it can be checked by substituting any data point back in.
Why the number of columns is what it is. Every coefficient in the model needs a multiplier, and each multiplier is a number you already know or). Unknowns become columns; known functions of the data become entries. A model linear in its coefficients works the same way even when it is not linear in: for the entries are known, so simply has three columns.
Fit to,,, and set up only.
Step 1, write the equations, one per point, unknowns in the order:
Step 2, read off the coefficient of each unknown.
| point | coefficient of | coefficient of | height | |---|---|---|---| | | | | | | | | | | | | | | |
Step 3, stack.
Step 4, the checks that cost nothing.
- - is: three points, two coefficients ✓.
- - Row 2 dotted with gives, which is the second equation ✓.
- -'s second entry is, and the second point is ✓.
Step 5, what comes next. The normal equations would be. Unless the fit is asked for, stop here: solving a correct setup earns nothing extra, and solving a wrong one earns nothing at all.
- Write one equation C+D t_i = y_i per data point and read A and b off them
- State the rule: one row per point, one column per coefficient, heights in the same order
- Reproduce a data point by dotting the matching row of A with the unknown vector
- Recognise that swapping the columns of A requires swapping the order of the unknowns
Points,,. Model.
- 1. Write and.
- 2. What is row 3 of dotted with, and does it match the third point?
- 3. What would be for the model — no intercept?
Answers
- 1. and.
- 2., which is the equation for the point ✓.
- 3. and is unchanged — one column, because there is one unknown. The fit is then forced through the origin, which is a different model and generally gives a different slope.