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 , form
If at least two input values are distinct, the least-squares straight-line fit has the unique coefficient vector
For a candidate line , the vector of predicted values at the inputs is
The columns of contain the sampled values of and , so multiplying them by and produces the line's predicted values. The line need not pass through every data point.
The fitted value vector lies in the column space
Least squares chooses and to minimise the sum of squared vertical errors
where is the usual Euclidean norm on . The problem is therefore to find the point of closest to ; the formula in the statement is the coordinate calculation for that projection.
At a minimum, differentiating with respect to and gives
These are exactly the two entries of
Thus the residual
is perpendicular to both columns of , hence to their span. If solves the normal equations and is any other coefficient vector, this perpendicularity gives
So is the closest model vector to .
When two input values are distinct, for every forces , so the columns of are independent. Hence is invertible and the minimising coefficient vector is unique. Multiplying the normal equations by gives the coefficient formula in the statement.
Interpolate in the standard polynomial basis
To find the coordinate vector of the interpolating polynomial in :
- Form the Vandermonde matrix
and the data vector . 2. Solve
- Read the solution
as the coordinates of the interpolating polynomial.
The th row imposes the condition . Because the inputs are distinct, these conditions determine exactly one coordinate vector.
Interpolate in the Lagrange basis
For data , construct the Lagrange polynomials and set
Then for every , which gives the interpolating polynomial.
The data values are the coordinates in the Lagrange basis, while are the coordinates of the same polynomial in the standard basis:
The coordinate vector changes with the basis; the polynomial does not.