The simplest way to exhibit the existence of a polynomial for interpolation with unevenly spaced data.
Linear interpolation
Quadratic interpolation
Lagrange polynomials have two important advantages over interpolating polynomials.
the construction of the interpolating polynomials does not require the solution of a system of equations.
the evaluation of the Lagrange polynomials is much less susceptible to roundoff.
Linear interpolation
put the values
then
substituting back and rearranging
redefining as
where Ls are the first-degree Lagrange interpolating polynomials.
Quadratic interpolation
where Ls are not the same with the previous Ls!!!
In general
Suppose we have a table of data with four pairs of - and -values, with indexed by variable :
Through these four data pairs we can pass a cubic.
The Lagrangian form is
This equation is made up of four terms, each of which is a cubic in ; hence the sum is a cubic.
The pattern of each term is to form the numerator as a product of linear factors of the form , omitting one in each term.
The omitted value being used to form the denominator by replacing in each of the numerator factors.
In each term, we multiply by the .
It will have terms when the degree is .
Fit a cubic through the first four points of the preceding Table 1 and use it to find the interpolated value for .
Carrying out the arithmetic,
.
MATLAB gets interpolating polynomials readily. The cubic fitted to the first four points;
Example m-file: Interpolation of gasoline prices with Lagrange Polynomials. (http://siber.cankaya.edu.tr/ozdogan/NumericalComputations/mfiles/chapter3/demoGasLag.mdemoGasLag.m http://siber.cankaya.edu.tr/ozdogan/NumericalComputations/mfiles/chapter3/lagrint.mlagrint.m)
Error of Interpolation; When we fit a polynomial to some data points, it will pass exactly through those points,
but between those points will not be precisely the same as the function that generated the points (unless the function is that polynomial).
How much is different from ?
How large is the error of ?
It is most important that you never fit a polynomial of a degree higher than 4 or 5 to a set of points.
If you need to fit to a set of more than six points, be sure to break up the set into subsets and fit separate polynomials to these.
You cannot fit a function that is discontinuous or one whose derivative is discontinuous with a polynomial.