Interpolation
Interpolation
Interpolation
n=3 n=4
n=2
3
Introduction
6
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 )
f ( x1 ) f ( x0 )
x x1 b1
x x0
f ( x2 ) f ( x1 ) f ( x1 ) f ( x0 )
x2 x1 x1 x0
x x2 b2
x2 x0
7
General Form of Newton’s Interpolating Polynomials/
f n ( x) f ( x0 ) ( x x0 ) f [ x1 , x0 ] ( x x0 )( x x1 ) f [ x2 , x1 , x0 ]
( x x0 )( x x1 ) ( x xn 1 ) f [ xn , xn 1 , , x0 ]
b0 f ( x0 )
b1 f [ x1 , x0 ]
b2 f [ x2 , x1 , x0 ]
bn f [ xn , xn 1 , , x1 , x0 ]
f ( xi ) f ( x j )
f [ xi , x j ] Bracketed function
xi x j evaluations are finite
f [ xi , x j ] f [ x j , xk ] divided differences
f [ xi , x j , xk ]
xi xk
f [ xn , xn 1 , , x1 ] f [ xn 1 , xn 2 , , x0 ]
f [ xn , xn 1 , , x1 , x0 ]
xn x0 8
Lagrange Interpolating Polynomials
n
f n ( x) Li ( x) f ( xi )
i 0
n x xj
Li ( x)
j 0 xi x j
j i
L o( x) L1 ( x)
Lagrange Interpolating
Polynomials
• Second order version (n = 2):
f 2 ( x )=
(x− x 1 )(x− x 2 )
f ( x 0)
L o( x) , j≠ 0
(x 0− x1 )(x 0− x 2 )
(x− x 0 )(x − x 2 )
+ f ( x1 ) L1 ( x) , j≠ 1
(x1 − x 0 )(x1 − x 2 )
+
( x− x 0 )(x− x1 )
f ( x 2) L 2( x ) , j≠ 2
(x 2 − x 0 )(x 2 − x 1 )
Lagrange Interpolating Polynomials -
Example
x 0= 1 f ( x 0 )= ln(1)= 0
x 1= 4 f ( x 1 )= ln (4)= 1.386294
x 2= 6 f ( x 2 )= ln(6)= 1.791760
Lagrange Interpolating Polynomials –
Example (cont’d)
● First order polynomial:
x− x 1 x− x 0
f 1 ( x)= f ( x 0 )+ f ( x1)
x 0− x 1 x 1− x 0
2− 4 2− 1
f 1 ( 2)= ⋅ 0+ ⋅ 1 . 386294= 0 . 4620981
1− 4 4− 1
Lagrange Interpolating Polynomials –
Example (cont’d)
xx1xx
2 x4
x6
L
(x
)
o
xox1xox20 406
xxox
x
2 x0
x6
L
(x
)
1
x1xox
1x24 046
xxox
x
1 x0
x4
L
(x
)
2
x2 x
ox
2 x
16 064
Lagrange Interpolating Polynomials –
Example (cont’d)
n n
xx
fn(
x)L
i(
x)f(
xi)
L
i(
x
) j
( i
) j
i
0
j i
0x 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)
Coefficients of an Interpolating Polynomial
f ( x 0 )= a 0 +a 1 x 0 +a 2 x 20 ⋯+a n x n0
2 n
f ( 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 “x”s are the knowns and “a”s are the
unknowns.
Possible divergence of an extrapolated
production
Why Spline Interpolation?
20
Why Splines ?
1
f ( x )=
1+25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y
1 25 x 2
-1.0 0.038461
-0.6 0.1
-0.2 0.5
0.2 0.5
0.6 0.1
17thOrder
Polynom ial
Original
Function
5thOrder
Polynom ial
9thOrder
Polynom ial
f ( x)= f ( x 0)+m0( x− x 0 ) x 0≤ x ≤ x1
f ( x)= f ( x1 )+m1 ( x− x 1 ) x 1 ≤ x≤ x 2
⋮
f ( x)= f ( x n− 1 )+mn− 1 ( x− x n− 1 ) x n− 1≤ x≤ x n
f ( xi+1 )− f ( x i )
mi =
x i+1 − x i
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
= 1.3
9.0 0.5
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.
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:
For
2 the end point (9, 0.5)
x 3 a1 +x 3 b 3 +c 3 = f ( x 3 ) 81 a 3 +9b 3 +c 3 = 0 . 5
Quadric Splines - Example
Equal derivatives at the interior knots.
For first interior point (4.5, 1.0)
righ
[]
b1
c1
a2
b2
c2
a3
b3
c3
righ
1
1
2.5
2.5
2.5
0.5
0
0
righ
Quadric Splines - Example
Solving these 8 equations with 8 unknowns
a 1 = 0, b1 = − 1, c 1= 5 . 5
a 2 = 0 . 64 , b 2 = − 6. 76 , c 2 = 18. 46
a 3 = − 1. 6, b3 = 24. 6, c 3 = − 91. 3
f 1 ( x )= − x +5. 5, 3 .0≤ x ≤ 4 . 5
f 2 ( x )= 0. 46 x 2 − 6 .76 x+18 . 46 , 4 . 5≤ x≤ 7 . 0
A straight line
x− x i x− x i− 1
f ''( x )= f '' ( xi− 1 ) + f ''( xi ) connecting the first
i i x i− 1− x i i xi − x i− 1 knot f’’(xi-1) and the
second knot f’’(xi)
Unknowns:
i = 0, 1,…, n
Cubic Splines
• For each interior point xi (n-1): f 'i− 1 ( x i )= f i ( x i )
'
Solution:
Natural Spline:
f '' ( x 0 )= f '' (3 )= 0, f '' ( x 3 )= f '' (9 )= 0
Cubic Splines - Example
For 1st interior point (x1 = 4.5)
x 3.0 4.5 7.0 9.0
f(x) 2.5 1.0 2.5 0.5
- x i − x i− 1= x 1− x 0= 4. 5− 3. 0= 1. 5
- x i+1− xi− 1= x 2− x 0= 7− 3. 0= 4
- x i+1− xi = x 2− x 1= 7− 4. 5= 2. 5
Apply the following equation:
( x i− x i− 1 ) f '' ( x i− 1 )+2( x i+1 − x i− 1 ) f ''( x i )+( x i+1− x i ) f ''( xi+1 )
6 6
¿
xi+1 − x i [ f ( xi+1 )− f ( x i ) ] +
x i− xi− 1 [ f ( xi− 1 )− f ( xi ) ]
Cubic Splines - Example
'' '' 6 '' 6
1. 5f (3 )+2× 4f (4 . 5)+2 . 5f (7 )= (2 . 5− 1 )+ (2 . 5− 1 )
2.5 1 .5
''
Since f (3)= 0
8f ''( 4.5)+2.5f '' (7)= 9.6 .............. (eq.1)
For 2nd interior point (x2 = 7 )
f i ( xi − 1 ) f i'' ( x i− 1 ) (x i − x i− 1 ) f ''( x i ) (x i − x i− 1 )
+
[ x−x
i
−
i− 1 6 ] [
x −
( i ) x−x
x +
f i( xi )
i i− 1
−
6
i
]
(x− x i− 1 )
f 1 ( x)= 0 ( xi − 3 ) +
1. 67909
3
6(1. 5)
3
( x− 3 ) +
1.5
−
6 [
2 . 5 0(1. 5 )
(4 . 5− x )+] 1 1. 67909(1. 5)
1. 5
−
6 [
( x− 3) ]
f 1 ( x )= 0 .186566 ( x− 3 )3 +1 .6667 (4 . 5− x )+0 . 24689( x− 3 )
Cubic Splines - Example
The 2nd interval (i =2), apply for the equation:
3 − 1 .53308 − 1. 67909(2 . 5)
f 2 ( x )=
1 . 67909
6 (2 .5 )
(7− x) +
6(2 .5 )
3 1
( x− 4 .5 ) + [ −
2 .5 6 ]
(7− x )
2. 5 − 1 . 53308(2 . 5)
+[ −
2. 5 6 ]
( x− 4 . 5)