Type a command or search the notes. Tab cycles completions. Up and down recall history when blank. Escape dismisses, then leaves the prompt.
MATH
[1251]

Methods from Data fitting and polynomial interpolation

All methods from Data fitting and polynomial interpolation.

Fit a straight line by least squares

For real data (ti,yi)∈R2(t_i,y_i)\in\mathbb R^2, form

M=(t11t21⋮⋮tn1),Y=(y1y2⋮yn).M= \begin{pmatrix} t_1&1\\ t_2&1\\ \vdots&\vdots\\ t_n&1 \end{pmatrix}, \qquad Y= \begin{pmatrix} y_1\\y_2\\\vdots\\y_n \end{pmatrix}.

If at least two input values are distinct, the least-squares straight-line fit y=mt+cy=mt+c has the unique coefficient vector

(mc)=(MTM)−1MTY.\begin{pmatrix}m\\c\end{pmatrix} =(M^{\mathsf T}M)^{-1}M^{\mathsf T}Y.

For a candidate line y=mt+cy=mt+c, the vector of predicted values at the inputs is

M(mc).M\begin{pmatrix}m\\c\end{pmatrix}.

The columns of MM contain the sampled values of tt and 11, so multiplying them by mm and cc produces the line's predicted values. The line need not pass through every data point.

The fitted value vector M(mc)M\binom{m}{c} lies in the column space

col⁡(M)=span⁡{(t1⋮tn),(1⋮1)}.\operatorname{col}(M)=\operatorname{span}\left\{ \begin{pmatrix}t_1\\\vdots\\t_n\end{pmatrix}, \begin{pmatrix}1\\\vdots\\1\end{pmatrix} \right\}.

Least squares chooses mm and cc to minimise the sum of squared vertical errors

E(m,c)=∑i=1n(yi−mti−c)2=∥Y−M(mc)∥2,E(m,c)=\sum_{i=1}^n(y_i-mt_i-c)^2 =\left\|Y-M\begin{pmatrix}m\\c\end{pmatrix}\right\|^2,

where ∥⋅∥\|\cdot\| is the usual Euclidean norm on Rn\mathbb R^n. The problem is therefore to find the point of col⁡(M)\operatorname{col}(M) closest to YY; the formula in the statement is the coordinate calculation for that projection.

At a minimum, differentiating with respect to mm and cc gives

∑i=1nti(yi−mti−c)=0,∑i=1n(yi−mti−c)=0.\sum_{i=1}^n t_i(y_i-mt_i-c)=0, \qquad \sum_{i=1}^n(y_i-mt_i-c)=0.

These are exactly the two entries of

MT(Y−M(mc))=0,MTM(mc)=MTY.M^{\mathsf T}\left(Y-M\binom{m}{c}\right)=0, \qquad M^{\mathsf T}M\binom{m}{c}=M^{\mathsf T}Y.

Thus the residual

Y−M(mc)Y-M\binom{m}{c}

is perpendicular to both columns of MM, hence to their span. If x∗x_* solves the normal equations and xx is any other coefficient vector, this perpendicularity gives

∥Y−Mx∥2=∥Y−Mx∗∥2+∥M(x−x∗)∥2.\|Y-Mx\|^2=\|Y-Mx_*\|^2+\|M(x-x_*)\|^2.

So Mx∗Mx_* is the closest model vector to YY.

When two input values are distinct, ati+b=0at_i+b=0 for every ii forces a=b=0a=b=0, so the columns of MM are independent. Hence MTMM^{\mathsf T}M is invertible and the minimising coefficient vector is unique. Multiplying the normal equations by (MTM)−1(M^{\mathsf T}M)^{-1} gives the coefficient formula in the statement.

Interpolate in the standard polynomial basis

To find the coordinate vector of the interpolating polynomial in B=(1,t,…,tn−1)B=(1,t,\ldots,t^{n-1}):

  1. Form the Vandermonde matrix
A=(1t1t12⋯t1n−11t2t22⋯t2n−1⋮⋮⋮⋮1tntn2⋯tnn−1)A= \begin{pmatrix} 1&t_1&t_1^2&\cdots&t_1^{n-1}\\ 1&t_2&t_2^2&\cdots&t_2^{n-1}\\ \vdots&\vdots&\vdots&&\vdots\\ 1&t_n&t_n^2&\cdots&t_n^{n-1} \end{pmatrix}

and the data vector y=(y1,…,yn)Ty=(y_1,\ldots,y_n)^T. 2. Solve

Ax=y.Ax=y.
  1. Read the solution
x=(a0a1⋮an−1)=[f]Bx= \begin{pmatrix} a_0\\a_1\\\vdots\\a_{n-1} \end{pmatrix} =[f]_B

as the coordinates of the interpolating polynomial.

The iith row imposes the condition f(ti)=yif(t_i)=y_i. Because the inputs are distinct, these conditions determine exactly one coordinate vector.

Interpolate in the Lagrange basis

For data (tj,yj)(t_j,y_j), construct the Lagrange polynomials and set

f(t)=∑j=1nyjℓj(t).f(t)=\sum_{j=1}^n y_j\ell_j(t).

Then f(ti)=yif(t_i)=y_i for every ii, which gives the interpolating polynomial.

The data values are the coordinates in the Lagrange basis, while a0,…,an−1a_0,\ldots,a_{n-1} are the coordinates of the same polynomial in the standard basis:

[f]L=(y1⋮yn),[f]B=(a0⋮an−1).[f]_L= \begin{pmatrix} y_1\\\vdots\\y_n \end{pmatrix}, \qquad [f]_B= \begin{pmatrix} a_0\\\vdots\\a_{n-1} \end{pmatrix}.

The coordinate vector changes with the basis; the polynomial ff does not.

On this page