Interpolation - Introduction: NTH n+1
Interpolation - Introduction: NTH n+1
Introduction
n=2
n=3
n=4
Interpolation
Introduction
Newtons Divided-Difference
Interpolating Polynomials
Linear Interpolation/
Is the simplest form of interpolation, connecting two data points
with a straight line.
f1 ( x) f ( x0 ) f ( x1 ) f ( x0 )
x x0
x x0
Slope and a
finite divided
difference
approximation to
1st derivative
f ( x1 ) f ( x0 )
f1 ( x) f ( x0 )
( x x0 ) Linear-interpolation
x x0
formula
Figure
18.2
Quadratic Interpolation/
If three data points are available, the estimate is improved
by introducing some curvature into the line connecting
the points.
f 2 ( x) b0 b1 ( x x0 ) b2 ( x x0 )( x x1 )
A simple procedure can be used to determine the values
of the coefficients.
x x0
b0 f ( x0 )
x x1
f ( x1 ) f ( x0 )
b1
x x0
x x2
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1
x1 x0
b2
x2 x0
7
bn f [ xn , xn 1 , , x1 , x0 ]
f [ xi , x j ]
f ( xi ) f ( x j )
f [ xi , x j , xk ]
xi x j
f [ xi , x j ] f [ x j , xk ]
Bracketed function
evaluations are finite
divided differences
xi xk
f [ xn , xn 1 , , x1 , x0 ]
f [ xn , xn 1 , , x1 ] f [ xn 1 , xn 2 , , x0 ]
xn x0
f n ( x) Li ( x) f ( xi )
i 0
n
Li ( x)
j 0
j i
x xj
xi x j
designates the product of
f 1 ( x )=
xx 1
x 0 x 1
f ( x 0 )+
L o ( x)
xx 0
x 1 x 0
f ( x1 )
L1 ( x )
Lagrange Interpolating
Polynomials
Second order version (n = 2):
xx 1 )( x x 2 )
(
f 2 ( x )=
f ( x 0)
( x 0 x1 )( x 0 x 2 )
xx 0 ) ( x x 2 )
(
+
f ( x1 )
( x1 x 0 )( x1 x 2 )
x x 0 )( x x1 )
(
+
f ( x 2)
( x 2 x 0 )( x 2 x 1 )
L o ( x ) , j0
L1 ( x ) , j1
L 2 ( x ) , j2
x 0=1
x 1=4
x 2=6
f ( x 0 )=ln (1 )=0
f ( x 1 )=ln (4 )=1. 386294
f ( x 2 )=ln (6)=1. 791760
x x 1
xx 0
f 1 ( x)=
f ( x 0 )+
f ( x1)
x 0 x 1
x 1 x 0
24
21
f 1 ( 2)=
0+
1 . 386294=0 . 4620981
14
41
x x1 x x2
x 4 x 6
Lo ( x )
xo x1 xo x2 0 4 0 6
x xo x x2 x 0 x 6
L1 ( x )
x1 xo x1 x2 4 0 4 6
x xo x x1
x 0 x 4
L2 ( x )
x2 xo x2 x1 6 0 6 4
f n ( x ) Li ( x ) f ( xi )
i 0
Li ( x )
j 0
x xj
xi x j
(24)(26)
f 2 (2)=
0
(14)(16)
( 21)( 26 )
+
1.386294
( 41)(46)
(21)(24 )
+
1.791760=0. 5658444
(61)(64 )
( j i)
f ( x )=a 0 + a1 x+ a 2 x ++ a x x
Coefficients of an Interpolating
Polynomial (contd)
2
n
( x 0 )=a 0 +a 1 x 0 +a 2 x 0 +a n x 0
2
n
( x1 )=a 0 +a1 x1 +a 2 x1 +a n x 1
2
n
f ( x n )=a 0 +a 1 x n +a 2 x n +a n x n
Where xs are the knowns and as are the
unknowns.
Why Splines ?
1
f ( x )=
1+ 25 x 2
Table : Six equidistantly spaced points in [-1, 1]
x
1
1 25 x 2
-1.0
0.038461
-0.6
0.1
-0.2
0.5
0.2
0.5
0.6
0.1
1.0
0.038461
Why Splines ?
17th Order
Polynomial
Original
Function
5th Order
Polynomial
9th Order
Polynomial
22
Spline Interpolation
Polynomials are the most common choice of
interpolants.
There are cases where polynomials can lead to
erroneous results because of round off error and
overshoot.
Alternative approach is to apply lower-order
polynomials to subsets of data points. Such
connecting polynomials are called spline
functions.
Spline Interpolation
The concept of spline is using a thin , flexible strip
(called a spline) to draw smooth curves through a
set of points.natural spline (cubic)
Linear Spline
The first order splines for a group of ordered data
points can be defined as a set of linear functions:
f ( x )= f ( x 0 )+m0 ( x x 0 )
x 0 x x 1
f ( x )= f ( x1 )+m1 ( xx 1 )
x 1 x x 2
f ( x )= f ( x n1 )+mn1 ( xx n1 )
mi =
x n1 xx n
f ( xi+1 ) f ( x i )
x i+1 x i
f(x)
3.0
4.5
7.0
9.0
2.5
1.0
2.5
0.5
2. 51
m=
=0 . 6
74 . 5
f (5)= f (4 .5 )+m(54 . 5)
=1. 0+0. 60.5
=1. 3
Linear Spline
The main disadvantage of linear spline is that
they are not smooth. The data points where 2
splines meets called (a knot), the changes
abruptly.
The first derivative of the function is discontinuous
at these points.
Using higher order polynomial splines ensure
smoothness at the knots by equating derivatives
at these points.
Quadric Splines
Objective: to derive a second order polynomial for each
interval between data points. f i ( x )=a i x 2 +bi x+ci
Terms: Interior knots and end points
Quadric Splines
The function values of adjacent polynomial
must be equal at the interior knots 2(n-1).
a i1 x
ai x
i1
i1
2 + bi1 x i1 + ci1=
2 +b i x i1 + ci =
f i ( x i1 ) i=2, 3, 4, . .. , n
f i ( xi1 )
i=2, 3, 4, . .. , n
a n x 2 +b n x n + c n = f ( x n )
n
Quadric Splines
The first derivatives at the interior knots
must be equal (n-1).
f ' ( x )=2ai x+bi
i
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
Solutions:
There are 3 intervals (n=3), 9 unknowns.
( 7) a 2 + 7b2 + c 2 = f ( 7)
49 a 2 +7b 2 + c2 = 2. 5
x 2 a 3 + x 2 b3 + c 3= f ( x 2 )
2
(7) a 3 +7b 3 + c3 = f (7 )
49 a3 +7b3 +c 3 =2 .5
For
2 the end point (9, 0.5)
x 3 a1 + x 3 b 3 +c 3 = f ( x 3 )
9a 1 +3b1 + c 1= 2. 5
81 a 3 +9b 3 +c 3 =0 . 5
0
0
0
0
1 0
0
7 1
0
9
14
1 0
[]
b
1
c1
a2
b2
c2
a3
b3
c3
righ
1
1
2.5
2.5
2.5
0.5
0
0
righ
righ
81
49
0
0
14
4.5 1 0
0
0
49
3 1
1
20.25
3 .0 x 4 . 5
4 . 5 x7 . 0
7 . 0 x9 .0
Cubic Splines
Objective: to derive a third order polynomial for
each interval between data points.
Terms: Interior knots and end points
3
f i ( x )=a i x + bi x +c i x +d i
For n+1 data points:
i = (0, 1, 2, n),
n intervals,
4n unknown constants (as, bs ,cs and ds)
Cubic Splines
The function values must be equal at the interior
knots (2n-2).
The first and last functions must pass through the
end points (2).
The first derivatives at the interior knots must be
equal (n-1).
The second derivatives at the interior knots must
be equal (n-1).
The second derivatives at the end knots are zero (2),
(the 2nd derivative function becomes a straight line at
the end points)
xx i
x i1 x i
+ f ''( xi )
i
x x i1
xi x i1
A straight line
connecting the first
knot f(xi-1) and the
second knot f(xi)
Cubic Splines
The last equation can be integrated twice
2 unknown constants of integration can be evaluated by
applying the boundary conditions:
1. f(x) = f (xi-1) at xi-1
2. f(x) = f (xi) at xi
Unknowns:
i = 0, 1,, n
Cubic Splines
For each interior point xi (n-1):
f 'i1 ( x i )= f i ( x i )
'
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
Solution:
Natural Spline:
f '' ( x 0 )= f '' (3 )=0, f '' ( x 3 )= f '' (9 )=0
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
- x i x i1=x 1 x 0 =4 . 53 . 0=1. 5
-
f
(
x
)
f
(
x
)
+
f ( xi1 ) f ( xi ) ]
[
[
i+1
i ]
xi+1 x i
x i xi1
''
''
''
''
3.0
4.5
7.0
9.0
f(x)
2.5
1.0
2.5
0.5
x i x i1 =x 2 x 1 =74 . 5=2. 5
x i +1 xi = x3 x 2 =97=2
f ( xi+1 ) f ( x i ) ] +
f ( xi1 ) f ( xi )]
[
[
xi+1 x i
x i xi1
6
6
2 . 5f ( 4. 5)+24 .5f (7)+ 2f (9 )= (0. 52 . 5)+
(12. 5)
2
2. 5
''
Since
''
''
''
''
f (9 )=0
''
''
8 f i ( 4 . 5 )+ 2 . 5 f i ( 7 )=9 . 6
2 . 5f ''i ( 4 . 5 )+9 f i'' ( 7 )=9 . 6
}
yeild
''
( 4 . 5 )=1 . 67909 ,
''
( 7 )=1 . 53308
f '' ( x i1 )
i
6 ( x i x i1 )
f i ( xi 1 )
x i x i 1
( x i x )
f '' ( xi )
i
6 ( xi xi 1 )
f '' ( x i1 ) ( x i x i 1 )
i
f 1 ( x )=0 ( xi 3 )3 +
( xx i 1 )
( x i x ) +
f i( xi )
x i x i1
f ''( x i ) ( x i x i1 )
i
( xx i 1 )
1. 67909
2 . 5 0(1. 5 )
1 1. 67909(1. 5)
( x3 )3 +
( 4 . 5x ) +
( x 3)
6(1. 5)
1.5
6
1. 5
6
3
1 . 67909
1. 67909(2 . 5)
3 1 .53308
3 1
f 2 ( x )=
(7x ) +
( x4 .5 ) +
( 7 x )
6 (2 .5 )
6(2 .5 )
2 .5 6
2. 5 1 . 53308(2 . 5)
+
( x4 . 5)
2. 5 6
f 2 ( x )= f 2 ( 5)=1. 102886
Credits:
Chapra, Canale
The Islamic University of Gaza, Civil Engineering
Department