Professional Documents
Culture Documents
Chapter 3
Chapter 3
Introduction
Newton Interpolation: Finite Divided Difference
Lagrange Interpolation
Spline Interpolation
Polynomial Regression
Multivariable Interpolation
Chapter 3 Interpolation & Curve Fitting / 2
3.1 Introduction
Interpolation is a technique to estimate the value between a set of data.
fn (x) a0 n
a1x L x ax
n
(3.1)
an i
i
i0
This chapter covers three types of techniques, i.e. the Newton interpolation,
the Lagrange interpolation and the Spline interpolation.
f x
f
x
1
f
x
x
f
0
0
x
1
x
f x
f x f x1 f x0 x
1 0 x (3.2)
0
x1 x0
Example 3.1
For the quadratic interpolation, consider Fig. 3.2 and the following relation:
y
fx
2
ln x
1
f1
x
0
0 2 4 6 x
FIGURE 3.2 The result for the linear interpolation for ln 2
f 2 x b0 b1 x x0 b2 x x0 x x1 (3.3)
By taking the values of x equal to x0, x1 dan x2 in Eq. (3.3), the coefficients
bi can be calculated as followed:
b0
f x0 (3.4a)
f x1 f x0 (3.4b)
b1
x1 x0
fx
ln x
1
f2
x
0
f1
0 2 4 x x 6
FIGURE 3.3 The result for the quadratic interpolation for ln 2
f n x b0 b1 x x0 L bn x x0 x x1 L x
(3.5)
xn1
b0
f x0
b1
f x1 , x0
b2
f x2 , x1 , x0
M
bn
f xn , xn1 ,K, x1 , x0
where the terms [] are finite divided differences and are defined as:
f x,x f x f x
i (3.6a)
i j
xi x j
f x,x,x
f xi , x f xj , x
i j k
(3.6b)
xi xk
f x , x ,K, x , x
f xn , xn1 ,K, x2 , x1 f xn1 , xn2 ,K, x1 , (3.6c)
x0
n n1 1 0
xn x0
i xi fxi I II III
0 x0 f x0 f x1x0 f x2x1x0 f x3x2x1x0
1 x1 f x1 f x2x1 f x3x2x1
2 x2 f x2 f x3x2
3 x3 f x3
The relation for error for the n-th order interpolation function can be
estimated using:
Rn
f xn1 , xn , xn1 ,K, x0 x x0 x x1 Lx (3.8)
xn
Example 3.3
i xi fxi I II III
0 1 0 0.46209813 0.0597386 0.00786553
1 4 1.3862944 0.22314355 0.0204110
2 5 1.6094379 0.18232156
3 6 1.7917595
Thus,
f 3 x 0 0.46209812x 1 0.0597386x 1x 4
0.00786553x 1x 4x 5,
f 3 2 0 0.462098122 1 0.05973862 12 4
0.007865532 12 42 5,
0.6287691.
and producing a relative error of t 9.29%.
y
2
fx l n x
f3x
0
0 2 4 6 x
TABLE 3.4 The result for the cubic interpolation for ln 2
3.3 Lagrange Interpolation
The formula for the Lagrange interpolation is:
n
f n x Li x f x i (3.9)
i 0
L x
xxj
n
i
(3.10)
j 0
j i
xi x
j
For n 1, the first order Lagrange interpolation function can be written as:
f x
x x1 f x x x 0 f x
1
0 1
x 0 x1 x1 x0
x0 x1 x0 x2 x0 x x2
x1 1
x x0 x x1
f x2
x2 x0 x 2 x1
The error term for the Lagrange interpolation can be estimated using:
Rn
f xn1 , xn , xn1 ,K, x0 x xi (3.11)
n
i0
Example 3.5
Repeat Examples 3.1 and 3.2 using the first and second order Lagrange
interpolation functions, respectively.
Solution
From Examples 3.1:
x0 1 : f (x0 ) 0
x1 4 : f (x1) 1.3862944
x2 6 : f (x2 ) 1.7917595
Chapter 3 Interpolation & Curve Fitting / 10
1 4 4 1
0.4620981
For the second order Lagrange interpolation:
f x
2 x x x0 x x2 f x
x x1 x x2 x 1
f
0 x1 x0 x2 0
x1 x0 x x2
1
x x0 x x1
x2 x0 x2 f x2
x1
f (2) 2 42 6 2 12 6
0 1.3862944
2
1 41 6 4 14 6
2 12 4
1.7917595
6 16 4
0.5658444
3.4 Spline Interpolation
The polynomial interpolation can cause oscillation to the function and this
can be remedied by using the spline interpolation.
fx f
x
x
x
(a) polynomial (b) Linear spline
FIGURE 3.5 Comparison between polynomial and spline interpolation
The formula for the linear spline interpolation for n1 data between points
x0 and xn (n intervals) is
f11 x
f x0 m0 x x0 untuk x0 x x1
f12 x f x1 m1 x x1 untuk x1 x x2
M M (3.12)
f1n x f xn1 mn1 x xn1 untuk xn1 x xn
dengan mi is the gradient for the (i1)-th interval:
f xi1 f xi
m (3.13)
i
xi1 xi
Example 3.6
Use the following data to estimate the function fx at x 5 using the linear
spline interpolation.
x f(
x
)
3 2
. .
0 5
4 1
. .
5 0
7 2
. .
0 5
9 0
. .
0 5
Solution
The value of x 5 is in the range 4.5 x 7 , where the gradient is
m1 2.5 1.0
7.0 4.5 0.60
From Eq. (3.12):
f12 x f x1 m1 x x1 ,
f12 5 1.0 0.605 4.5 1.3.
2
fx
4
2
6
For the quadratic spline, the general polynomial for each interval is
f x a x b x c
2
x
(3.14)
2i i i i
The coefficient ai, bi and ci for each interval can be evaluated using:
ai1
bi xi1 ci1 f xi1
2
xi1 (3.15)
1
2
ax
b x c f x (3.16)
i i1 i i1 i1
a x b x c f x
2
(3.18)
n n n n n n
f x 2ax b
2ai1xi1 bi1 2aixi1 (3.19)
bi
fx
0
2 4 6 x 8
For the cubic spline, the general polynomial for each interval is
f x a x b x c x d
3 2
(3.21)
3i i i i i
For interval xi1, xi, the second derivative can be written as:
x
f x f x x f x (3.22)
x xi1
i
i i i1
xi1 xi i i xi xi1
⎣ i i1 ⎦
The differentiability can be maintained troughout the function via
f i1 xi
f i xi (3.24)
Eq. (3.23) can be differentiated for both the i1-th and i-th intervals and
following Eq. (3.24):
Example 3.8
f31 1.67909
x x 33 2.5 4.5 x
64.5 4.5
3 3
⎡ 1 1.679094.5 3⎤
⎢ x 3,
⎣ 4.5 3 6 ⎥
⎦
0.186566x 3 1.6666674.5 x 0.246894x 3.
3
For the second and third intervals:
f32
x 0.1119397 x 3 0.102205x 4.53 0.2996217 x
1.638783x 4.5
f 33 x 0.1277579 x 1.7610279 x 0.25x 7
3
fx
2
e
Splin
c
Cubi
0
2 4 6 8 x
Interpolation
Lagrange
Cubic Newton/
f x a0
a1x a2 x2 L a xnn (3.26)
ey
i i f x y a
2
a x L a x
n
a i i 0
x1 i 2 i n i
N N
xn
S ei yi a2 x2 L a
2
a0 a1x (3.27)
i1 i1 i
i n 2
i
S
0 2 y a a x 2 L a xn x
N a x
a1 i1
i 0 1 i 2 i n i i
M
S
0 2 y a a x 2 L a x x
n n
N a x
an i1
i 0 1 i 2 i n i i
a0 N a1 a2 x 2 L a xn y
xi
i n i i
a x a x x L 2 3
x
n1
xy
0 i
a a
1 i3 2 i n i i i
a x a x a x 4 L
2
xn2 x2 y
a (3.28)
0 i 1 i 2 n i i i
i
M
a xn a xin1 2 xi n2 L n xi2n xni y i
0 i 1
a a
or, in a form of matrix equation:
⎡ N x
2
L
n
x ⎤ ⎧a 0 ⎧ yi ⎫
x i ⎫
⎢ i i ⎥ ⎪
L x
n1
a ⎪ ⎪
⎢ xi
2 3
x i x i ⎪ xi yi
⎥⎥ ⎪ ⎪
i 1
⎢ x 2 x
4
L x
n2 2
⎬ ⎪⎨ x y⎪ (3.29)
3
x ⎨a ⎬
i i ⎥ ⎪ 2⎪ ⎪ i i⎪
⎢ Mi M ⎥ M M
⎢ i
M O M
⎪ ⎪ ⎪ ⎪
⎢ x n
xi ⎥⎦ ⎪a
n
⎩ n ⎪ ⎪
⎩ xi yi ⎪
2n
⎣ i xi
n1
xi
n2
L ⎭ ⎭
The standard deviation for this case can be evaluated as followed:
e
2
S i1
(3.30)
N N
n
The case for n 1 is referred to as1the linear regression:
ni
y a0 a1x
1
⎡⎢ N x
⎤ ⎧ 0 ⎫ ⎨ ⎧ yi ⎫
a
2i ⎥ ⎨ ⎬
⎬ x x a x y (3.31)
⎣ i i ⎦ ⎩ 1⎭ ⎩ ii ⎭
Example 3.9
Solution
For n 2, the quadratic polynomial can be written as
2
f x a0 a1x a2 x
From Eq. (3.28):
⎡N 2
x ⎤ ⎧a0 yi ⎫
⎢ ⎧
⎪ ⎪
⎥ ⎫
i
xi 3 ⎪
x ⎪
2
⎢ xi xi i⎥
a
⎬ ⎨ xi yi ⎬
⎨ 1
⎢ x 2 x 3 x 4 ⎥ ⎪a ⎪ ⎪ x 2 y ⎪
⎣ i i i⎦ ⎩ 2⎭ i i⎭
⎩
From the following table:
xi 6.01 N 11
2
x 4.6545
i 5.905
3
x 4.1150 yi 2.1839
i
4
x 3.9161 xi 1.3357
i
yi
Hence the matrix equation becomes: 2
xi yi
⎡ 11 6.01 4.6545⎤ ⎧a0 ⎧ 5.905 ⎫
⎢ ⎫ ⎥ ⎪ ⎪ ⎪ ⎪
6.01 4.6545 4.1150 a 2.1839
⎨ 1⎬ ⎨ ⎬
⎢4.6545 4.1150 3.9161⎥⎥ ⎪a ⎪ ⎪1.3357⎪
⎣ ⎦ ⎩ 2⎭ ⎩ ⎭
a0 0.998 a1 1.018 a2 0.225
Hence, the quadratic function which can represent the data is
f x 0.998 1.018x 0.225x
2
y
1
0.8
fx
0.6
0.4
0.2
0 x
0 0.2 0.4 0.6 0.8 1 1.2
FIGURE 3.9 The fitting of data using a quadratic function
3.6 Multivariable Interpolation
The Newton, Lagrange and spline interpolation method can be applied for
multivariable cases, e.g. for two and three variables:
q
p
y
f pq
x, Lx i L y f xi , y (3.32)
y x
j
i0 j0
p
q r
y z
f pqr
x, y, L xi x L y j
L k
z f xi , y j , (3.33)
z zk
i0 j0 k 0
where
L x
q
x L y y L z
r
z zl
p
xl yl
xi
l 0 xi xl yj
l 0 y j yl zk
l 0 zk zl
l i lj l k
x y
0 1 1 0 1 0 1 0
Example 3.10
Solution
At x 1.0:
i x fxi 0.33 I II
i
1. The fuel consumption of an engine has been recorded as shown in the following table.
Time, Fuel,
hour liter
1.2 0.3320
1
1.7 0.5473
9
1.8 0.6049
6
2.0 0.7389
1
If a user runs the engine for 1.55 hours, determine the estimated fuel consumption using
the Newton and Lagrange interpolation methods.
2. The following data shows the height function of a hill a a distance x from a reference.
Form a cubic polynomial via regression.
xi 0 1 2 3 4 5 6 7 8
hi 4 5 1 1 2 1 1 3 1
0 7 1 6 1
Also, calculate the corresponding standard deviation.
Temperat y coordinate
ur e 0.5 1 1.5 2
T(x,y) . .
0 0
0.5 7.51 10.05 12.7 15.67
x coordinate
0
1.0 10. 10.00 10.0 10.00
00 0
1.5 12. 9.95 7.32 4.33
51
2.0 15. 10.00 5.00 0.00
00
Estimate the temperature at the coordinate (x, y) = (1.15, 1.42) using:
a. the Newton linear interpolation,
b. the Newton cubic interpolation.