1
College of Engineering
Bio. Eng. Dept.
Subject: Numerical Analysis
Third Stage
Lecturer : Zaher M.Abed Lecture 5
2
Chapter Two
Interpolation and Curve Fitting
Introduction 3
The word interpolation refers to approximating , predicting, or estimating some unknown
information from a given set of known information. The technique of interpolation is widely
used as a valuable tool in science and engineering. The problem is a classical one and dates
back to the time of Newton and Kepler, who needed to solve such a problem in analyzing data
on the position of stars and planets.
Mathematical applications of interpolation include derivation of computational techniques for
Numerical differentiation , Numerical integration, and Numerical solutions of differential
equations.
Definition 1
Estimating intermediate values between precise data points.
4
We first fit a function that exactly passes through the given data points and than evaluate intermediate
values using this function.
•Polynomial Interpolation: A unique 𝑛𝑡ℎ order polynomial passes through n points.
I. Lagrange Interpolating Polynomials
II. Newton’s Divided Difference Interpolating Polynomials
•Spline Interpolation: Pass different curves (mostly 3rd order) through different subsets of the data
points.
1.Lagrange’s interpolation formula 5
Let 𝑦 = 𝑓( 𝑥) be a function such that 𝑓( 𝑥) takes the values 𝑦0 , 𝑦1 , 𝑦2 , … … . , 𝑦𝑛 corresponding to
𝑥 = 𝑥0 , 𝑥1 , 𝑥2 … , 𝑥𝑛 That is 𝑦𝑖 = 𝑓(𝑥𝑖 ), 𝑖 = 0,1,2, … , 𝑛 .
Now, there are (𝑛 + 1) paired values (𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0, 1, 2, … , 𝑛 and hence 𝑓 ( 𝑥) can be represented
by a polynomial function of degree n in 𝑥.
Then the Lagrange’s formula is
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 ) (𝑥 − 𝑥0 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛 )
𝑦 = 𝑓(𝑥) = 𝑦0 + 𝑦
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 ) … (𝑥0 − 𝑥𝑛 ) (𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 ) … (𝑥1 − 𝑥𝑛 ) 1
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) … (𝑥 − 𝑥𝑛−1 )
+. . + 𝑦 … … . (1)
(𝑥𝑛 − 𝑥0 )(𝑥𝑛 − 𝑥1 ) … (𝑥𝑛 − 𝑥𝑛−1 ) 𝑛
(prove that 𝒆𝒒𝒖𝒂𝒕𝒊𝒐𝒏 (𝟏) ?)
Example:
Using Lagrange’s interpolation formula find 𝑦(10) from the following table: 6
𝑥 5 6 9 11
𝑦 12 13 14 16
Solution: Here the intervals are unequal. By Lagrange’s interpolation formula we have
𝑥0 = 5, 𝑥1 = 6, 𝑥2 = 9, 𝑥3 = 11
𝑦0 = 12, 𝑦1 = 13, 𝑦2 = 14, 𝑦3 = 16
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 ) (𝑥 − 𝑥0 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 )
𝑦 = 𝑓(𝑥) = × 𝑦0 + × 𝑦1
(𝑥0 − 𝑥1 )(𝑥0 − 𝑥2 )(𝑥0 − 𝑥3 ) (𝑥1 − 𝑥0 )(𝑥1 − 𝑥2 )(𝑥1 − 𝑥3 )
(𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥3 ) (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )
+ × 𝑦2 + × 𝑦3
(𝑥2 − 𝑥0 )(𝑥2 − 𝑥1 )(𝑥2 − 𝑥3 ) (𝑥3 − 𝑥0 )(𝑥3 − 𝑥1 )(𝑥3 − 𝑥2 )
(𝑥 − 6)(𝑥 − 9)(𝑥 − 11) (𝑥 − 5)(𝑥 − 9)(𝑥 − 11)
= (12) + (13)
(5 − 6)(5 − 6)(5 − 11) (6 − 5)(6 − 9)(6 − 9)
(𝑥 − 5)(𝑥 − 6)(𝑥 − 11) (𝑥 − 5)(𝑥 − 6)(𝑥 − 9)
+ (14) + (16)
(9 − 5)(9 − 6)(9 − 11) (11 − 5)(11 − 6)(11 − 9)
4(1)(−1) (5)(1)(−1) 5(4)(−1) (5)(4)(1)
𝑷𝒖𝒕 𝒙 = 𝟏𝟎 y(10) = 𝑓(10) = (12) + (13) + (14) + (16)
(−1)(−4)(−6) (1)(−3)(−5) 4(3)(−2) 6(5)(2)
1 13 5(14) 4 × 16
= (12) − + +
6 3 3×2 12
= 14.6663
2.Newton’s Gregory forward interpolation formula 7
Let 𝑦 = 𝑓 ( 𝑥) denote a polynomial of degree n which takes (𝑛 + 1) values. Let them be
𝑦0 , 𝑦1 , 𝑦2 , … 𝑦𝑛 corresponding to the values 𝑥 , 𝑥 , … 𝑥𝑛 respectively.
The values of (𝑥0 , 𝑥1 , 𝑥2 , … 𝑥𝑛 ) are at equidistant.
(i.e.) 𝑥1 = 𝑥0 + ℎ, 𝑥2 = 𝑥0 + 2ℎ, 𝑥3 = 𝑥0 + 3ℎ, … 𝑥𝑛 = 𝑥0 + 𝑛ℎ,
Then the value of 𝑓(𝑥) 𝑎𝑡 𝑥 = 𝑥0 + 𝑛ℎ is given by
𝑛 𝑛(𝑛 − 1) 2 𝑛(𝑛 − 1)(𝑛 − 2) 3
𝑓(𝑥0 + 𝑛ℎ) = 𝑓(𝑥0 ) + Δ𝑓(𝑥0 ) + Δ 𝑓(𝑥0 ) + Δ 𝑓(𝑥0 ) + ⋯
1! 2! 3!
or
𝑛 𝑛(𝑛 − 1) 2 𝑛(𝑛 − 1)(𝑛 − 2) 3 𝑥 − 𝑥0
𝑦(𝑥=𝑥0+𝑛ℎ) = 𝑦0 + Δ𝑦0 + Δ 𝑦0 + Δ 𝑦0 + ⋯ where 𝑛 =
1! 2! 3! ℎ
3.Newton’s Gregory backward interpolation formula 8
Newton’s forward interpolation formula cannot be used when the value of y is required near the end of the table.
For this we use another formula, called Newton’s Gregory backward interpolation formula.
Then the value of 𝑓(𝑥) 𝑎𝑡 𝑥 = 𝑥𝑛 + 𝑛ℎ is given by
𝑛 𝑛(𝑛 + 1) 2 𝑛(𝑛 + 1)(𝑛 + 2) 3
𝑓(𝑥𝑛 + 𝑛ℎ) = 𝑓(𝑥𝑛 ) + 𝛻𝑓(𝑥𝑛 ) + 𝛻 𝑓(𝑥𝑛 ) + 𝛻 𝑓(𝑥𝑛 ) + ⋯
1! 2! 3!
or
𝑛 𝑛(𝑛 + 1) 2 𝑛(𝑛 + 1)(𝑛 + 2) 3 𝑥 − 𝑥𝑛
𝑦(𝑥=𝑥𝑛+𝑛ℎ) = 𝑦𝑛 + 𝛻𝑦𝑛 + 𝛻 𝑦𝑛 + 𝛻 𝑦𝑛 + ⋯ when 𝑛 =
1! 2! 3! ℎ
Difference Table 9
1. Forward Difference Tables
Forward differences are now defined as follows:
Δ0 𝑓𝑖 ≡ 𝑓𝑖 (Zeroth order forward difference)
Δ𝑓𝑖 ≡ 𝑓𝑖+1 − 𝑓𝑖 (First order forward difference)
Δ2 𝑓𝑖 ≡ Δ𝑓𝑖+1 − Δ𝑓𝑖 Second order forward difference
⟹ Δ2 𝑓𝑖 = (𝑓𝑖+2 − 𝑓𝑖+1 ) − (𝑓𝑖+1 − 𝑓𝑖 ) ⟹ Δ2 𝑓𝑖 = 𝑓𝑖+2 − 2𝑓𝑖+1 + 𝑓𝑖
Δ3 𝑓𝑖 ≡ Δ2 𝑓𝑖+1 − Δ2 𝑓𝑖 (Third order forward difference
⟹ Δ3 𝑓𝑖 = (𝑓𝑖+3 − 2𝑓𝑖+2 + 𝑓𝑖+1 ) − (𝑓𝑖+2 − 2𝑓𝑖+1 + 𝑓𝑖 ) ⟹ Δ3 𝑓𝑖 = 𝑓𝑖+3 − 3𝑓𝑖+2 + 3𝑓𝑖+1 − 𝑓𝑖
Δ𝑘 𝑓𝑖 = Δ𝑘−1 𝑓𝑖+1 − Δ𝑘−1 𝑓𝑖 (𝑘 𝑡ℎ order forward difference)
Typically we set up a difference table
Difference Table 10
2. Newton Backward Interpolation
Newton backward interpolation is essentially the same as Newton forward interpolation
except that backward differences are used
Backward differences are defined as:
𝛻 𝑜 𝑓𝑖 ≡ 𝑓𝑖 (Zeroth order backward difference)
𝛻𝑓𝑖 = 𝑓𝑖 − 𝑓𝑖−1 (First order backward difference)
𝛻 2 𝑓𝑖 = 𝛻𝑓𝑖 − 𝛻𝑓𝑖−1 Second order backward difference
𝛻𝑘 𝑓𝑖 = 𝛻𝑘−1 𝑓𝑖 − 𝛻𝑘−1 𝑓𝑖−1 (𝑘𝑡ℎ order backward difference)
Example: In the following table, use the Newton-Gregory Forward Interpolation formula 11
to find f(2.4)?
𝑥 2 4 6 8 10
𝐹(𝑥) 9.68 10.96 12.32 13.76 15.28
Solution:
𝑥 𝐹(𝑥) Δ𝑓𝑖 Δ2 𝑓𝑖 Δ3 𝑓𝑖
2 9.68 1.28 0.08 0
4 10.96 1.36 0.08 0
6 12.32 1.44 0.08
8 13.76 1.52
10 15.28
For 𝑥 = 2.4; 𝑥0 = 2; ℎ = 2
𝑛 𝑛(𝑛 − 1) 2 𝑛(𝑛 − 1)(𝑛 − 2) 3 𝑥 − 𝑥0
𝐹(𝑥=𝑥0+𝑛ℎ) = 𝑦0 + Δ𝑦0 + Δ 𝑦0 + Δ 𝑦0 + ⋯ where 𝑛 =
1! 2! 3! ℎ
2.4 − 2 0.08
we get 𝑓 2.4 = 9.68 + ∗ 1.28 + 0.2(0.2 − 1) ∗ = 9.9296
2 2
Example: In the following table of 𝑒 (𝑥) use the Newton-Gregory formula of backward 12
interpolation to calculate 𝑒 (2.0) ?
𝑥 0.1 0.6 1.1 1.6 2.1
𝑒 (𝑥) 1.1052 1.8221 3.0042 4.9530 8.1662
Solution:
𝑥 𝑒 (𝑥) 𝛻𝑓𝑖 𝛻 2 𝑓𝑖 𝛻 3 𝑓𝑖 𝛻 4 𝑓𝑖
0.1 1.1052
0.6 1.8221 0.7169
1.1 3.0042 1.1821 0.4652
1.6 4.9530 1.9488 0.7667 0.3015
2.1 8.1662 3.2132 1.2644 0.4977 0.1962
For 𝑥 = 2; 𝑥0 = 2.1; ℎ = 0.5
𝑛 𝑛(𝑛 + 1) 2 𝑛(𝑛 + 1)(𝑛 + 2) 3 𝑥 − 𝑥𝑛
𝑦(𝑥=𝑥𝑛+𝑛ℎ) = 𝑦𝑛 + 𝛻𝑦𝑛 + 𝛻 𝑦𝑛 + 𝛻 𝑦𝑛 + ⋯ when 𝑛 =
1! 2! 3! ℎ
We get
1.2644 0.4977
𝑒 2.00 = 8.1662 − 0.2 × 3.2132 − 0.2 × 0.8 × − 0.2 × 0.8 × 1.8 × +⋯
2 6
= 7.3920
13
Homework:
Construct the differences table and then find
1. 𝑓(𝑥) when 𝑥 = 112
2. 𝑓(𝑥) when 𝑥 = 112
𝑥 100 110 120 130 140
𝐹(𝑥) 3 7 13 21 31