Inverse Interpolation: For Example, Let's Suppose That We Want To Calculate A Zero of The Function
Inverse Interpolation: For Example, Let's Suppose That We Want To Calculate A Zero of The Function
Inverse Interpolation: For Example, Let's Suppose That We Want To Calculate A Zero of The Function
The inverse interpolation method can be used to found a zero of a function f (x) by
computing f 1 (0) , where x f 1 ( y ) is a polynomial that interpolates a table of
( f 1 ( x), x) values.
For example, let's suppose that we want to calculate a zero of the function
f ( x) x 3 15x 4 knowing that this is close to x 0.3 .
We then first evaluate the function in three points close to x 0.3 :
f2(0) = 0.2679.
Given x0 , f ( x0 ) , x1 , f ( x1 ) ,......, xn 1 , f ( xn 1 ) , xn , f ( xn ) and a function value f ( xk ) , how do
you determine x k ?
1. Using one of the interpolation methods (Newton or Lagrange), obtain the function
f(x) :
f ( x) a0 a1 x a2 x 2 an x n
2. Plug in the value of f ( xk ) in the above equation and find one of the real roots of the
resultant equation using a root finding method:
a0 a1 x a2 x 2 an x n f ( xk ) 0
Example:
Employ inverse interpolation using a cubic interpolating polynomial and root finding to
determine the value of x that corresponds to f(x) = 0.23 for the following data:
xi f(xi)
3 0.3333
4 0.25
5 0.2
6 0.1667
Solution:
First step: polynomial interpolation
The following points are used to generate a cubic interpolating polynomial
x0 = 3 f(x0) = 0.3333
x1 = 4 f(x1) = 0.25
x2 = 5 f(x2) = 0.2
x3 = 6 f(x3) = 0.1667
The polynomial can be generated in a number of ways including: Newton’s Divided
Linear splines
Then, the linear spline can be expressed as:
f ( x1 ) f ( x0 ) x0 x x1
f ( x) f ( x0 ) ( x x0 ),
x1 x0
f ( x2 ) f ( x1 ) x1 x x2
f ( x1 ) ( x x1 ),
x2 x1
......
f ( xn ) f ( xn1 ) xn 1 x xn
f ( xn1 ) ( x xn1 ),
xn xn1
f ( xi ) f ( xi 1 )
where : the first divided differenceof f(x).
xi xi 1
2. Quadratic Splines
In these splines, a quadratic polynomial approximates the data between two consecutive data
points. The splines are given by
Given (n+1) points, there are 3(n) coefficients to find and hence, need to determine 3n
equations to solve:
ai xi2 bi xi ci f ( xi ) i 1,2,, n
ai xi21 bi xi 1 ci f ( xi 1 ) i 1,2,, n
This condition gives 2n equations as there are ‘n’ quadratic splines going through two
consecutive data points.
Since there are (n-1) interior points, we have (n-1) such equations.
3. Now, the total number of equations is (2n) (n 1) (3n 1) equations. We can
assume that the first spline (or the last spline) is linear, that is:
a0 0 (or an 0 )
Example:
Construct a quadratic spline interpolating the following data:
xi -1 0 1
-1 0 1
yi sin( xi )
2
Solution: Assume that the quadratic spline S2 x is of the form:
P x a1 x 2 b1 x c1 , ha x 1; 0
S 2 x 1
P2 x a2 x b2 x c2 , ha x 0; 1
2
We have a1 1 and b1 2 .
5) b1 b2 2
4) a2 2 1 a2 1 .
Therefore the quadratic spline function is:
x 2 2 x, ha x 1; 0
S 2 x 2
x 2 x, ha x 0; 1 .
s1 ( x) a1 b1 ( x x1 ) c1 ( x x1 ) 2 d1 ( x x1 )3 , x1 x x2
S3 ( x)si ( x) ai bi ( x xi ) ci ( x xi ) 2 di ( x xi )3 , xi x xi 1
sn 1 ( x) an 1 bn 1 ( x xn 1 ) cn 1 ( x xn 1 ) 2 d n 1 ( x xn 1 )3 , xn 1 x xn
For S 3 ( x ) to be a cubic interpolating spline, we have a set on interpolation conditions: that is,
at an interval [ xi , xi 1 ]
1. si ( xi ) yi , i 1,, n 1
Since each of the (n 1) cubic pieces has four unknown coefficients, our description of the
and its first and second derivatives imposes 2(n 1) 2(n 2) linear constraints on its
coefficients. Therefore, there are a total of 4n 6 linear constraints on the 4(n 1) unknown
coefficients. In order that we have the same number of equations as unknowns, we need 2
more (linear) constraints. There are various ways of specifying two additional constraints such
as the following:
1. The so–called natural cubic spline results when we impose the conditions:
s1'' ( x1 ) 0, sn'' 1 ( xn ) 0.
2. Instead of imposing the natural cubic spline conditions, we could use the correct
second derivative values:
s1'' ( x1 ) c1, sn'' 1 ( xn ) c2 where c1 and c2 are given.
3. In the complete cubic spline, the slope conditions
s1 ( x1 ) c1 , sn 1 ( xn ) c2 where c1 and c2 are given.
are imposed. These first derivative values of the data may not be readily available but
they can be replaced by accurate approximations.
Example:
Construct a cubic spline interpolating the following data:
xi -1 0 1
-1 0 1
yi sin( xi )
2
Solution:
Assume that the cubic spline S x is of the form:
The continuity of the first and second derivative at each interior point, we have:
From the data we known that the function is periodic ( yi sin( xi ) ), then the periodicity
2
may be used to specify the boundary conditions:
Therefore the cubic spline function is:
MATLAB has several built-in functions to implement piecewise interpolation. The first is
spline:
yy=spline(x, y, xx)
Example:
• Generate data:
Calculate actual function values at model points and plot data points, the 9-point
(solid), and the actual function (dashed),
>> yr = 1./(1+25*xx.^2);
>> plot(x, y, 'o', xx, yy, '-', xx, yr, '--')
MATLAB’s interp1 function
While spline can only perform cubic splines, MATLAB’s interp1 function can
perform several different kinds of interpolation:
Example: 1. Find the linear splines for the following data set
i 1 2 3 4 5
x 0 5 7 8 10
y 0 2 -1 -2 20
>> x=[0 5 7 8 10];
>> y=[0 2 -1 -2 20];
>> n=1000; % Number of points.
>> xi=linspace(0,10,n); % Create vector of x values
>> yi=interp1(x,y,xi,'linear'); % Calculate y
>> plot(x,y,'o',xi,yi);
Example: 2. Find the quadratic splines for the following data set
i 1 2 3 4 5 6 7 8
x 0 0.2 0.6 1 1.4 1.6 1.8 2
y 1 1 1.2 1.1 0.6 0.5 0.5 0.5
>> plot(x,y,'o',xi,yi);