Professional Documents
Culture Documents
CH 4 Interpolation
CH 4 Interpolation
Introduction
Estimation of intermediate values between
precise data points. The most common method is
polynomial interpolation:
f ( x) a0 a1 x a2 x 2 an x n
n=3 n=4
n=2
n
f n ( x) Li ( x) f ( xi )
i 0
n x xj
Li ( x)
j 0 xi x j
j i
x x1 x x0
f1 ( x) f ( x0 ) f ( x1 )
x0 x1 x1 x0
Lo (x) L1 ( x)
Lagrange Interpolating Polynomials
f 2 ( x)
x x1 x x2
f ( x0 ) Lo ( x) , j 0
x0 x1 x0 x 2
x x0 x x2
f ( x1 ) L1 ( x) , j 1
x1 x0 x1 x 2
x x0 x x1
f ( x2 ) L2 ( x) , j 2
x2 x0 x2 x1
Lagrange Interpolating Polynomials - Example
x0 1 f ( x0) ln(1) 0
x1 4 f ( x1) ln( 4) 1.386294
x2 6 f ( x2) ln( 6) 1.791760
Lagrange Interpolating Polynomials – Example
(cont’d)
• First order polynomial:
x x1 x x0
f 1( x) f ( x 0) f ( x1)
x 0 x1 x1 x 0
24 2 1
f 1(2) 0 1.386294 0.4620981
1 4 4 1
Lagrange Interpolating Polynomials –
Example (cont’d)
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
Lagrange Interpolating Polynomials – Example
(cont’d)
n n
x xj
f n ( x ) Li ( x ) f ( xi ) Li ( x ) ( j i)
i 0 j 0 xi x j
(2 4)(2 6)
f 2 (2) 0
(1 4)(1 6)
(2 1)(2 6)
1.386294
(4 1)(4 6)
(2 1)(2 4)
1.791760 0.5658444
(6 1)(6 4)
Lagrange Interpolating Polynomials – Example
(cont’d)
Pseudocode – Lagrange interpolation
Coefficients of an Interpolating Polynomial
f ( x) a0 a1 x a2 x ax x
2 n
f ( x0 ) a0 a1 x0 a x a x
2
2 0
n
n 0
f ( x1 ) a0 a1 x1 a x a x
2
2 1
n
n 1
f ( xn ) a0 a1 xn a2 xn2 an xnn
Where “x”s are the knowns and “a”s are the
unknowns.
Interpolantion
Polynomials are the most common choice
of interpolation because they are easy
to:
Evaluate
Differentiate, and
Integrate.
16
Possible divergence of an extrapolated
production
Why Spline Interpolation?
18
Why Splines ?
17th Order
Polynomial
Original
Function
5th Order
Polynomial
9th Order
Polynomial
f ( x) f ( x0 ) m0 ( x x0 ) x0 x x1
f ( x) f ( x1 ) m1 ( x x1 ) x1 x x2
f ( x) f ( xn1 ) mn1 ( x xn1 ) xn1 x xn
f ( xi 1 ) f ( xi )
mi
xi 1 xi
Linear spline - Example
Fit the following data with first order splines.
Evaluate the function at x = 5.
2 .5 1
x f(x) m 0.6
7 4.5
3.0 2.5 f (5) f (4.5) m(5 4.5)
4.5 1.0 1.0 0.6 0.5
7.0 2.5
9.0 0.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.
ai xi 1 bi xi 1 ci f i ( xi 1 ) i 2, 3, 4,..., n
2
an xn bn xn cn f ( xn )
2
Quadric Splines
• The first derivatives at the interior knots
must be equal (n-1).
f i ( x) 2ai x bi
'
2ai 1 xi 1 bi 1 2ai xi 1 bi
Solutions:
There are 3 intervals (n=3), 9 unknowns.
Quadric Splines - Example
1. Equal interior points:
For first interior point (4.5, 1.0)
The 1st equation:
x12 a1 x1b1 c1 f ( x1 )
x a x3b3 c3 f ( x3 )
2
3 1 81a3 9b3 c3 0.5
Quadric Splines - Example
Equal derivatives at the interior knots.
For first interior point (4.5, 1.0)
2 x1 a1 b1 2 x1 a2 b2 9a1 b1 9a2 b2
4.5 1 0 0 0 0 0 0 b1 1
0 0 c
20.25 4.5 1 0 0 0 1 1
0 0 49 7 1 0 0 0 a2 2.5
0 0 0 0 0 49 7 1 b2 2.5
3 1 0 0 0 0 0
0 c2 2.5
0 0 0 0 0 81 9 1 a3 0.5
1 0 9 1 0 0 0 0 b3 0
0 0 14 1 0 14 1 0 c3 0
Quadric Splines - Example
Solving these 8 equations with 8 unknowns
a1 0, b1 1, c1 5.5
a2 0.64, b2 6.76, c2 18.46
a3 1.6, b3 24.6, c3 91.3
fi ( x) ai x3 bi x 2 ci x di
For n+1 data points:
• i = (0, 1, 2, …n),
• n intervals,
• 4n unknown constants (a’s, b’s ,c’s and d’s)
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)
Alternative technique to get Cubic Splines
• The second derivative within each interval [xi-1, xi ] is a straight line. (the 2nd
derivatives can be represented by first order Lagrange interpolating
polynomials.
A straight line
x xi x xi 1
f i ( x) f i ( xi 1 ) f i ( xi )
'' '' ''
connecting the first
xi 1 xi xi xi 1 knot f’’(xi-1) and the
second knot f’’(xi)
f ' ' ( xi )
f i ( xi 1 ) f i ( xi 1 ) xi xi 1
''
xi x
xi xi 1 6 f ' ' ( xi 1 )
i = 0, 1,…, n
f i ( xi ) f i ( xi ) xi xi 1
''
x xi 1
xi xi 1 6
Cubic Splines
• For each interior point xi (n-1): f i1 ( xi ) f i ( xi )
' '
( xi xi 1 ) f '' ( xi 1 ) 2( xi 1 xi 1 ) f '' ( xi )
( xi 1 xi ) f '' ( xi 1 )
6
f ( xi 1 ) f ( xi )
xi 1 xi
6
f ( xi 1 ) f ( xi )
xi xi 1
Solution:
Natural Spline:
6
f ( xi 1 ) f ( xi ) 6
f ( xi 1 ) f ( xi )
xi 1 xi xi xi 1
Cubic Splines - Example
6 6
1.5 f (3) 2 4 f (4.5) 2.5 f (7)
'' ''
(2.5 1)
''
(2.5 1)
2.5 1.5
Since f ''
(3) 0
xi 1 xi x3 x2 9 7 2
Cubic Splines - Example
6
f ( xi 1 ) f ( xi ) 6
f ( xi 1 ) f ( xi )
xi 1 xi xi xi 1
6 6
2.5 f '' (4.5) 2 4.5 f '' (7) 2 f '' (9) (0.5 2.5) (1 2.5)
2 2.5
Since f '' (9) 0