0% found this document useful (0 votes)
30 views15 pages

Numerical LectureNote Chap4

Uploaded by

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

Numerical LectureNote Chap4

Uploaded by

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

Numerical Methods

Interpolation

Mikiyas G.

Department of Mathematics
College of Natural Sciences
Arba Minch University
[email protected]

March 22, 2021

Abstract
Module Summary: The purpose of this module is to show you how to
interpolate a given data set using Newton, Lagrange and Spline
interpolations.
Table of Contents

1 Interpolation
Finite Difference Operators
Finite Differences and Interpolating Polynomials
Interpolation with Equal Interval
Interpolation with unequal interval
References

Mikiyas G. (AMU) Numerical Methods 1 / 14


Finite Difference Operators
Let {f0 , f1 , ..., fn } denote the set of values of the function f (x) defined by fi = f (xi ), where, xi = x0 + ih, i = 1, ..., n (equally spaced
data sets), and let I be an identity, then:

∇2 fi = ∇(∇fi )
1. Shift operator (E):
= ∇(fi − fi−1 )
Efi = fi+1 = ∇fi − ∇fi−1
E 2 fi = E(Efi ) = (fi − fi−1 ) − (fi−1 − fi−2 ) (second order at xi ) .
= Efi+1 ... ...
= fi+2 ∇ fi = ∇n−1 fi − ∇n−1 fi−1 (nth order at xi ) .
n

In general,
Remark:
E n fi = fi+n . ∇fi = ∆fi−1 and
∇n fi = ∆n fi−n .
2. Forward Difference Operator (∆):
4. Central Difference operator (δ):
∆fi = Efi − Ifi 1 −1
δ = E2 − E 2
= fi+1 − fi (first order at xi ) . 1 −1
2 δfi = E 2 fi − E 2 fi
∆ fi = ∆(∆fi )
= fi+ 1 − fi− 1 (first order at xi ) .
= ∆(fi+1 − fi ) 2 2

= ∆fi+1 − ∆fi δ 2 fi = δ(δfi )


= (fi+2 − fi+1 ) − (fi+1 − fi ) (second order at xi ) . = δ(fi+ 1 − fi− 1 )
2 2

... ... = δfi+ 1 − δfi− 1


2 2
n n−1 n−1 th
∆ fi = ∆ fi+1 − ∆ fi (n order at xi ) . = (fi+ 1 + 1 − fi+ 1 − 1 ) − (fi− 1 + 1 − fi− 1 − 1 )
2 2 2 2 2 2 2 2

3. Backward Difference Operator (∇): = (fi+1 − fi ) − (fi − fi−1 ) (second order at xi ) .


... ...
∇ = I − E −1
δ n fi = δ n−1 fi+1 − δ n−1 fi− 1 (nth order at xi ) .
∇fi = Ifi − Efi 2

= fi − fi−1 (first order at xi ) . Remark:


δfi+ 1 = δfi = ∇fi+1 .
2

Mikiyas G. (AMU) Numerical Methods 2 / 14


...
The forward, backward and central difference table.
If we take a sample data points {f0 , f1 , f2 , f3 }, the forward, backward and
x f 1st Diff. 2nd Diff. 3rd Diff. central difference tables are as follows.
x0 f0
∆f0 x f 1st Diff. 2nd Diff. 3rd Diff.
x1 f1 ∆2 f0 x0 f0
∆f1 ∆3 f0 ∆f0 = f1 − f0
x2 f2 ∆2 f1 x1 f1 ∆2 f0 = ∆f1 − ∆f0
∆f2 ∆f1 = f2 − f1 ∆3 f0 = ∆2 f1 − ∆2 f0
| {z }
x3 f3 x2 f2 2
∆ f1 = ∆f2 − ∆f1
.. .. | {z }
. . ∆f2 = f3 − f2
xi−2 fi−2 | {z }
δfi− 3 x3 f3
2
|{z}
xi−1 fi−1 δ 2 fi−1
δfi− 1 δ 3 fi− 1 Example 1: Construct a forward difference (∆) table for the following data
2 2
xi fi δ 2 fi δ 4 fi
x 1 2 3 4 5
δfi+ 1 δ 3 fi+ 1
2 2 f (x) 4 13 34 73 136
xi+1 fi+1 δ 2 fi+1
δfi+ 3 sol:
2
xi+2 fi+2
.. .. x f (x) ∆f ∆2 f ∆3 f ∆4 f
. . 1 4
xn−4 fn−4 9
∇fn−3 2 13 12
xn−3 fn−3 ∇2 fn−2 21 6
∇fn−2 ∇3 fn−1 3 34 18 0
xn−2 fn−2 ∇2 fn−1 ∇4 fn 39 6
| {z }
∇fn−1 ∇3 fn 4 73 24
63
| {z }
xn−1 fn−1 ∇2 f
| {z n} 5 136
∇fn
|{z}
xn fn Example 1: Construct backward difference (∇) table for the above data
|{z} (exercise!).

Mikiyas G. (AMU) Numerical Methods 3 / 14


Finite Differences and Interpolating Polynomials
Since polynomial approximations are used in many areas of engineering and
science, it is important to investigate the effects of differencing polynomials. Example: Tabulate f (x) = x3 for x = 5.0(0.1)5.5
Consider the finite differences of an nth degree polynomial
x f (x) = x3 ∆f ∆2 f ∆3 f ∆4 f
f (x) = an xn + an−1 xn−1 + ... + a1 x + a0 (1) 5.0 125.000
7.651
tabulated for equidistant points at tabular interval h, 5.1 132.651 0.306
7.957 0.006
Theorem 5.2 140.608 0.312 0
The nth order difference of polynomial of degree n is a constant proportional to hn 8.269 0.006
and higher order differences are zero. 5.3 148.877 0.318 0
Proof: Omitting the subscript on xj , we have: 8.587 0.006
5.4 157.464 0.324
∆f (x) =f (x + h) − f (x) 8.911
h i
=an [(x + h)n − xn ] + an−1 (x + h)n−1 − xn−1 5.5 166.375

+ ... + a1 [(x + h) − x] In this case, n = 3, an = 1, h = 0.1 and hence:


=an nhxn−1 + Q2 (x), Q2 (x) is polynomial of degree n − 2
h i ∆3 f (x) = (1)(3!)(0.13 ) = 0.006.
∆2 f (x) =an nh (x + h)n−1 − xn−1
Note that round-off error noise may occur.
=an n(n − 1)h2 xn−2 + Q3 (x), Q3 (x) is polynomial of degree n − 3 Example: consider the tabulation of
... f (x) = x3 for x = 5.0(0.1)5.5 rounded to two decimal places:
∆n f (x) =an n(n − 1)(n − 2). . . . (3)(2)(1)(hn ) x f (x) = x3 ∆f ∆2 f ∆3 f ∆4 f ∆5 f
=an n!hn 5.0 125.00
therefore, ∆n+1 f (x) = 0. 7.65
5.1 132.65 0.31
Note: When a polynomial of degree n, pn (x) is fit exactly to a set of (n + 1) 7.96 0.00
discrete data points, (x0 , f0 ), (x1 , f1 ), ..., (xn , fn ) the polynomial has no error at 5.2 140.61 0.31 0.00
the data points themselves. However, at the locations between the data points, 8.27 0.00 0.03
there is an error which is defined by 5.3 148.88 0.31 0.03
8.58 0.03
E(x) = pn (x) − f (x). 5.4 157.46 0.34
8.92
Using Taylor approximation it can be shown that the error term, E(x), has the form 5.5 166.38
1
E(x) = (x − x0 )(x − x1 )...(x − xn )f (n+1) (ξ), x0 ≤ ξ ≤ xn . this tabulation produces a round-off error of 0.03.
(n + 1)!

Mikiyas G. (AMU) Numerical Methods 4 / 14


...
Whenever the higher differences of a table become small (allowing for
round-off error noise), the function represented may be well approximated by a Interpolation
polynomial. There is always a need to approximate functions; for instance,
Example: Consider the difference table of f (x) = ex for x = 0.1(0.05)0.5 to due to:
six significant digits:
1 Given a set of discrete data {(x , y ) /i = 1, 2, ..., n} we
i i
x f (x) = x3 ∆ ∆2 ∆3 ∆4 want to find the relation between xi and yi that can
0.10 1.10517 describe the physical phenomena sufficiently.
2 we may have a function f (x) that is complicated to
0.05666
0.15 1.16183 0.00291 differentiate or integrate, then we can on a given closed
0.05957 0.00015 interval find a simpler function that approximates the
0.20 1.22140 0.00306 -0.00001 differentiation and integration of the complicated function
0.06263 0.00014 f (x).
3 we may want to determine the solution of differential
0.25 1.28403 0.00320 0.00004
0.06583 0.00018 equations, but finding it analytically is difficult, so we find
0.30 1.34986 0.00338 -0.00002 the approximate solution at finite points of the interval
0.06921 0.00016 Interpolation:
0.35 1.41907 0.00354 0.00004 - is the method of estimating unknown values with the help of
0.07275 0.00020 given data sets.
0.40 1.49182 0.00374 -0.00002 - Also interpolation means insertion or filling up intermediate
0.07649 0.00018 terms of the series.
0.45 1.56831 0.00392 - is the technique of obtaining the value of a function
0.08041 fi = f (xi ) for any intermediate values of the independent
variables xi .
0.50 1.64872
- is required in many engineering and science applications
that use tabular data as input.
Since the estimate for round-off error at ∆3 is ±3 × 10−5 , we say that the - An algebraic polynomial is the most simplest function to
third difference are constant with in round-off error and deduce that a cubic be handled in practice.
approximation is appropriate for ex for the range 0.1 < x < 0.5 at interval The process of computing the value of the function f
length 0.05. outside the range of given values of the variable x is called
caution: Sometimes polynomial approximation is inappropriate. It should also extrapolation.
be understood that there exist functions that can’t usefully be tabulated at all.

Mikiyas G. (AMU) Numerical Methods 5 / 14


Interpolation with Equal Interval
1.Newton Interpolating Polynomial
Similarly by putting x = x3 , x = x4 , ..., x = xn in Eq., (2) we get
a. Newton Forward Interpolation Formula: Let y = f (x) be a function
which takes the values y0 , y1 , y2 , ..., yn corresponding to the (n + 1) values ∆3 y0 ∆4 y0 ∆n y0
a3 = , a4 = , ..., an =
x0 , x1 , x2 , ..., xn of the independent variable x. Let the values x be equally 3!h3 4!h4 n!hn
spaced, i.e.,
xi = x0 + ih, i = 1, 2, ..., n putting the values of a0 , a1 , ..., an in Eq., (2) we get

where h is the step size. Let pn (x) be a polynomial of the nth degree in x ∆y0 ∆2 y0
f (x) ≈ pn (x) =y0 + (x − x0 ) + (x − x0 )(x − x1 )
taking the same values as y corresponding to x = xi , then, pn (x) represents h 2!h2
the continuous function y = f (x) such that f (xi ) = pn (xi ) for ∆3 y0
+ (x − x0 )(x − x 1 )(x − x2 ) + ...
i = 0, 1, 2, ..., n and at all other points f (x) = pn (x) + R(x) where R(x) is 3!h3
called the error term (Remainder term) of the interpolation formula. ∆n y0
+ n
(x − x0 )(x − x1 )(x − x2 )...(x − xn−1 ). (3)
Ignoring the error term let us assume n!h
x−x0
f (x) ≈ pn (x) ≈a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + . . . Writing u = h , we get
+an (x − x0 )(x − x1 ) . . . (x − xn−1 ) (2) x − x0 = uh
the constants a0 , a1 , ..., an can be determine as: x − x1 = x − x0 + x0 − x1
Putting x = x0 in Eq., (2) we get = x − x0 − (x1 − x0 )
= uh − h
f (x0 ) ≈p0 (x0 ) = a0
= h(u − 1)
⇒y0 = a0
Similarly
Putting x = x1 in Eq., (2) we get x − x2 = h(u − 2)
x − x3 = h(u − 3)
f (x1 ) ≈p1 (x1 ) = a0 + a1 (x1 − x0 ) = y0 + a1 h
...
⇒y1 = y0 + a1 h
x − xn−1 = h(u − n + 1)
y1 − y0 ∆y0
⇒a1 = = .
h h Now, Eq., (3) can be written as
Putting x = x2 in Eq., (2) we get
∆y0 ∆2 y0
pn (x) =y0 + u + u(u − 1)
f (x2 ) ≈p2 (x2 ) = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 ) 1! 2!
∆ n y0
∆y0 + ... + u(u − 1)...(u − n + 1) . (4)
⇒y2 = y0 + (2h) + a2 (2h)(h). n!
h
⇒y2 = y0 + 2(y1 − y0 ) + a2 (2h2 ) The above formula is called Newton’s forward interpolation formula.
y2 − 2y1 + y0 ∆ 2 y0 Note: Newton forward interpolation formula is used to interpolate the values of y
⇒a2 = = . near the beginning of a set of tabular values.
2h2 2!h2

Mikiyas G. (AMU) Numerical Methods 6 / 14


...
Example 1: Evaluate y = e2x for x = 0.05 using the following table
2. Newton Backward Interpolation Formula: Let y = f (x) be a function which takes
x 0.00 0.10 0.20 0.30 0.40
the values y0 , y1 , y2 , ..., yn corresponding to the (n + 1) values x0 , x1 , x2 , ..., xn of the
y = e2x 1.000 1.2214 1.4918 1.8221 2.25513
independent variable x. Let the values x be equally spaced, i.e.,
sol: The difference table is: xi = x0 + ih, i = 1, 2, ..., n
x y = e2x ∆y ∆2 y ∆3 y ∆4 y
where h is the step size. Let pn (x) be a polynomial of the nth degree in x taking the
0.000 1.0000
same values as y corresponding to x = xi , then, pn (x) represents the continuous function
0.2214
y = f (x) such that f (xi ) = pn (xi ) for i = 0, 1, 2, ..., n and at all other points
0.10 1.2214 0.0490
f (x) = pn (x) + R(x) where R(x) is called the error term (Remainder term) of the
0.2704 0.0109
interpolation formula. Ignoring the error term let us assume
0.20 1.4918 0.0599 0.0023
0.3303 0.0132 f (x) ≈ pn (x) ≈an + an−1 (x − xn ) + an−2 (x − xn )(x − xn−1 ) + . . .
0.30 1.8221 0.0731
+a0 (x − xn )(x − xn−1 ) . . . (x − x1 ) (5)
0.4034
0.40 2.2255 the constants a0 , a1 , ..., an can be determine as:
Putting x = xn in Eq., (5) we get
Here we have, x0 = 0.00, x = 0.05, h = 0.1.
Therefore, u = x−x
h =
0 0.05−0.00
0.1 = 0.5. f (xn ) ≈p0 (xn ) = an
Using Newton’s forward formula
⇒yn = an
∆y0 ∆2 y0
f (x) =y0 + u+ u(u − 1) Putting x = xn−1 in Eq., (5) we get
1! 2!
∆3 y0 f (xn−1 ) ≈p1 (xn−1 ) = an + an−1 (xn−1 − xn ) = yn + an−1 (−h)
+ u(u − 1)(u − 2)
3!
⇒yn−1 = yn + an−1 (−h)
∆4 y0
+ u(u − 1)(u − 2)(u − 3) + ... yn−1 − yn −∇yn ∇yn
4! ⇒an−1 = = = .
0.0490 −h −h h
f (0.05) ≈1.000 + 0.5 × 0.2214 + 0.5(0.5 − 1)
2 Putting x = xn−2 in Eq., (5) we get
00109
+ 0.5(0.5 − 1)(0.5 − 2)
6 f (xn−2 ) ≈p2 (xn−2 ) = an + an−1 (xn−2 − xn ) + an−2 (xn−2 − xn )(xn−2 − xn−1 )
00023
+ 0.5(0.5 − 1)(0.5 − 2)(0.5 − 3) yn−1 − yn
24 ⇒yn−2 = yn + (−2h) + an−2 (−2h)(h).
−h
= 1.0000 + 0.1107 − 0.006125 + 0.000681 − 0.000090 = 1.105166
⇒yn−2 = yn + 2(yn−1 − yn ) + an−2 (2h2 )
⇒ f (0.05) ≈1.1052
yn−2 − 2yn−1 + yn ∇ 2 yn
⇒an−2 = = .
Example 2: Find the second degree polynomial which passes through the points (1, -1), 2h2 2!h2
(2, -1), (3, 1),(4, 5). (exercise!)

Mikiyas G. (AMU) Numerical Methods 7 / 14


...
Similarly by putting x = xn−3 , x = xn−4 , ..., x = x0 in Eq., (5) we get The difference table is:

∇3 yn ∇ 4 yn ∇ n yn x f (x) ∇y ∇2 y ∇3 y ∇4 y
an−3 = , an−4 = , ..., a0 =
3!h3 4!h4 n!hn 80 5026
648
putting the values of a0 , a1 , ..., an in Eq., (5) we get
85 5674 40
∇yn ∇ 2 yn 688 -2
f (x) ≈ pn (x) =yn + (x − xn ) + (x − xn )(x − xn−1 ) 90 6362 38 4
h 2!h2
∇ 3 yn 726 2
+ 3
(x − xn )(x − xn−1 )(x − xn−2 ) + ... 95 7088 40
3!h
∇ n yn 766
+ (x − xn )(x − xn−1 )(x − xn−2 )...(x − x1 ). (6) 100 7854
n!hn
x−xn Here we have, xn = 100, x = 105, h = 5.
Writing u = h , we get
yn = 7854, ∇yn = 766, ∇2 yn = 40, ∇3 yn = 2, ∇4 yn = 4.
x − xn = uh Therefore, u = x−x
h
n
= 105−100
5 = 1.
x − xn−1 = x − xn + xn − xn−1 Now on applying Newton’s backward difference formula, we have
= x − xn − (xn−1 − xn ) ∇yn ∇ 2 yn
= uh + h f (105) =yn + u + u(u + 1)
1! 2!
= h(u + 1) ∇ 3 yn ∇4 yn
+ u(u + 1)(u + 2) + u(u + 1)(u + 2)(u + 3) .
Similarly 3! 4!
40
x − xn−2 = h(u + 2) f (105) ≈7854 + 1 × 766 + 1(1 + 1)
2
x − xn−3 = h(u + 3) 2
+ 1(1 + 1)(1 + 2)
... 6
x − x1 = h(u + (n + 1)) 4
+ 1(1 + 1)(1 + 2)(1 + 3)
24
Now, Eq., (6) can be written as = 7854 + 766 + 40 + 2 + 4 = 8666
⇒ f (105) ≈8666
∇yn ∇ 2 yn
pn (x) =yn + u + u(u + 1)
1! 2! c. Error in the Interpolation Formula
∇ n yn
+ ... + u(u + 1)...(u + (n − 1)) . (7) If R(x) denotes the error in the formula then R(x) = f (x) − Pn (x). Show that error in the
n! forward interpolation formula is:
The above formula is called Newton’s backward interpolation formula.
∆n+1 y0
Note: R(x) = u(u − 1)(u − 2)...(u − n)
(n + 1)!
It is useful for interpolating near the end of the tabular values.
Example 1. Calculate the value of f (105) for the table: and the error in the Newton backward interpolation formula is:

∇n+1 yn
x 80 85 90 95 100 R(x) = u(u + 1)(u + 2)...(u + n), where , uh = x − xn .
f (x) 5026 5674 6362 7088 7854 (n + 1)!

proof (exercise!)
sol: 105 is near to the end of the table, we use Newton’s backward formula to find f (105).

Mikiyas G. (AMU) Numerical Methods 8 / 14


Interpolation with unequal interval
Definition
A. Lagrange’s Interpolation Formula n
X
Suppose on an interval [a, b] n + 1 points, x0 , x1 , x2 , ..., xn are specified, we Pn (x) = fi Li (x) is called Lagrange’s form of interpolation polynomial.
call them mesh points and the values of some function at these points are i=0
f (xi ) = fi , for i = 0, 1, ..., n. It is required to construct a unique polynomial where,
of degree n, pn (x) that assumes the same values as f (x) at the mesh points n 
and approximates f (x) at x 6= xi . Y (x − xj ) 1 if i = j,
Li (x) = and Li (xj ) =
(xi − xj ) 0 if i 6= j,
j=0,j6=i
1 Linear polynomial: given (x0 , y0 ) and (x1 , y1 ), we construct a
polynomial passing through these points to approximate f (x) at x 6= xi . Example 1. Use the Lagrange interpolation formula to find a polynomial P3 (x)
for i = 0, 1, where f (x0 ) = y0 and f (x1 ) = y1 which passes through (0, 3), (1, 2), (2, 7), (4, 59) and approximate f (3).
Sol:
(x − x1 ) (x − x0 )
p1 (x) = f0 + f1 3
x0 − x1 x1 − x0 X
P3 (x) = fi Li (x) = 3L0 + 2L1 + 7L2 + 59L3
Hence, p1 (x) is the required polynomial to approximate, where i=0
p1 (x0 ) = f0 and p1 (x1 ) = f1 (x − x1 )(x − x2 )(x − x3 )
L0 (x) =
2 Quadratic polynomial: consider the quadratic polynomial (x0 − x1 )(x0 − x2 )(x0 − x3 )
(x − 1)(x − 2)(x − 4) −1 3
p2 (x) = L0 (x)f0 + L1 (x)f1 + L2 (x)f2 = = (x − 7x2 + 14x − 8)
(0 − 1)(0 − 2)(0 − 4) 8
with (x − x0 )(x − x2 )(x − x3 )
L1 (x) =
(x1 − x0 )(x1 − x2 )(x1 − x3 )
(x − x1 )(x − x2 ) (x − 0)(x − 2)(x − 4) 1
L0 (x) = = = (x3 − 6x2 + 8x)
(x0 − x1 )(x0 − x2 ) (1 − 0)(1 − 2)(1 − 4) 3
(x − x0 )(x − x2 ) (x − x0 )(x − x1 )(x − x3 )
L1 (x) = L2 (x) =
(x1 − x0 )(x1 − x2 ) (x2 − x0 )(x2 − x1 )(x2 − x3 )
(x − x0 )(x − x1 ) (x − 0)(x − 1)(x − 4) −1 3
L2 (x) = = = (x − 5x2 + 4x)
(x2 − x0 )(x2 − x1 ) (2 − 0)(2 − 1)(2 − 4) 4
and look at the interpolation basis L0 (x), L1 (x) and L2 (x) each (x − x0 )(x − x1 )(x − x2 )
L3 (x) =
polynomial Li (x) has degree two, hence p2 (x) has degree two. (x3 − x0 )(x3 − x1 )(x3 − x2 )
3 Higher degree interpolation: Theorem If x0 , x1 , ..., xn are distinct (x − 0)(x − 1)(x − 2) 1
= = (x3 − 3x2 + 2x)
points and f is a function whose values are given at these points then (4 − 0)(4 − 1)(4 − 2) 24
there exists a unique polynomial p0 of degree at most n with the ⇒ P3 (x) = 3L0 + 2L1 + 7L2 + 59L3
property that pn (xi ) = f (xi ), for i = 0, 1, 2, ..., n.
= x3 − 2x + 3
proof: (exercise!)
and f (3) ≈ P3 (3) = 24.

Mikiyas G. (AMU) Numerical Methods 9 / 14


...
Example 1. construct a divided difference table from the following data
B. Newton’s Divided Difference Interpolation Formula
x 0 1 3 6 10
Divided Differences: suppose the function f (x) is tabulated at the (not necessarily f (x) 1 -6 4 169 921
equidistant) points {x0 , x1 , ..., xn }, and Suppose that Pn (x) is the nth Lagrange polynomial that
agrees with the function f at the distinct numbers {x0 , x1 , ..., xn },. The divided differences of f sol: the divided difference table is:
with respect to {x0 , x1 , ..., xn }, are used to express Pn (x) in the form:
x f (x) 1st 2nd 3rd 4th
Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + ... + an (x − x0 )(x − x1 )...(x − xn−1 ) (8) 0 1
-7
with a0 = Pn (x0 ) = f (x0 ) = f [x0 ], then: 1 -6 4
1 First divided difference of f (say between x0 and x1 ) is defined as 5 1
3 4 10 0
f (x1 ) − f (x0 ) 55 1
a1 = f [x0 , x1 ] =
x1 − x0 6 169 19
188
2 Second divided difference (say between x0 , x1 and x2 ) is defined as
10 921
f [x1 , x2 ] − f [x0 , x1 ]
a2 = f [x0 , x1 , x2 ] = Example 2. Form the Newton’s Divided Difference formula for the ff data and
x2 − x0
evaluate f (0.5).
As might be expected from the evaluation of a0 , a1 and a2 , the required constants are:
xi 0 1 2 5
f [x1 , x2 , .., xk ] − f [x0 , x1 , ..., xk−1 ] f (xi ) 2 3 12 147
ak = f [x0 , x1 , ..., xk ] = , k = 0, 1, ..., n
xk − x0
sol: the divided difference table is:
Hence, the interpolating polynomial in Eq. (8) can be rewritten in a form called Newton’s
Divided- Difference: xi f (xi ) f [xi , xi+1 ] f [xi , xi+1 , xi+2 ] f [xi , xi+1 , xi+2 , xi+3 ]
n
X 0 2
Pn (x) = f [x0 ] + f [x0 , x1 , ..., xk ] (x − x0 )(x − x1 )...(x − xk−1 ) (9) 1
k=1 1 3 4
9 1
The generation of Newton’s Divided Difference can be outlined as in the ff table:
2 12 9
xi f (xi ) f [xi , xi+1 ] f [xi , xi+1 , xi+2 ] f [xi , xi+1 , xi+2 , xi+3 ] 45
5 147
x0 f [x0 ]
f [x0 , x1 ] Here We have x0 = 0, f [x0 ] = 2, f [x0 , x1 ] = 1, f [x0 , x1 , x2 ] = 4, f [x0 , x1 , x2 , x3 ] = 1.
x1 f [x1 ] f [x0 , x1 , x2 ] The Newton’s divided difference interpolation formula is
f [x1 , x2 ] f [x0 , x1 , x2 , x3 ]
x2 f [x2 ] f [x1 , x2 , x3 ] f (x) = f [x0 ] + f [x0 , x1 ](x − x0 ) + f [x0 , x1 , x2 ](x − x0 )(x − x1 )
f [x2 , x3 ] + f [x0 , x1 , x2 , x3 ](x − x0 )(x − x1 )(x − x2 )
x3 f [x3 ]
= 2 + 1(x − 0) + 4(x − 0)(x − 1) + 1(x − 0)(x − 1)(x − 2)
⇒ f (x) = x3 + x2 − x + 2.

Mikiyas G. (AMU) Numerical Methods 10 / 14


...
C.Spline Interpolation (Reading Ass.)
Example: The upward velocity of a rocket is given as a function of time in the table below. Find
the velocity at time t = 16 seconds.
It is often possible to have measurements that contain many peaks and dips.
One way to handle such kind of rapidly varying measurements is to fit the function
locally and to connect each piece of the function smoothly.
Spline is a method of interpolating suck kind of measurements locally through a
polynomial and fits the data overall by connecting each segment of the
interpolating polynomial by matching the function and its derivatives at the data
points.
a. Linear Spline Interpolation: The simplest piecewise-polynomial approximation is
linear spline interpolation,which consists of joining a set of data points

(x0 , f (x0 )), (x1 , f (x1 )), ..., (xn , f (xn ))

by a series of straight lines, as shown in the ff Figure.

b. Cubic Spline Interpolation:


The basic idea of the cubic spline is that it represents by different cubic function on each interval
between data points. The essential idea is to fit a piecewise function, if there are n data points,
then S(x) is the function:-


 s1 (x), x1 ≤ x ≤ x2
 s2 (x), x2 ≤ x ≤ x3



S (x) = s3 (x), x3 ≤ x ≤ x4
 ...




sn−1 (x), xn−1 ≤ x ≤ xn

The essential idea is to fit a piecewise-linear function, if there are n data points, then where each si (x) is a cubic functions (third degree polynomial).
f (x) is the function:- Definition: Given a function f defined on [a, b] and a set of nodes x0 < x1 < ... < xn ,a cubic
yn − yn−1 spline interpolant S for f is a function that satisfies the following conditions:
f (x) = yn−1 + (x, xn−1 ), xn−1 ≤ x ≤ xn , n = 1, 2, 3...
xn − xn−1 1 The piecewise function S(x) will interpolate all the data points [xi , xi+1 ] for
i = 0, 1, ..., n − 1.
from this, 2 si (xi ) = yi , i = 0, 1, ..., n,
the first linear spline is 3 si (xi+1 ) = si+1 (xi+1 ), i = 0, 1, ..., n − 2,
y1 − y0 4 s0i (xi+1 ) = s0i+1 (xi+1 ), i = 0, 1, ..., n − 2,
f (x) = y0 + (x, x0 ), x0 ≤ x ≤ x1 5 s00i (xi+1 ) = s00i+1 (xi+1 ), i = 0, 1, ..., n − 2
x1 − x0
6 One of the following boundary condition is satisfied
and the second linear spline is 1 s00 (x0 ) = s00 (xn ) = 0, (free or natural boundary)
2 s0 (x0 ) = y00 and s0 (xn ) = yn0 , (clamped boundary.)
y2 − y1
f (x) = y1 + (x, x1 ), x1 ≤ x ≤ x2
x2 − x1

Mikiyas G. (AMU) Numerical Methods 11 / 14


...
Construction:
1 Ni 2
si (xi+1 ) = (Ni+1 − Ni )h3i + h + ci hi + si (xi )
The most general cubic function has the form: 6hi 2 i
3 2 h2i 3
si (x) = ai (x − xi ) + bi (x − xi ) + ci (x − xi ) + di , i = 1, 2, ..., n − 1. (10) ⇒ si (xi+1 ) − si (xi ) = (Ni+1 + 2Ni )hi + ci hi .
6
The first and second derivatives of si (x) are: And

s0i (x) = 3ai (x − xi )2 + 2bi (x − xi ) + ci (11) si (xi+1 ) − si (xi ) hi


ci = − (Ni+1 + 2Ni )
hi 6
and
s00i (x) = 6ai (x − xi ) + 2bi (12) However, by equation (11) we have:
Because of s0i (xi ) = ci ,
xi ∈ [xi , xi+1 ] , S(xi ) = si (xi ) si (xi+1 ) − si (xi ) hi
= − (Ni+1 + 2Ni )
and we can use equation (10) to give hi 6

si (xi ) = ai (xi − xi )3 + bi (xi − xi )2 + ci (xi − xi ) + di . The final relationship involving the coefficients is obtained by

= di (13) s0i−1 (xi ) = 3ai−1 h2i−1 + 2bi hi−1 + ci−1

when x = xi+1 , we have: By substituting the values of ai−1 , bi−1 and ci−1 in the above equation we have

si (xi+1 ) = ai (xi+1 − xi )3 + bi (xi+1 − xi )2 + ci (xi+1 − xi ) + di , (14) 1 Ni−1


s0i−1 (xi ) = 3 (Ni − Ni−1 )h2i−1 + 2 hi−1
6hi 2
Letting hi = xi+1 − xi , and Ni = s00i (xi ) then we will have si−1 (xi ) − si−1 (xi−1 ) hi−1
+ − (Ni + 2Ni−1 ).
hi−1 6
si (xi+1 ) = ai h3i + bi h2i + ci hi + di . (15)
After simple simplification, we have:
and
si−1 (xi ) − si−1 (xi−1 ) 2Ni + Ni−1
Ni = s00i (xi ) = 2bi s0i−1 (xi ) = + hi−1 .
hi−1 6
Ni
⇒bi = . Since s0i−1 (xi ) = ci , then
2
When x = xi+1 , ci = 3ai−1 h2i−1 + 2bi hi−1 + ci−1 . (16)

Ni+1 = s00i (xi+1 ) By substituting the values of ai−1 , bi−1 , ci−1 and ci in Eq. (16), we have:
= 6ai (xi+1 − xi ) + 2bi
si (xi+1 ) − si (xi ) Ni+1 + 2Ni
= 6ai hi + Ni ci−1 = + hi
hi 6
Ni+1 − Ni si−1 (xi ) − si−1 (xi−1 ) 2Ni + Ni−1
⇒ai = = + hi−1 . (17)
6hi hi−1 6
Now substituting the values of ai , bi &di to Eq. 15, we have:
for every i = 1, 2, ..., n.

Mikiyas G. (AMU) Numerical Methods 12 / 14


...
Rearranging this substitution and ci can be re-written from the equation
(17) as a form of Ni and yi as:
substitute the values from the table and N0 = 0 = N3 we have:
hi−1 hi + Ni−1 hi yi+1 − yi yi − yi−1
Ni−1 + Ni + Ni+1 = − . (18) 6
6 3 6 hi hi−1 4N1 + N2 = (33 − 2(2) + 1)
12
For equally spaced data hi = h, the condition for Ni and the cubic spline 6
N1 + 4N2 = 2 (244 − 2(33) + 2)
interpolation are: 1
⇒N1 = −24&N2 = 276.
6
Ni−1 + 4Ni + Ni+1 = (yi+1 − 2yi + yi−1 ) , i = 1, .., n − 1 (19)
h2
1 h i
and s0 (x) = (x1 − x)3 N0 + (x − x0 )3 N1
6h
2
 
1 h i 1 h
si (x) = (xi+1 − x)3 Ni + (x − xi )3 Ni+1 + (x1 − x) y0 − N0
6h h 6
h2
 
1 h2
 
1
+ (xi+1 − x) yi − Ni + (x − x0 ) y1 − N1
h 6 h 6
h2
 
1 1 h i
+ (x − xi ) yi+1 − Ni+1 .i = 0, 1, .., n − 1. (20) = (1 − x)3 (0) + (x − 0)3 (−24)
h 6 6h
12
 
1
Remark: N0 = Nn = 0 (Free or Natural spline) and this one is the most + (1 − x) 1 − (0)
h 6
common boundary condition (i.e, second derivative be equal to zero at the
12
 
1
endpoints.) + (x − 0) 2 − (−24)
1 6
Example: Construct a natural cubic spline that interpolates the data points:
= 4x3 + 5x + 1 for 0 ≤ x ≤ 1.
x 0 1 2 3
f (x) 1 2 33 244 similarly, we can solve for s1 (x) and s2 (x) and The natural cubic spine is
described piecewise by
with N0 = N3 and estimate f (2.5).
 4x3 + 5x + 1forx ∈ [0, 1],

Solution: Here, We have h = 1 and n = 3, therefore i = 1, 2.
S (x) = 50x3 − 162x2 + 167x − 53forx ∈ [1, 2],
6 −46x3 + 414x2 − 985x + 715forx ∈ [2, 3].

N0 + 4N1 + N2 = (y2 − 2y1 + y0 )
12 ⇒ s2 (2.5) ≈ f (2.5) = 121.25.
6
N1 + 4N2 + N3 = 2 (y3 − 2y2 + y1 )
1

Mikiyas G. (AMU) Numerical Methods 13 / 14


References
Jaan Kiusalaas, Numerical Methods in Engineering with MATLAB, first
edition, 2005.
Ralston, Antony, A first course in Numerical Analysis (2nd ed), Feb,6,2001
Recktenwald, Gerald. Numerical Methods with MATLAB, prentice Hall, 2000.

Mikiyas G. (AMU) Numerical Methods 14 / 14

You might also like