0% found this document useful (0 votes)
207 views

Chapter 3

The document discusses various techniques for interpolation and curve fitting of data points, including Newton interpolation, Lagrange interpolation, and spline interpolation. Newton interpolation involves constructing polynomials using finite divided differences of the data points. Higher order polynomials are built from lower order divided differences. The coefficients of the Newton interpolation polynomial provide a general formula for interpolating any order polynomial through a given data set.

Uploaded by

Angel Paguay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views

Chapter 3

The document discusses various techniques for interpolation and curve fitting of data points, including Newton interpolation, Lagrange interpolation, and spline interpolation. Newton interpolation involves constructing polynomials using finite divided differences of the data points. Higher order polynomials are built from lower order divided differences. The coefficients of the Newton interpolation polynomial provide a general formula for interpolating any order polynomial through a given data set.

Uploaded by

Angel Paguay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

3

INTERPOLATION AND CURVE FITTING

 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.

 A general approach is to map the data into an n-th order polynomial:

fn (x)  a0 n
 a1x L x ax
n
(3.1)
an i
i
i0

 This chapter covers three types of techniques, i.e. the Newton interpolation,
the Lagrange interpolation and the Spline interpolation.

 The resulting equation can be used for curve fitting.


3.2 Newton Interpolation: Finite Divided Difference
 For the linear interpolation, consider Fig. 3.1 and the following relation:
f1 x   f x0 
f x1   f x0

x  x0 
x1  x0

f x

f
x

1

f
x
 x
f

0

0
x

1
x

FIGURE 3.1 Linear interpolation

Rearranging the above relation leads to

f x 
f x  f x1   f x0  x
1 0 x    (3.2)
0
x1  x0

The term  f x1   f x0  x1  x0 is referred to as the first-order finite



divided difference.

Example 3.1

Calculate an approximate value of ln 2 using the linear interpolation using


the following ranges: (1,4) and (1,6). Use ln 1  0, ln 4  1.3862944 and
ln 6  1.7917595 as the source data. Estimate the relative error if the actual
value is ln 2  0.69314718.
Solution
For the linear interpolation between x0  1 and x1  6:
1.7917595  0
f 2  0   2 1  0.35835190
1
6 1
This produces a relative error of t  48.3%.
For the linear interpolation between x0  1 dan x1  4:
1.3862944  0
f 2  0   2 1  0.46209812
1
4 1
This produces a relative error of t  33.3%, which smaller than the
previous case.

 For the quadratic interpolation, consider Fig. 3.2 and the following relation:

y
fx 
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

f x2   f x1  f x1   f  x0


x2  x1 
b   (3.4c)
x1  x0
2
x2  x0
Example 3.2

Repeat Example 3.1 using the quadratic interpolation.


Solution
From Example 3.1, the data can be rewritten as followed:
x0  1: f (x0 )  0
x1  4 : f (x1)  1.3862944
x2  6 : f (x2 )  1.7917595
Using Eq. (3.4):
b0  0
1.3862944  0
b  0.46209812
1
4 1
1.7917595 1.3862944 1.3862944  0
6  4 4  1 
b2   0.051873113
6 1
Hence, Eq. (3.3) yields
f2 (x)  0  0.46209812x 1 0.051873113x 1x  4
For x  2:
f 2 2  0  0.462098122  1  0.0518731132  12  4,
 0.56584436.
This produces the relative error t  18.4% as shown below.

y

fx 
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

 The general form representing an n-th order interpolation function (requires


n1 pairs of data) is:

f n  x   b0  b1  x  x0  L bn x  x0 x  x1 L  x 
(3.5)
xn1 

where the coefficients bi can be obtained via

b0 
f  x0 
b1 
f x1 , x0 
b2 
f x2 , x1 , x0 
M
bn 
f xn , xn1 ,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 , xn1 ,K, x2 , x1   f xn1 , xn2 ,K, x1 , (3.6c)
x0 
n n1 1 0
xn  x0

Hence, Eq. (3.5) forms the Newton interpolation polynomial:


f n x   f x0   x  x0  f x1 , x0   x  x0 x  x1  f x2 , x1 , x0 
L x  x  L(x  (3.7)
n1
)f , ,K, x 
0
x0 x1 x x n xn1
TABLE 3.1 Newton finite divided difference interpolation polynomial

i xi fxi  I II III
0 x0 f x0 f x1x0 f x2x1x0 f x3x2x1x0
1 x1 f x1 f x2x1 f x3x2x1
2 x2 f x2 f x3x2
3 x3 f x3

 The relation for error for the n-th order interpolation function can be
estimated using:

Rn 
f xn1 , xn , xn1 ,K, x0  x  x0  x  x1 Lx  (3.8)
xn 

Example 3.3

Repeat Example 3.1 with an additional fourth point of x3  5,


fx3  1.6094379 using the third order Newton interpolation polynomial.
Solution
The third order Newton interpolation polynomial can be written as
f 3 x   b0  b1 x  x0   b2  x  x0  x  x1   b3 x  x0 x  x1 x  x2 

i xi fxi  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.46209812x  1  0.0597386x  1x  4
 0.00786553x  1x  4x  5,
f 3 2  0  0.462098122  1  0.05973862  12  4
 0.007865532  12  42  5,
 0.6287691.
and producing a relative error of t  9.29%.

y

2
fx  l n x

f3x

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

where the parameter Lix is defined as

L x  
xxj
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

 For n  2, the second order Lagrange interpolation can be written as:


 x  x1 x  x2  x  x0 x 
xf 2x   f x   f x 
2  0  1

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 xn1 , xn , xn1 ,K, x0   x  xi (3.11)
n


i0

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

For the first order Lagrange interpolation:


f x  x 
f x  x  f x 
1 x1 
x0
0 1
x0  x1 x1  x0
24 2 1
 f 2  0  1.3862944
1

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  42  6 2  12  6
0  1.3862944
2
1  41  6 4  14  6
2  12  4
 1.7917595
6  16  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.

fx 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 n1 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 xn1   mn1  x  xn1 untuk xn1  x  xn

dengan mi is the gradient for the (i1)-th interval:

f xi1   f xi
m  (3.13)
 i

xi1  xi

Example 3.6

Use the following data to estimate the function fx 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.605  4.5  1.3.

2

fx
4

2
6

FIGURE 3.6 Linear spline interpolation for Example 3.6


8

 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:

1. Continuity at vertices (2n2 equations):

ai1
 bi xi1  ci1  f  xi1
2
xi1 (3.15)

1

2
ax
 b x  c  f x  (3.16)
i i1 i i1 i1

2. Conditions at end points (2 equations):


a x  b x  c  f x 
2
(3.17)
1 0 1 0 1 0

a x  b x  c  f x 
2
(3.18)
n n n n n n

3. Differentiability at vertices (n1 equations):

f x   2ax  b
2ai1xi1  bi1  2aixi1  (3.19)
bi

4. Assumption at the first interval (1 persamaan):


(3.20)
a1  0

fx

0
2 4 6 x 8

FIGURE 3.7 The quadratic spline interpolasi for example 3.7

 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

 The formulation for the cubic spline can be derived as followed:

For interval xi1, xi, the second derivative can be written as:
x
f x   f  x x  f  x  (3.22)
x xi1
i
i i i1
xi1  xi i i xi  xi1

The integration of Eq. (3.22) twice produces two integration constants,


which can be evaluated using f  x   f  xi1  at xi1 and f x   f xi  at xi,
thus produces
f x 
f   xi1 x  x 
3
f   xi   x  x 3
3
i

6 xi  xi1  6xi  xi1 
i
i1
⎡ f xi1  f   xi1  xi  xi1  x
 
⎤
x

x  xi1 
⎣ i 6

⎦i (3.23)

⎡ f xi  f  xi  xi  xi1 ⎤


⎢  x  x 
x  x  6
⎥ i1

⎣ i i1 ⎦
The differentiability can be maintained troughout the function via

f i1 xi   
f i  xi  (3.24)

Eq. (3.23) can be differentiated for both the i1-th and i-th intervals and
following Eq. (3.24):

xi  xi1  f  xi1   2xi1  xi1  f  xi   xi1  xi  f  xi1 


6 6
 xi1  xi  f xi1  f xi    f xi1 f xi (3.25)
  
xi

  xi1 

Example 3.8

Repeat Example 3.6 using the cubic spline interpolation.


Solution
Using Eq. (3.25) for the first interval (i  1):
4.5  3 f  3  27  3 f  4.5  7  4.5 f  7
6
2.5  1 
  2.5  1

 6 
7  4.5 4.5  3
It is known that f  3  0 .
Hence
8 f  4.5 2.5 f  7  9.6
For the second interval (i  2):
2.5 f  4.5 9 f  7  9.6
Both equations is solved simultaneously to yield
f  4.5  1.67909
f  7  1.53308
Using Eq. (3.23) for the first interval:

f31 1.67909
x x  33  2.5 4.5  x
64.5  4.5 

3 3
⎡  1 1.679094.5  3⎤
⎢  x  3,
⎣ 4.5  3 6 ⎥

 0.186566x  3  1.6666674.5  x   0.246894x  3.
3
For the second and third intervals:
f32
x   0.1119397  x 3  0.102205x  4.53  0.2996217  x 
 1.638783x  4.5
f 33  x   0.1277579  x   1.7610279  x   0.25x  7 
3

At x  5, use the function for the second interval:


f32
5  0.1119397  53  0.1022055  4.53  0.2996217  5
 1.6387835  4.5,
 1.102886 .

fx

2
e
Splin
c
Cubi

0
2 4 6 8 x
Interpolation
Lagrange
Cubic Newton/

FIGURE 3.8 The cubic spline interpolation for Example 3.8


3.5 Polynomial Regression
 A “best fit” polynomial of an order lower than the number of intervals is
sometimes required to represent the data and can be evaluated via
polynomial regression.

 Consider the following form of polynomial:

f x  a0
 a1x  a2 x2 L a xnn (3.26)

where the error for the i-th data (xi,yi) is

ey
i i  f x   y   a 
2
a x L a x
n

a i i 0
x1 i 2 i n i

The sum of the squares of error for N data is


N N
xn
S   ei   yi a2 x2 L  a
2
 a0  a1x  (3.27)
i1 i1 i
i n 2
i

These errors can be minimised as followed:


S
 0  2 y   a  a x 2 L a xn   1
N a x
a0 i1
i 0 1 i 2 i n i

S
 0  2 y   a  a x 2 L a xn   x 
N a x
a1 i1
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 i1
i 0 1 i 2 i n i i

producing the following system of equations:

a0 N  a1   a2  x 2 L a  xn   y
xi
i n i i
a  x  a  x   x L 2 3
x
n1
xy
0 i
a a
1 i3 2 i n i i i
a  x  a  x  a  x 4 L
2
 xn2   x2 y
a (3.28)
0 i 1 i 2 n i i i
i
M
a  xn  a  xin1  2  xi n2 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
n1
a ⎪ ⎪
⎢  xi
2 3
x i x i ⎪  xi yi

⎥⎥ ⎪ ⎪
i 1
⎢ x 2  x
4
L x
n2 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
n1
 xi
n2
L ⎭ ⎭
 The standard deviation  for this case can be evaluated as followed:


e
2

 S  i1
(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

Determine a best-fit quadratic equation which can represent the following


experimental data:
xi 0.0 0.1 0.15 0.3 0.4 0.5
5 1 1 6 2
yi 0.9 0.8 0.832 0.7 0.5 0.5
56 90 17 71 39

xi 0.7 0.7 0.82 0.9 1.1


0 4 8 7
yi 0.3 0.3 0.306 0.2 0.1
78 70 42 04

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
fx

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

  
i0 j0

  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
i0 j0 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 lj l k

 For example, Eq. (3.32) can be expanded as


x  x1 y  y1 
f x, y   f x x  x0 y  y1 
,y     f1 x 0, y 
x
x0  x1  y0  y  y  y1
1,1
0 0
1
 x0
1 0

x  x1 y  y0 f ,y x  x0 y  y0 f x , y 



 x 

x  x y x  0 1 x y  1 1

x y
0 1 1 0 1 0 1 0

Example 3.10

The following table show the topology of a 3-D non-planar surface:


y
z  f(x,y)
0.2 0.3 0.4 0.5
1 0.6 1.0 1.3 1.7
. 40 03 59 03
0
x 1 0.9 1.5 2.0 2.5
. 90 24 45 49
5
2 1.5 2.3 3.1 3.9
. 68 84 77 43
0
Use the Newton interpolation to estimate the value of z at the coordinat
(1.6, 0.33). As a comparison, the above data follows the function
f x, y   e sin y  y  0.1, thus f(1.6, 0.33)  1.8350.
x
Chapter 3 Interpolation & Curve Fitting / 20

Solution
At x  1.0:

j yj f1.0, yj I II III


0 0.2 0.640 0.363 0.007 0.005
1 0.3 1.003 0.356 0.012
2 0.4 1.359 0.344
3 0.5 1.703
f1 1.0, y   0.640  0.363 y  0.2   0.007  y  0.2  y  0.3
 0.005y  0.2y  0.3y  0.4,
f1 1.0, 0.33  1.1108 .
At x  1.5:
j yj f1.5, yj I II III
0 0.2 0.990 0.534 0.013 0.004
1 0.3 1.524 0.521 0.017
2 0.4 2.045 0.504
3 0.5 2.549

f1 1.5, y   0.990  0.534 y  0.2   0.013 y  0.2  y  0.3


 0.004y  0.2y  0.3y  0.4,
f1 1.5, 0.33  1.6818 .
At x  2.0:
j yj f2.0, yj I II III
0 0.2 1.568 0.816 0.023 0.004
1 0.3 2.384 0.793 0.027
2 0.4 3.177 0.766
3 0.5 3.943

f1 2.0, y   1.568  0.816 y  0.2   0.023 y  0.2  y  0.3


 0.004y  0.2y  0.3y  0.4,
f1 2.0,0.33  2.6245 .
Next, at y  0.33:

i x fxi 0.33 I II
i

0 1 1.1108 0.57 0.37


. 10 17
0
1 1 1.6818 0.94
. 27
5
2 2 2.6245
.
0
f1,1  x, 0.33  1.1108  0.5710 x  1.0   0.3717 x  1.0 x  1.5 ,
f1,1 1.6, 0.33  1.8406 .
This produces a relative error of t  0.305%.

Exercise

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.

3. The following data represents temperature distribution T(x,y) in a metal plate:

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.

You might also like