Euler Hall — free maths guides

Set up the columns 1, t and t squared for a parabola fit

Give the design matrix for y = C + D t + E t squared, one row per point and columns 1, t, t squared. 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

A line has two coefficients, so its design matrix has two columns. A parabola has three —CC,DD andEE — so its design matrix has three.

The construction is exactly the same, one row per point: C+D ti+E ti2=yi.C+D\,t_i+E\,t_i^{2}=y_i.

Reading off the coefficients of each unknown, in the order(C,D,E)(C,D,E):

The three columns are the three fixed functions oftt: the constant11, the timett, and the squaret2t^{2}. They are not the data points, and the rows are not the coefficients — the roles are worth saying out loud, because reversing them is the error that survives every shape check.

Why a curve is still a linear problem. The unknownsC,D,EC,D,E each appear to the first power. Squaringtt does not make the problem nonlinear, becausett is data, not an unknown —ti2t_i^{2} is a number you already have, exactly astit_i is.

Why the third column ist2t^{2} and not something else

The row ofAA must reproduce one equation. Rowii dotted with(C,D,E)(C,D,E) givesAi1C+Ai2D+Ai3EA_{i1}C+A_{i2}D+A_{i3}E. For this to equal the model at timetit_i — which isC+Dti+Eti2C+Dt_i+Et_i^{2} — we needAi1=1A_{i1}=1,Ai2=tiA_{i2}=t_i andAi3=ti2A_{i3}=t_i^{2}. Each entry is the coefficient of that unknown at that data point, and nothing else would do.

This is a general recipe, not a fact about parabolas. Fory=C+Dt+Et2+Ft3y=C+Dt+Et^{2}+Ft^{3} the fourth column isti3t_i^{3}. Fory=C+Dcos⁡ty=C+D\cos t the second column iscos⁡ti\cos t_i. For a model with two separate predictors, the columns are those two measurements. The rule is always: columnjj holds the values of the function multiplying unknownjj, evaluated at every data point.

Why the columns are independent when the times are distinct. Supposeα+βt+γt2\alpha+\beta t+\gamma t^{2} is zero at every data point. A nonzero quadratic has at most two roots, so three distinct times forceα=β=γ=0\alpha=\beta=\gamma=0.

Worked example, the exam's shape

Fity=C+Dt+Et2y=C+Dt+Et^{2} to(0,2)(0,2),(1,3)(1,3),(2,6)(2,6),(3,11)(3,11). Set up only.

Step 1, one equation per point. C+E⋅0=2,C+D+E=3,C+2D+4E=6,C+3D+9E=11.C+E\cdot0=2,\quad C+D+E=3,\quad C+2D+4E=6,\quad C+3D+9E=11.

Step 2, read the coefficients.

| point | forCC | forDD | forEE | height | |---|---|---|---|---| |(0,2)(0,2) |11 |00 |00 |22 | |(1,3)(1,3) |11 |11 |11 |33 | |(2,6)(2,6) |11 |22 |44 |66 | |(3,11)(3,11) |11 |33 |99 |1111 |

Step 3, stack. A=[100111124139],b=[23611].A=\begin{bmatrix}1&0&0\\1&1&1\\1&2&4\\1&3&9\end{bmatrix},\qquad \mathbf b=\begin{bmatrix}2\\3\\6\\11\end{bmatrix}.

Step 4, the normal equations, since a full setup usually asks for them too: ATA=[461461436143698],ATb=[2248126].A^{T}A=\begin{bmatrix}4&6&14\\6&14&36\\14&36&98\end{bmatrix},\qquad A^{T}\mathbf b=\begin{bmatrix}22\\48\\126\end{bmatrix}.

Check the pattern: top-left4=m4=m ✓; the(1,2)(1,2) entry is∑t=0+1+2+3=6\sum t=0+1+2+3=6 ✓; the(2,2)(2,2) entry is∑t2=0+1+4+9=14\sum t^{2}=0+1+4+9=14 ✓; the(1,3)(1,3) entry is∑t2\sum t^{2} again, which is why it equals the(2,2)(2,2) entry — a real symmetry to spot rather than a coincidence. The right-hand side is(∑yi, ∑tiyi, ∑ti2yi)\left(\sum y_i,\ \sum t_iy_i,\ \sum t_i^{2}y_i\right). All four sums are verified in the SymPy check below.

Step 5, the check. This data does lie on an exact parabola: it isy=t2+2y=t^{2}+2. So the fit is exact, the residual is zero, and(C,D,E)=(2,0,1)(C,D,E)=(2,0,1) must reproduceATbA^{T}\mathbf b row by row: 4⋅2+6⋅0+14⋅1=22 ✓,6⋅2+14⋅0+36⋅1=48,14⋅2+36⋅0+98⋅1=126.4\cdot2+6\cdot0+14\cdot1=22\ ✓,\qquad 6\cdot2+14\cdot0+36\cdot1=48,\qquad 14\cdot2+36\cdot0+98\cdot1=126.

That is worth keeping rather than tidying away: my first draft of this example hadATb=(22,64,206)A^{T}\mathbf b=(22,64,206), and the substitution check is what caught it.6464 and206206 are not∑tiyi\sum t_iy_i and∑ti2yi\sum t_i^{2}y_i; the true values are0+3+12+33=480+3+12+33=48 and0+3+24+99=1260+3+24+99=126. Multiplying a correctATAA^{T}A by the answer you expect and comparing withATbA^{T}\mathbf b is a two-line check that finds exactly this class of error, and it is the check to run on an exam before you hand the sheet in.

By the end you can
  • Give the design matrix for y = C + D t + E t squared, one row per point and columns 1, t, t squared
  • Count the columns from the number of coefficients, not the number of data points
  • Write A transpose A as a three by three matrix of power sums
  • State how many distinct times a unique parabola fit requires and why
Test yourself without looking back

Points(1,2)(1,2),(2,9)(2,9),(3,20)(3,20), modely=C+Dt+Et2y=C+Dt+Et^{2}.

  1. 1. WriteAA andb\mathbf b.
  2. 2. What isATAA^{T}A?
  3. 3. Do these three points lie exactly on a parabola? How can you tell fromAA alone?
Answers
  1. 1.A=[111124139]A=\begin{bmatrix}1&1&1\\1&2&4\\1&3&9\end{bmatrix} andb=[2920]\mathbf b=\begin{bmatrix}2\\9\\20\end{bmatrix}.
  2. 2.[361461436143698]\begin{bmatrix}3&6&14\\6&14&36\\14&36&98\end{bmatrix}: the sums are over1,2,31,2,3, so∑t=6\sum t=6,∑t2=14\sum t^{2}=14,∑t3=36\sum t^{3}=36 and∑t4=98\sum t^{4}=98.
  3. 3. Yes —AA is square 3×33\times3) with three distinct times, so it is invertible andAx^=bA\hat{x}=\mathbf b has an exact solution. (It isy=t2+1y=t^{2}+1.) A square design matrix means the "fit" is an interpolation: no error is being minimised because none is needed.
Work out where to start — free, no accountAnswer six real questions — free, no account