-20
-30
-40
-10
20
10
0
-10
The polynomial interpolation problem can be stated as the following:
๐บ๐๐ฃ๐๐ ๐ + 1 ๐๐๐ก๐ ๐๐๐๐๐ก๐ , (๐ฅ ๐
, ๐ฆ ๐
-) ๐๐๐ ๐ = 0,1, … ๐ ๐๐๐๐ ๐ ๐(๐ฅ) ∈ ๐ซ ๐
๐ ๐ข๐โ ๐กโ๐๐ก ๐(๐ฅ ๐
) = ๐ฆ ๐
๐๐๐ ๐๐๐ ๐ = 0,1, … ๐ ๐คโ๐๐๐ ๐ซ ๐
๐๐๐๐๐ก๐๐ ๐กโ๐ ๐ ๐๐ก ๐๐ ๐๐๐ ๐๐๐๐ฆ๐๐๐๐๐๐๐ ๐๐ ๐๐๐๐๐๐ ๐๐ก ๐๐๐ ๐ก ๐
Example
The blue circles represent the data points, and the red curve represents the interpolating polynomial.
The black line represents a least squares regression line fitted to the same data.
X
Y
0
-10
10
3
20
-30
30
6
40
10
50
-2
60
15
40
30
0 10 20 30 40 50 60 70
Interpolation vs. Regression
Interpolation models must take on the exact values of the known data points, whereas regression models try to minimize the distance between the prediction and each actual known value.
Given n+1 data points, the “best fit” polynomials of degree < n form regression models, where the predictions may not necessarily land exactly on the data points. However, the “best fit” polynomial of degree = n forms the interpolating polynomial which will land exactly on every data point. Notice that this means the sum of squared errors for the interpolating polynomial is always zero.
Interpolation vs. Regression Examples
-2
-3
-1
0
-1
3
2
1
-0.8
-0.6
-0.4
-0.2
0 0.2
0.4
0.6
0.8
1
1.5
1
-0.5
-1
-1.5
-1
0.5
0
-0.8
-0.6
-0.4
-0.2
0 0.2
0.4
0.6
0.8
1
Polynomial interpolation can be used when you believe your measured data to be exact.
Regression models, on the other hand, assume that measurements have noise. The model is usually: ๐ฆ = ๐(๐ฅ) + ๐ ๐คโ๐๐๐ ๐~๐(0, ๐ 2 )
The point of a regression model is to estimate f(x), and this estimate can be used for forecasting future and past data values as well as predicting data values between known data points.
However, interpolation models are suitable only for estimating data values between data points.
Runge Phenomenon example
The function being sampled is:
1
1+16๐ฅ 2
The blue curve is f(x), the red curve is the interpolating polynomial, and the green curve is a spline
5 nodes 9 nodes
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-1
1.2
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-1
1.2
1
0.8
-0.8
-0.6
-0.4
-0.2
0 0.2
0.4
0.6
0.8
1
-0.6
-0.4
-0.8
17 nodes
-0.2
0 0.2
0.4
0.6
0.8
1
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-1
1.2
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-1
1.2
1
0.8
-0.8
-0.6
-0.4
-0.6
-0.8
21 nodes
-0.4
-0.2
-0.2
0 0.2
0.4
0.6
0.8
1
0 0.2
0.4
0.6
0.8
1
Solving the Polynomial Interpolation Problem
๐๐ ๐๐๐ {1, ๐ฅ, ๐ฅ 2 , ๐ฅ 3 , … ๐ฅ ๐ } ๐๐ ๐ ๐๐๐ ๐๐ ๐๐๐ ๐ซ ๐ ๐๐๐ฆ ๐(๐ฅ) ∈ ๐ซ ๐
๐๐๐ ๐๐ ๐ค๐๐๐ก๐ก๐๐ ๐๐ ๐กโ๐ ๐๐๐๐: ๐(๐ฅ) = ๐ผ
0
+ ๐ผ
1 ๐ฅ + ๐ผ
2 ๐ฅ 2 + โฏ + ๐ผ ๐ ๐ฅ ๐ ๐๐๐ ๐ผ ๐
∈ โ
๐๐ข๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐ ๐กโ๐ ๐ผ ๐
๐ ๐ข๐โ ๐กโ๐๐ก ๐๐๐ฃ๐๐ ๐ + 1 ๐๐๐ก๐ ๐๐๐๐๐ก๐ , (๐ฅ ๐
, ๐ฆ ๐
-) ๐๐๐ ๐ = 0,1, … ๐ ๐ผ
0
+ ๐ผ
1 ๐ฅ ๐
+ ๐ผ
2 ๐ฅ ๐
2 + โฏ + ๐ผ ๐ ๐ฅ ๐ ๐ = ๐ฆ ๐
It is clear that this problem is simply a system of linear equations. We can set up the problem as
[
1 ๐ฅ 0
1 ๐ฅ
1 ๐ฅ ๐ฅ
2
0
2
1
โฏ
… ๐ฅ ๐ฅ
โฎ โฎ โฎ โฑ โฎ ๐
0 ๐
1
1 ๐ฅ ๐ ๐ฅ 2 ๐
… ๐ฅ ๐ ๐
] [
๐ผ 0 ๐ผ
โฎ
1 ๐ผ ๐
]
=
[
๐ฆ 0 ๐ฆ
โฎ
1 ๐ฆ ๐
]
We can use any normal solution method for solving systems of linear equations to find our solution.
The solution will be the interpolating polynomial ๐(๐ฅ) = ๐ผ
0
+ ๐ผ
1 ๐ฅ + ๐ผ
2 ๐ฅ 2 + โฏ + ๐ผ ๐ ๐ฅ ๐
Matlab Implementation function result = poly_interp(x, y)
% x and y are column vectors with the x and y values of the data points
% there are n+1 data points n = length(x) - 1;
% construct the Vandermonde matrix
V = zeros(n+1,n+1); for i=1:n+1 for j=1:n+1
V(i,j) = x(i).^(j-1); end %for end %for
% solve the system of equations alpha = V\y;
%reverse the alpha vector to match Matlab standards
%for polynomial coefficient vectors result = fliplr(alpha');
% plot the solution xx = x(1):0.01:x(n+1); yp = polyval(result,xx); figure(100) plot(x,y, 'bo' ) hold on plot(xx,yp, 'r' ) end %function
Or you can just use the polyfit(x,y,n) function in Matlab. This function will find the polynomial of degree
n, which fits the data x and y best in a least squares sense. However, since the sum of squared errors for the interpolating polynomial is always zero, calling this function with n = #data points – 1 will give you the interpolating polynomial—instead of a regression polynomial—as a result.