You are on page 1of 79

Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

CHAPTER # 2
INTERPOLATION
&
CURVE FITTING

Dr. Jamil Book Series 2 Page 1


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

CHAPTER # 2
PART-I: INTERPOLATION
Introduction:-
In this chapter we will discuss the problem of approximating a given function by a class of
simpler function especially polynomial. Let us suppose a function 𝒚 = 𝒚(𝒙) = 𝒇(𝒙) is not
known explicitly and only the values of 𝒇(𝒙) at a set of points are known.
Let 𝒇(𝒙) is known at the distinct points 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ,...., 𝒙𝒏 i.e.
“Table of values”

Interpolation:-
Interpolation is the process of finding the value of a function for any value of argument or
independent variable in an interval (𝒙𝟎 , 𝒙𝒏 ).
Thus interpolation is the art of reading between the lines in a given table.

Extrapolation:-
Extrapolation is the process of finding the value of a function outside an interval
(𝒙𝟎 , 𝒙𝒏 ).

Polynomial Interpolation 𝑷(𝒙):-


Approximation by the polynomial of least degree satisfying the given data is called
Polynomial Interpolation and the corresponding polynomial is called the interpolating
polynomial.
The following theorem guarantees the existence and uniqueness of such a polynomial.

Dr. Jamil Book Series 2 Page 2


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Theorem:-
Let 𝒚(𝒙) = 𝒇(𝒙) be known at the distinct points 𝒙𝟎 , 𝒙𝟏 , … 𝒙𝒏 . Then there exists a Unique
polynomial 𝑷(𝒙) of Degree less than or equals to 𝒏 and Satisfying the condition:

𝑷(𝒙𝒊 ) = 𝒚(𝒙𝒊 ) = 𝒚𝒊 = 𝒇𝒊 , 𝒊 = 𝟎, 𝟏, 𝟐, … . , 𝒏

1): Lagrange’s Interpolation Polynomial Formula


Let 𝒇(𝒙) are known at the distinct points 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏 i.e. there are (𝒏 + 𝟏) points are
given as in the following table:
“Table of values”

𝒙 𝒙𝟎 𝒙𝟏 𝒙𝟐 . .. 𝒙𝒏
𝒚(𝒙) = 𝒇(𝒙) 𝒚𝟎 = 𝒇(𝒙𝟎 ) = 𝒇𝟎 𝒚𝟏 = 𝒇(𝒙𝟏 ) = 𝒇𝟏 𝒚𝟐 = 𝒇(𝒙𝟐 ) = 𝒇𝟐 … 𝒚𝒏 = 𝒇(𝒙𝒏 ) = 𝒇𝒏

The Lagrange’s interpolation polynomial formula of degree at most (𝒏 + 𝟏) is given by


(without proof):
𝒏

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

where 𝑳𝒊 (𝒙) are called Lagrange’s interpolation coefficients and defined as:

(𝒙−𝒙𝟎 ) (𝒙−𝒙𝟏 ) …(𝒙−𝒙𝒊−𝟏 ) (𝒙−𝒙𝒊+𝟏 )… (𝒙−𝒙𝒏 )


𝑳 𝒊 (𝒙 ) = ( [ 𝑫𝒆𝒍𝒆𝒕𝒆 𝒊𝒕𝒉 𝒇𝒂𝒄𝒕𝒐𝒓 (𝒙𝒊 − 𝒙𝒊 ) ]
𝒙𝒊 −𝒙𝟎 )(𝒙𝒊 −𝒙𝟏 )…(𝒙𝒊 −𝒙𝒊−𝟏 )(𝒙𝒊 −𝒙𝒊+𝟏 )…(𝒙𝒊 −𝒙𝒏 )

Example # 1:-
Determine the Lagrange’s interpolation polynomial for the data:

𝒙 𝟎 𝟏 𝟑
𝒙𝟎 𝒙𝟏 𝒙𝟐
𝒚 = 𝒇(𝒙) 𝟏 𝟑 𝟓5
𝒚𝟎 𝒚𝟏 𝒚𝟐

and estimate the value of 𝒚 = 𝒚(𝒙) at 𝒙 = 𝟐 and 𝒙 = 𝟒.

Solution :-
The Lagrange’s interpolation polynomial formula of degree at most 2 is given by (here 𝒏 =
𝟐) :

Dr. Jamil Book Series 2 Page 3


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

⟹ 𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝑳𝟎 (𝒙)𝒚𝟎 + 𝑳𝟏 (𝒙)𝒚𝟏 + 𝑳𝟐 (𝒙)𝒚𝟐 (𝟏)

Now
(𝒙−𝒙𝟏 )(𝒙−𝒙𝟐 ) (𝒙−𝟏)(𝒙−𝟑) 𝟏
𝑳𝟎 (𝒙) = (𝒙 = = 𝟑 (𝒙𝟐 − 𝟒𝒙 + 𝟑)
𝟎 −𝒙𝟏 )(𝒙𝟎 −𝒙𝟐 ) (𝟎−𝟏)(𝟎−𝟑)

(𝒙−𝒙𝟎 )(𝒙−𝒙𝟐 ) (𝒙−𝟎)(𝒙−𝟑) −𝟏


𝑳𝟏 (𝒙) = (𝒙𝟏 −𝒙𝟎 )(𝒙𝟏 −𝒙𝟐
=
) (𝟏−𝟎)(𝟏−𝟑)
= (𝒙𝟐 − 𝟑𝒙)
𝟐

(𝒙−𝒙𝟎 )(𝒙−𝒙𝟏 ) (𝒙−𝟎)(𝒙−𝟏) 𝟏


𝑳𝟐 (𝒙) = (𝒙 = (𝟑−𝟎)(𝟑−𝟏) = 𝟔 (𝒙𝟐 − 𝒙)
𝟐 −𝒙𝟎 )(𝒙𝟐 −𝒙𝟏 )

Substituting values in Eq. (1), we get


𝟏 𝟐 𝟏 𝟏
𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = (𝒙 − 𝟒𝒙 + 𝟑)(𝟏) − (𝒙𝟐 − 𝟑𝒙)(𝟑) + (𝒙𝟐 − 𝒙)(𝟓𝟓)
𝟑 𝟐 𝟔

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝟖𝒙𝟐 − 𝟔𝒙 + 𝟏

is the required Lagrange’s interpolation polynomial. Also

𝒚(𝟐) = 𝒇(𝟐) ≅ 𝑷(𝟐) = 𝟖(𝟐)𝟐 − 𝟔(𝟐) + 𝟏 = 𝟐𝟏

and

𝒚(𝟒) = 𝒇(𝟒) ≅ 𝑷(𝟒) = 𝟖(𝟒)𝟐 − 𝟔(𝟒) + 𝟏 = 𝟏𝟎𝟓

Example # 2:-
Find the missing value from the following data using Lagrange’s interpolation formula:

𝒙 𝟎 𝟏 𝟐 𝟑 𝟒
𝒚(𝒙) = 𝒇(𝒙) −𝟏𝟐 𝟎 − 𝟔 𝟏𝟐

Solution:-
Consider the following data:

Dr. Jamil Book Series 2 Page 4


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒙 𝟎 𝟏 𝟑 𝟒
𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑
𝒚(𝒙) = 𝒇(𝒙) −𝟏𝟐 𝟎 𝟔 𝟏𝟐
𝒚𝟎 𝒚𝟏 𝒚𝟐 𝒚𝟑

The Lagrange’s interpolation polynomial formula of degree at most 3 is given by (here 𝒏 =


𝟑):
𝟑

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝑳𝟎 (𝒙)𝒚𝟎 + 𝑳𝟏 (𝒙)𝒚𝟏 + 𝑳𝟐 (𝒙)𝒚𝟐 + 𝑳𝟑 (𝒙)𝒚𝟑 (1)

Now
(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟏)(𝒙 − 𝟑)(𝒙 − 𝟒)
𝑳𝟎 (𝒙) = =
(𝒙𝟎 − 𝒙𝟏 )(𝒙𝟎 − 𝒙𝟐 )(𝒙𝟎 − 𝒙𝟑 ) (𝟎 − 𝟏)(𝟎 − 𝟑)(𝟎 − 𝟒)

−𝟏 𝟑
𝑳𝟎 (𝒙) = (𝒙 − 𝟖𝒙𝟐 + 𝟏𝟗𝒙 − 𝟏𝟐)
𝟏𝟐

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟎)(𝒙 − 𝟑)(𝒙 − 𝟒) 𝟏 𝟑


𝑳𝟏 (𝒙) = = = (𝒙 − 𝟕𝒙𝟐 + 𝟏𝟐𝒙)
(𝒙𝟏 − 𝒙𝟎 )(𝒙𝟏 − 𝒙𝟐 )(𝒙𝟏 − 𝒙𝟑 ) (𝟏 − 𝟎)(𝟏 − 𝟑)(𝟏 − 𝟒) 𝟔

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟎)(𝒙 − 𝟏)(𝒙 − 𝟒) −𝟏 𝟑


𝑳𝟐 (𝒙) = = = (𝒙 − 𝟓𝒙𝟐 + 𝟒𝒙)
(𝒙𝟐 − 𝒙𝟎 )(𝒙𝟐 − 𝒙𝟏 )(𝒙𝟐 − 𝒙𝟑 ) (𝟑 − 𝟎)(𝟑 − 𝟏)(𝟑 − 𝟒) 𝟔

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 ) (𝒙 − 𝟎)(𝒙 − 𝟏)(𝒙 − 𝟑) 𝟏 𝟑


𝑳𝟑 (𝒙) = = = (𝒙 − 𝟒𝒙𝟐 + 𝟑𝒙)
(𝒙𝟑 − 𝒙𝟎 )(𝒙𝟑 − 𝒙𝟏 )(𝒙𝟑 − 𝒙𝟐 ) (𝟒 − 𝟎)(𝟒 − 𝟏)(𝟒 − 𝟑) 𝟏𝟐

Substituting these values in Eq. (1), we get

𝟏 𝟑 𝟏
𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = − (𝒙 − 𝟖𝒙𝟐 + 𝟏𝟗𝒙 − 𝟐)(−𝟏𝟐) + (𝒙𝟑 − 𝟕𝒙𝟐 + 𝟏𝟐𝒙)(𝟎)
𝟏𝟐 𝟔
𝟏 𝟏 𝟑
− (𝒙𝟑 − 𝟓𝒙𝟐 + 𝟒𝒙)(𝟔) + (𝒙 − 𝟒𝒙𝟐 + 𝟑𝒙)(𝟏𝟐)
𝟔 𝟏𝟐

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒙𝟑 − 𝟕𝒙𝟐 + 𝟏𝟖𝒙 − 𝟏𝟐

Hence

Dr. Jamil Book Series 2 Page 5


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒚(𝟐) = 𝒇(𝟐) ≅ 𝑷(𝟐) = (𝟐)𝟑 − 𝟕(𝟐)𝟐 + 𝟏𝟖(𝟐) − 𝟏𝟐 = 𝟒

Example # 3:-
Find 𝒚(𝟏) using Lagrange’s interpolation polynomial:

𝒙 −𝟏 𝟎 𝟐 𝟑
𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑
𝒚 = 𝒇(𝒙) 𝟓 𝟐 𝟎 𝟏
𝒚𝟎 𝒚𝟏 𝒚𝟐 𝒚𝟑
Solution:-
The Lagrange’s interpolation polynomial formula of degree at most 3 is given by (here
𝒏 = 𝟑):
𝟑

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

Here = 𝟏 , therefore we have

⟹ 𝒚(𝟏) = 𝒇(𝟏) ≅ 𝑷(𝟏) = ∑𝟑𝒊=𝟎 𝑳𝒊 (𝟏)𝒚𝒊 = 𝑳𝟎 (𝟏)𝒚𝟎 + 𝑳𝟏 (𝟏)𝒚𝟏 + 𝑳𝟐 (𝟏)𝒚𝟐 + 𝑳𝟑 (𝟏)𝒚𝟑 (1)
Now
(𝒙−𝒙𝟏 )(𝒙−𝒙𝟐 )(𝒙−𝒙𝟑 ) (𝟏−𝟎)(𝟏−𝟐)(𝟏−𝟑) 𝟐 −𝟏
𝑳𝟎 (𝟏) = = = =
(𝒙𝟎 −𝒙𝟏 )(𝒙𝟎 −𝒙𝟐 )(𝒙𝟎 −𝒙𝟑 ) (−𝟏−𝟎)(−𝟏−𝟐)(−𝟏−𝟑) −𝟏𝟐 𝟔

(𝒙−𝒙𝟎 )(𝒙−𝒙𝟐 )(𝒙−𝒙𝟑 ) [𝟏—(−𝟏)](𝟏−𝟐)(𝟏−𝟑) 𝟒 𝟐


𝑳𝟏 (𝟏) = (𝒙 = =𝟔=𝟑
𝟏 −𝒙𝟎 )(𝒙𝟏 −𝒙𝟐 )(𝒙𝟏 −𝒙𝟑 ) [𝟎−(−𝟏)](𝟎−𝟐)(𝟎−𝟑)

(𝒙−𝒙𝟎 )(𝒙−𝒙𝟏 )(𝒙−𝒙𝟑 ) [𝟏—(−𝟏)](𝟏−𝟎)(𝟏−𝟑) −𝟒 𝟐


𝑳𝟐 (𝟏) = (𝒙 = = −𝟔 = 𝟑
𝟐 −𝒙𝟎 )(𝒙𝟐 −𝒙𝟏 )(𝒙𝟐 −𝒙𝟑 ) [𝟐−(−𝟏)](𝟐−𝟎)(𝟐−𝟑)

(𝒙−𝒙𝟎 )(𝒙−𝒙𝟏 )(𝒙−𝒙𝟐 ) [𝟏—(−𝟏)](𝟏−𝟎)(𝟏−𝟐) −𝟐 −𝟏


𝑳𝟑 (𝟏) = (𝒙 = = 𝟏𝟐 =
𝟑 −𝒙𝟎 )(𝒙𝟑 −𝒙𝟏 )(𝒙𝟑 −𝒙𝟐 ) [𝟑−(−𝟏)](𝟑−𝟎)(𝟑−𝟐) 𝟔

Substituting these values in Eq. (1), we get

𝟏 𝟐 𝟐 𝟏 𝟏
𝒚(𝟏) = 𝒇(𝟏) ≅ 𝑷(𝟏) = (− ) (𝟓) + ( ) (𝟐) + ( ) (𝟎) + (− ) (𝟏) =
𝟔 𝟑 𝟑 𝟔 𝟑

Dr. Jamil Book Series 2 Page 6


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 1:-


The following table are the measurement 𝑻 made on a curve record by oscilograph
representing a change of current 𝑰 due to a change in the conditions of an electric current:
1): Construct a Mathematical Model by Lagrange interpolation polynomial,
2): Write Polynomial in uncomplicated form.
3): Find the current 𝑰 for a 𝑻 = 𝟑.
4): Interpret and conclude your results.

𝑻 0 1 4 5

Current 𝑰 8 11 68 123

Answer:-
𝑰(𝑻) =≈ 𝑷(𝑻) = 𝑻𝟑 − 𝑻𝟐 + 𝟑𝑻 + 𝟖

Dr. Jamil Book Series 2 Page 7


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

2): Hermite’s Interpolation Polynomial Formula

Let 𝒇(𝒙) and 𝒇′(𝒙) are known at the distinct points 𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 i.e there are (𝟐𝒏 + 𝟐) points
are given as in the following table:
“Table of values”

𝒙 𝒙𝟎 𝒙𝟏 𝒙𝟐 … 𝒙𝒏

𝒚(𝒙) = 𝒇(𝒙) 𝒚𝟎 𝒚𝟏 𝒚𝟐 … 𝒚𝒏

𝒚’(𝒙) = 𝒇’(𝒙) 𝒚’𝟎 𝒚’𝟏 𝒚’𝟐 … 𝒚’𝒏

The Hermite’s interpolation polynomial formula of degree at most (𝟐𝒏 + 𝟏) is given by


(without proof):
𝒏 𝒏

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑨𝒊 (𝒙)𝒚𝒊 + ∑ 𝑩𝒊 (𝒙)𝒚′𝒊


𝒊=𝟎 𝒊=𝟎

where

𝑨𝒊 (𝒙) = [𝟏 − 𝟐𝑳′ 𝒊 (𝒙𝒊 )(𝒙 − 𝒙𝒊 )][𝑳𝒊 (𝒙)]𝟐

𝑩𝒊 (𝒙) = (𝒙 − 𝒙𝒊 )[𝑳𝒊 (𝒙)]𝟐

where 𝒚′𝒊 and 𝐋′𝒊 (𝒙) are derivatives of 𝒚(𝒙) and 𝑳𝒊 (𝒙) respectively.
Example # 4:-
Using Hermite’s interpolation formula find 𝒚 = 𝒇(𝒙) ≅ 𝑷(𝒙), and obtain 𝒚(𝟎. 𝟓) and
𝒚(−𝟎. 𝟓) from the following table:

𝒙 −𝟏 𝟎 𝟏
𝒙𝟎 𝒙𝟏 𝒙𝟐

𝒚 = 𝒇(𝒙) 𝟏 𝟏 𝟑
𝒚𝟎 𝒚𝟏 𝒚𝟐

𝒚′ = 𝒇′(𝒙) −𝟓 𝟏 𝟕
𝒚′ 𝟎 𝒚′ 𝟏 𝒚′ 𝟐

Solution:-
The Hermite’s interpolation polynomial formula of degree at most 5 is given by(here 𝒏 = 𝟐)

𝟐 𝟐

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑨𝒊 (𝒙)𝒚𝒊 + ∑ 𝑩𝒊 (𝒙)𝒚′𝒊


𝒊=𝟎 𝒊=𝟎

Dr. Jamil Book Series 2 Page 8


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

where
𝑨𝒊 (𝒙) = [𝟏 − 𝟐𝑳′𝒊 (𝒙𝒊 )(𝒙 − 𝒙𝒊 )][𝑳𝒊 (𝒙)]𝟐

𝑩𝒊 (𝒙) = (𝒙 − 𝒙𝒊 )[𝑳𝒊 (𝒙)]𝟐

we have:
𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝑨𝟎 (𝒙)𝒚𝟎 + 𝑨𝟏 (𝒙)𝒚𝟏 + 𝑨𝟐 (𝒙)𝒚𝟐 + 𝑩𝟎 (𝒙)𝒚′ 𝟎 + 𝑩𝟏 (𝒙)𝒚′ 𝟏
+𝑩𝟐 (𝒙)𝒚′𝟐 (1)

𝑨𝟎 (𝒙) = [𝟏 − 𝟐𝑳′𝟎 (𝒙𝟎 )(𝒙 − 𝒙𝟎 )][𝑳𝟎 (𝒙)]𝟐

𝑨𝟏 (𝒙) = [𝟏 − 𝟐𝑳′𝟏 (𝒙𝟏 )(𝒙 − 𝒙𝟏 )][𝑳𝟏 (𝒙)]𝟐

𝑨𝟐 (𝒙) = [𝟏 − 𝟐𝑳′𝟐 (𝒙𝟐 )(𝒙 − 𝒙𝟐 )][𝑳𝟐 (𝒙)]𝟐

𝑩𝟎 (𝒙) = (𝒙 − 𝒙𝟎 )[𝑳𝟎 (𝒙)]𝟐

𝑩𝟏 (𝒙) = (𝒙 − 𝒙𝟏 )[𝑳𝟏 (𝒙)]𝟐

𝑩𝟐 (𝒙) = (𝒙 − 𝒙𝟐 )[𝑳𝟐 (𝒙)]𝟐

Now we calculate 𝑳𝒊 (𝒙) and 𝑳′𝒊 (𝒙), 𝒊 = 𝟎, 𝟏, 𝟐

(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 ) (𝒙 − 𝟎)(𝒙 − 𝟏) 𝟏
𝑳𝟎 (𝒙) = = = 𝒙(𝒙 − 𝟏)
(𝒙𝟎 − 𝒙𝟏 )(𝒙𝟎 − 𝒙𝟐 ) (−𝟏 − 𝟎)(−𝟏 − 𝟏) 𝟐

𝟏 −𝟑
⟹ 𝑳′𝟎 (𝒙) = (𝟐𝒙 − 𝟏) ⟹ 𝑳′𝟎 (𝒙𝟎 ) = 𝑳′𝟎 (−𝟏) =
𝟐 𝟐

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟐 ) (𝒙 + 𝟏)(𝒙 − 𝟏)
𝑳𝟏 (𝒙) = = = 𝟏 − 𝒙𝟐
(𝒙𝟏 − 𝒙𝟎 )(𝒙𝟏 − 𝒙𝟐 ) (𝟎 + 𝟏)(𝟎 − 𝟏)

⟹ 𝑳′𝟏 (𝒙) = −𝟐𝒙 ⟹ 𝑳′𝟏 (𝒙𝟏 ) = 𝑳′𝟏 (𝟎) = 𝟎

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 ) (𝒙 + 𝟏)(𝒙 − 𝟎) 𝟏
𝑳𝟐 (𝒙) = = = 𝒙(𝒙 + 𝟏)
(𝒙𝟐 − 𝒙𝟎 )(𝒙𝟐 − 𝒙𝟏 ) (𝟏 + 𝟏)(𝟏 − 𝟎) 𝟐

𝟏 𝟑
⟹ 𝑳′𝟐 (𝒙) = (𝟐𝒙 + 𝟏) ⟹ 𝑳′𝟐 (𝒙𝟐 ) = 𝑳′𝟐 (𝟏) =
𝟐 𝟐

Dr. Jamil Book Series 2 Page 9


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Substituting these values in 𝑨′𝒊 𝒔 𝐚𝐧𝐝 𝑩′𝒊 𝒔, 𝒊 = 𝟎, 𝟏, 𝟐. We have

−𝟑 𝒙𝟐 (𝒙 − 𝟏)𝟐 𝒙𝟐 (𝒙 − 𝟏)𝟐
𝑨𝟎 (𝒙) = [𝟏 − 𝟐 ( ) (𝒙 + 𝟏)] = (𝟒 + 𝟑𝒙)
𝟐 𝟒 𝟒

𝟏
𝑨𝟎 (𝒙) = (𝟑𝒙𝟓 − 𝟐𝒙𝟒 + 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )
𝟒

𝑨𝟏 (𝒙) = [𝟏 − 𝟐(𝟎)(𝒙 − 𝟎)](𝟏 − 𝒙𝟐 )𝟐 = 𝟏 − 𝟐𝒙𝟐 + 𝒙𝟒

𝟑 𝒙𝟐 (𝒙 + 𝟏)𝟐 𝒙𝟐 (𝒙 + 𝟏)𝟐
𝑨𝟐 (𝒙) = [𝟏 − 𝟐 ( ) (𝒙 − 𝟏)] = (𝟒 − 𝟑𝒙)
𝟐 𝟒 𝟒

𝟏
𝑨𝟐 (𝒙) = (−𝟑𝒙𝟓 − 𝟐𝒙𝟒 + 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )
𝟒

𝒙𝟐 (𝒙 − 𝟏)𝟐 𝟏 𝟓
𝑩𝟎 (𝒙) = (𝒙 + 𝟏) = (𝒙 − 𝒙𝟒 − 𝒙𝟑 + 𝒙𝟐 )
𝟒 𝟒

𝑩𝟏 (𝒙) = (𝒙 − 𝟎)(𝟏 − 𝒙𝟐 )𝟐 = 𝒙𝟓 − 𝟐𝒙𝟑 + 𝒙

𝒙𝟐 (𝒙 + 𝟏)𝟐 𝟏 𝟓
𝑩𝟐 (𝒙) = (𝒙 − 𝟏) = (𝒙 + 𝒙𝟒 − 𝒙𝟑 − 𝒙𝟐 )
𝟒 𝟒

Using above values in Eq. (1), we get

𝟏
𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = (𝟑𝒙𝟓 − 𝟐𝒙𝟒 − 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )(𝟏) + (𝟏 − 𝟐𝒙𝟐 + 𝒙𝟒 )(𝟏)
𝟒
𝟏 𝟏
+ (−𝟑𝒙𝟓 − 𝟐𝒙𝟒 + 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )(𝟑) + (𝒙𝟓 − 𝒙𝟒 − 𝒙𝟑 + 𝒙𝟐 )(−𝟓)
𝟒 𝟒

𝟏
+( 𝒙𝟓 − 𝟐𝒙𝟑 + 𝒙)(𝟏) + (𝒙𝟓 + 𝒙𝟒 − 𝒙𝟑 − 𝒙𝟐 )(𝟕)
𝟒

⟹ 𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝟐𝒙𝟒 − 𝒙𝟐 + 𝒙 + 𝟏

Hence

𝟏 𝟒 𝟏 𝟐 𝟏 𝟏𝟏
𝒚(𝟎. 𝟓) = 𝒇(𝟎. 𝟓) ≅ 𝑷(𝟎. 𝟓) = 𝟐 ( ) − ( ) + + 𝟏 =
𝟐 𝟐 𝟐 𝟖

Dr. Jamil Book Series 2 Page 10


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟏 𝟒 𝟏 𝟐 𝟏 𝟑
𝒚(−𝟎. 𝟓) = 𝒇(−𝟎. 𝟓) ≅ 𝑷(−𝟎. 𝟓) = 𝟐 (− ) − (− ) − + 𝟏 =
𝟐 𝟐 𝟐 𝟖

Example # 5:-
From the following data find 𝑷𝟓 (𝒙) using Hermite’s interpolation formula and hence
determine 𝒚(𝟎. 𝟓) = 𝑷𝟓 (𝟎. 𝟓).

𝒙 𝒚 = 𝒇(𝒙) 𝒚′ = 𝒇′(𝒙)

−𝟏 𝒙𝟎 𝟏 𝒚𝟎 −𝟏 𝒚′𝟎

𝟎 𝒙𝟏 𝟎 𝒚𝟏 𝟏 𝒚′𝟏

𝟏 𝒙𝟐 𝟏 𝒚𝟐 𝟎 𝒚′𝟐

Solution:-
The Hermite’s interpolation polynomial formula of degree at most 5 is given by (here
𝒏 = 𝟐)
𝟐 𝟐

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷𝟓 (𝒙) = ∑ 𝑨𝒊 (𝒙)𝒚𝒊 + ∑ 𝑩𝒊 (𝒙)𝒚′𝒊


𝒊=𝟎 𝒊=𝟎
where
𝑨𝒊 (𝒙) = [𝟏 − 𝟐𝑳′𝒊 (𝒙𝒊 )(𝒙 − 𝒙𝒊 )][𝑳𝒊 (𝒙)]𝟐

𝑩𝒊 (𝒙) = (𝒙 − 𝒙𝒊 )[𝑳𝒊 (𝒙)]𝟐

we have:
𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷𝟓 (𝒙) = 𝑨𝟎 (𝒙)𝒚𝟎 + 𝑨𝟏 (𝒙)𝒚𝟏 + 𝑨𝟐 (𝒙)𝒚𝟐 + 𝑩𝟎 (𝒙)𝒚′ 𝟎 + 𝑩𝟏 (𝒙)𝒚′ 𝟏
+𝑩𝟐 (𝒙)𝒚′𝟐 (1)

Since the values of 𝒙 given are same as in the (Example#1) there is no change in
𝑨𝟎 , 𝑨𝟏 , 𝑨𝟐 , 𝑩𝟎 , 𝑩𝟏 and 𝑩𝟐 . Hence
𝟏
𝒚 = 𝒇(𝒙) = 𝑷𝟓 (𝒙) = (𝟑𝒙𝟓 − 𝟐𝒙𝟒 − 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )(𝟏) + (𝟏 − 𝟐𝒙𝟐 + 𝒙𝟒 )(𝟎)
𝟒
𝟏 𝟏
+ (−𝟑𝒙𝟓 − 𝟐𝒙𝟒 + 𝟓𝒙𝟑 + 𝟒𝒙𝟐 )(𝟏) + (𝒙𝟓 − 𝒙𝟒 − 𝒙𝟑 + 𝒙𝟐 )(−𝟏)
𝟒 𝟒

𝟏
+( 𝒙𝟓 − 𝟐𝒙𝟑 + 𝒙)(𝟏) + (𝒙𝟓 + 𝒙𝟒 − 𝒙𝟑 − 𝒙𝟐 )(𝟎)
𝟒

𝟏
𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷𝟓 (𝒙) = (𝟑𝒙𝟓 − 𝟑𝒙𝟒 − 𝟕𝒙𝟑 + 𝟕𝒙𝟐 + 𝟒𝒙)
𝟒

Therefore

Dr. Jamil Book Series 2 Page 11


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟏
𝒚(𝟎. 𝟓) = 𝒇(𝟎. 𝟓) ≅ 𝑷𝟓 (𝟎. 𝟓) = [𝟑(𝟎. 𝟓)𝟓 − 𝟑(𝟎. 𝟓)𝟒 − 𝟕(𝟎. 𝟓)𝟑 + 𝟕(𝟎. 𝟓)𝟐 + 𝟒(𝟎. 𝟓)]
𝟒

𝒚(𝟎. 𝟓) = 𝒇(𝟎. 𝟓) ≅ 𝑷𝟓 (𝟎. 𝟓) = 𝟎. 𝟔𝟗𝟓𝟑𝟏𝟐𝟓

Drill Excercise # 2:-


Using Hermite’s interpolation, find a cubic polynomial from the data below, also find 𝒚(𝟎. 𝟓) =
𝒇(𝟎. 𝟓).

𝒙 𝟎 𝟏

𝒚 = 𝒇(𝒙) 𝟎 𝟏

𝒚′ = 𝒇′(𝒙) 𝟎 𝟏

Answer:-
𝟑
𝒚 = 𝒚(𝒙) = 𝒇(𝒙) = 𝟐𝒙𝟐 − 𝒙𝟑 , 𝒇(𝟎. 𝟓) =
𝟖

Drill Excercise # 3:-


Using Hermite’s interpolation, find 𝒚 = 𝒇(𝒙) given in the table below and obtain 𝒚(𝟎. 𝟓) =
𝒇(𝟎. 𝟓).

𝒙 0 1

𝒚 = 𝒇(𝒙) 1 1

𝒚′ = 𝒇′(𝒙) 0 1

Answer:-
𝟕
𝒇(𝟎. 𝟓) =
𝟖

Dr. Jamil Book Series 2 Page 12


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

3): Newton’s Forward Interpolation Polynomial Formula:-


Consider

𝑷(𝒙) = 𝒇(𝒙) = 𝒚(𝒙) = 𝒚(𝒙𝟎 + 𝒑𝒉) = 𝑬𝒑 𝒚(𝒙𝟎 ) = 𝑬𝒑 𝒚𝟎 ⸪𝒙 = 𝒙𝟎 + 𝒑𝒉

𝑷(𝒙) = (𝟏 + 𝜟)𝒑 𝒚𝟎 ⸪𝑬 = 𝟏 + 𝜟

Using binomial formula, we have


𝒑(𝒑−𝟏) 𝒑(𝒑−𝟏)(𝒑−𝟐) 𝒑(𝒑−𝟏)(𝒑−𝟐)…(𝒑−𝒏+𝟏)
𝒚(𝒙) = 𝑷(𝒙) = 𝒚𝟎 + 𝒑𝜟𝒚𝟎 + 𝚫𝟐 𝒚𝟎 + 𝚫𝟑 𝒚𝟎 +. . . + 𝜟𝒏 𝒚𝟎
𝟐! 𝟑! 𝒏!

𝒙−𝒙𝟎
where 𝒑=
𝒉

This is called Newton’s or Newton’s-Gregory forward interpolation formula.

4): Newton’s Backward Interpolation Polynomial Formula:-


Consider

𝑷(𝒙) = 𝒇(𝒙) = 𝒚(𝒙) = 𝒚(𝒙𝒏 + 𝒑𝒉) = 𝑬𝒑 𝒚(𝒙𝒏 ) = 𝑬𝒑 𝒚𝒏 ⸪𝒙 = 𝒙𝒏 + 𝒑𝒉

𝑷(𝒙) = (𝟏 − 𝛁)−𝒑 𝒚𝒏 ⸪𝑬 = (𝟏 − 𝛁)−𝟏

Again using binomial formula for negative power, we have


𝒑(𝒑+𝟏) 𝒑(𝒑+𝟏)(𝒑+𝟐) 𝒑(𝒑+𝟏)(𝒑+𝟐)…(𝒑+𝒏−𝟏)
𝒚(𝒙) = 𝑷(𝒙) = 𝒚𝒏 + 𝒑𝛁𝒚𝒏 + 𝛁𝟐 𝒚𝒏 + 𝛁𝟑 𝒚𝒏 +. . . + 𝛁𝒏 𝒚𝒏
𝟐! 𝟑! 𝒏!

𝒙−𝒙𝒏
where 𝒑 =
𝒉
This is called Newton’s or Newton’s-Gregory backward interpolation formula.

Transformation From Forward to Backward Formulae:-


You have to only remember the Newton’s Forward Formula and for Newton’s Backward
Formula, use the following transformation:

S.N. Symbol Replace

1 𝒚𝟎 𝒚𝒏

2 𝜟 𝛁

3 +− ++

Dr. Jamil Book Series 2 Page 13


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Important note:-
a): Newton’s forward interpolation formula is used for interpolating the values of the
function near the beginning/initial/start of the table.

b): Newton’s backward interpolation formula is used for interpolating the values of the
function near the end/final of the table.

Example # 6:-
Estimate 𝒚(𝟑. 𝟏𝟕) from the following data using Newton’s forward interpolation formula:

𝒙 3.1 3.2 3.3 3.4 3.5

𝒚 = 𝒇(𝒙) 0 0.6 1.0 1.2 1.3

Solution:-
“Forward Difference Table”
𝒙 𝒚 𝚫𝐲 𝚫2y 𝚫3y 𝚫4y
3.1 0
0.6
3.2 0.6 -0.2
0.4 0
3.3 1.0 -0.2 0.1
0.2 0.1
3.4 1.2 -0.1
0.1
3.5 1.3

From the above table, we have


𝒚𝟎 = 𝟎, 𝜟𝒚𝟎 = 𝟎. 𝟔, 𝚫𝟐 𝒚𝟎 = −𝟎. 𝟐, 𝚫𝟑 𝒚𝟎 = 𝟎, 𝚫𝟒 𝒚𝟎 = 𝟎. 𝟏
Here 𝒙𝟎 = 𝟑. 𝟏, 𝒙 = 𝟑. 𝟏𝟕 and 𝒉 = 𝟎. 𝟏

𝒙−𝒙𝟎 𝟑.𝟏𝟕−𝟑.𝟏 𝟎.𝟎𝟕


⸫𝒑= = = = 𝟎. 𝟕
𝒉 𝟎.𝟏 𝟎.𝟏

As the point 𝒙 = 𝟑. 𝟏𝟕 is near the beginning of the table


we use the Newton’s forward interpolation formula.

𝒑(𝒑−𝟏) 𝒑(𝒑−𝟏)(𝒑−𝟐) 𝒑(𝒑−𝟏)(𝒑−𝟐)(𝒑−𝟑)


𝑷(𝒙) = 𝒚𝟎 + 𝒑𝜟𝒚𝟎 + 𝚫𝟐 𝒚𝟎 + 𝚫𝟑 𝒚𝟎 + 𝚫𝟒 𝒚𝟎
𝟐! 𝟑! 𝟒!

Substituting values, we get

Dr. Jamil Book Series 2 Page 14


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟎. 𝟕(𝟎. 𝟕 − 𝟏)
⇒ 𝑷(𝟑. 𝟏𝟕) = 𝟎 + (𝟎. 𝟕)(𝟎. 𝟔) + (−𝟎. 𝟐)
𝟐
𝟎.𝟕(𝟎.𝟕−𝟏)(𝟎.𝟕−𝟐) 𝟎.𝟕(𝟎.𝟕−𝟏)(𝟎.𝟕−𝟐)(𝟎.𝟕−𝟑)
+ (𝟎) + (𝟎. 𝟏)
𝟔 𝟐𝟒

⇒ 𝒚(𝟑. 𝟏𝟕) = 𝒇(𝟑. 𝟏𝟕) = 𝑷(𝟑. 𝟏𝟕) = 𝟎. 𝟒𝟑𝟖𝟒

Thus

𝒚(𝟑. 𝟏𝟕) = 𝒇(𝟑. 𝟏𝟕) = 𝑷(𝟑. 𝟏𝟕) = 𝟎. 𝟒𝟑𝟖𝟒

Example # 7:-
Find the Newton’s forward interpolation polynomial for the data:

𝒙 -1 0 1 2
𝒚(𝒙) = 𝒇(𝒙) 4 2 2 4

and estimate 𝒚(−𝟎. 𝟓) .


Solution:-
“Forward Difference Table”
𝒙 𝒚 𝚫𝐲 ∆𝟐 𝒚 ∆𝟑 𝒚
-1 4
-2
0 2 2
0 0
1 2 2
2
2 4

From the above table, we have


𝒚𝟎 = 𝟒, 𝜟𝒚𝟎 = −𝟐, 𝚫𝟐 𝒚𝟎 = 𝟐, 𝚫𝟑 𝒚𝟎 = 𝟎

Here 𝒙𝟎 = −𝟏, 𝒙 = 𝒙, 𝒉 = 𝟏, then

𝒙 − 𝒙𝟎 𝒙 + 𝟏
𝒑= = =𝒙+𝟏
𝒉 𝟏

The Newton’s forward interpolation polynomial formula is given as

Dr. Jamil Book Series 2 Page 15


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒑(𝒑 − 𝟏) 𝟐 𝒑(𝒑 − 𝟏)(𝒑 − 𝟐) 𝟑


𝑷(𝒙) = 𝒚𝟎 + 𝒑𝜟𝒚𝟎 + 𝜟 𝒚𝟎 + 𝜟 𝒚𝟎
𝟐! 𝟑!
(𝒙 + 𝟏)𝒙
⇒ 𝑷(𝒙) = 𝟒 + (𝒙 + 𝟏)(−𝟐) + (𝟐) + 𝟎
𝟐

⇒ 𝒚 = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝒙𝟐 − 𝒙 + 𝟐

Hence

𝒚 = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝒙𝟐 − 𝒙 + 𝟐

is the required Newton’s forward interpolation polynomial and

𝒚(−𝟎. 𝟓) = 𝒇(−𝟎. 𝟓) ≅ 𝑷(−𝟎. 𝟓) = (−𝟎. 𝟓)𝟐 − (−𝟎. 𝟓) + 𝟐 = 𝟐. 𝟕𝟓

Example # 8:-
Estimate 𝒚(𝟒𝟐) from the following data using Newton’s backward interpolation formula

𝒙 20 25 30 35 40 45
𝒚(𝒙) = 𝒇(𝒙) 354 332 291 260 231 204

Solution:-
“Backward Difference Table”

𝒙 𝒚 𝛁𝒚 𝛁𝟐 𝒚 𝛁𝟑 𝒚 𝛁𝟒 𝒚 𝛁𝟓 𝒚
𝟐𝟎 𝟑𝟓𝟒

𝟐𝟓 𝟑𝟑𝟐 −𝟐𝟐
−𝟏𝟗
𝟐𝟗
−𝟒𝟏
𝟑𝟎 𝟐𝟗𝟏 𝟏𝟎 −𝟑𝟕
𝟒𝟓
−𝟖
𝟑𝟓 𝟐𝟔𝟎 −𝟑𝟏 𝟐 𝟖

−𝟐𝟗 𝟎
𝟒𝟎 𝟐𝟑𝟏 𝟐
−𝟐𝟕
𝟒𝟓 204

From the table above, we have

𝒚𝒏 = 𝟐𝟎𝟒, 𝛁𝒚𝒏 = −𝟐𝟕, 𝛁𝟐 𝒚𝒏 = 𝟐, 𝛁𝟑 𝒚𝒏 = 𝟎, 𝛁𝟒 𝒚𝒏 = 𝟖, 𝛁𝟓 𝒚𝒏 = 𝟒𝟓

Dr. Jamil Book Series 2 Page 16


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Here 𝒙𝒏 = 𝟒𝟓, 𝒙 = 𝟒𝟐, and 𝒉 = 𝟓, then

𝒙 − 𝒙𝒏 𝟒𝟐 − 𝟒𝟓 −𝟑
⟹𝒑= = = = −𝟎. 𝟔
𝒉 𝟓 𝟓

As the point 𝒙 = 𝟒𝟐 is near the end of the table. We use Newton’s backward interpolation
formula

𝒑(𝒑 + 𝟏) 𝟐 𝒑(𝒑 + 𝟏)(𝒑 + 𝟐) 𝟑


𝑷(𝒙) = 𝒚𝒏 + 𝒑𝜵𝒚𝒏 + 𝜵 𝒚𝒏 + 𝜵 𝒚𝒏 +
𝟐! 𝟑!

𝒑(𝒑 + 𝟏)(𝒑 + 𝟐)(𝒑 + 𝟑) 𝟒 𝒑(𝒑 + 𝟏)(𝒑 + 𝟐)(𝒑 + 𝟑)(𝒑 + 𝟒) 𝟓


𝜵 𝒚𝒏 + 𝜵 𝒚𝒏
𝟒! 𝟓!

Substituting values, we get

(−𝟎. 𝟔)(𝟎. 𝟒) (−𝟎. 𝟔)(𝟎. 𝟒)(𝟏. 𝟒)


⇒ 𝑷(𝟒𝟐) = 𝟐𝟎𝟒 + (−𝟎. 𝟔)(−𝟐𝟕) + (𝟐) + (𝟎) +
𝟐 𝟔

(−𝟎. 𝟔)(𝟎. 𝟒)(𝟏. 𝟒)(𝟐. 𝟒) (−𝟎. 𝟔)(𝟎. 𝟒)(𝟏. 𝟒)(𝟐. 𝟒)(𝟑. 𝟒)


(𝟖) + (𝟒𝟓)
𝟐𝟒 𝟏𝟐𝟎

𝒚(𝟒𝟐) = 𝒇(𝟒𝟐) ≅ 𝑷(𝟒𝟐) = 𝟐𝟏𝟖. 𝟔𝟔𝟑𝟎

Example # 9:-
Given the following table

𝒙 1 2 3 4 5 6 7 8

𝒚 = 𝒇(𝒙) 1 8 27 64 125 216 343 512

Find a): 𝒇(𝟏. 𝟓) b): 𝒇(𝟕. 𝟓)

Solution:-

Dr. Jamil Book Series 2 Page 17


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Forward/Backward Difference Table”

𝒙 𝒚 ∆𝒚 ∆𝟐 𝒚 ∆𝟑 𝒚 ∆𝟒 𝒚 ∆𝟓 𝒚 ∆𝟔 𝒚 ∆𝟕 𝒚

𝟏 𝟏
𝟕
𝟐 𝟖
𝟏𝟐
𝟏𝟗
𝟔
𝟑 𝟐𝟕 𝟏𝟖 𝟎
𝟎
𝟑𝟕 𝟔
𝟐𝟒 𝟎
𝟎
𝟒 𝟔𝟒 𝟎 𝟎
𝟔𝟏 𝟔
𝟑𝟎 𝟎
𝟎
𝟎
𝟓 𝟏𝟐𝟓 𝟔
𝟗𝟏
𝟑𝟔 𝟎
𝟔 𝟐𝟏𝟔
𝟏𝟐𝟕 𝟔

𝟒𝟐
7 𝟑𝟒𝟑
𝟏𝟔𝟗

8 𝟓𝟏𝟐

a): For 𝒇(𝟏. 𝟓):-


To compute 𝒇(𝟏. 𝟓), we use Newton’s-forward interpolation formula, as the point 𝒙 = 𝟏. 𝟓
is near the beginning of the table, therefore we have

𝒑(𝒑 − 𝟏) 𝟐 𝒑(𝒑 − 𝟏)(𝒑 − 𝟐) 𝟑


𝑷(𝒙) = 𝒚𝟎 + 𝒑𝜟𝒚𝟎 + 𝜟 𝒚𝟎 + 𝜟 𝒚𝟎 + 𝟎 + 𝟎 + 𝟎 + 𝟎
𝟐! 𝟑!
Here 𝒙𝟎 = 𝟏, 𝒙 = 𝟏. 𝟓 and 𝒉 = 𝟏, then

𝒙 − 𝒙𝟎 𝟏. 𝟓 − 𝟏
⟹𝒑= = = 𝟎. 𝟓
𝒉 𝟏

Substituting these values in above formula, we get

(𝟎. 𝟓)(−𝟎. 𝟓) (𝟎. 𝟓)(−𝟎. 𝟓)(−𝟏. 𝟓)


⇒ 𝑷(𝟏. 𝟓) = 𝟏 + (𝟎. 𝟓)(𝟕) + (𝟏𝟐) + (𝟔)
𝟐 𝟔

⇒ 𝑷(𝟏. 𝟓) = 𝟏 + 𝟑. 𝟓 − 𝟏. 𝟓 + 𝟎. 𝟑𝟕𝟓 = 𝟑. 𝟑𝟕𝟓


Hence

𝒚(𝟏. 𝟓) = 𝒇(𝟏. 𝟓) ≅ 𝑷(𝟏. 𝟓) = 𝟑. 𝟑𝟕𝟓

Dr. Jamil Book Series 2 Page 18


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

b): For 𝒇(𝟕. 𝟓):-


To compute 𝒇(𝟕. 𝟓), we use Newton’s-backward interpolation formula, as the point 𝒙 = 𝟕. 𝟓
is near the end of the table, therefore we have

𝒑(𝒑 + 𝟏) 𝟐 𝒑(𝒑 + 𝟏)(𝒑 + 𝟐) 𝟑


𝑷(𝒙) = 𝒚𝒏 + 𝒑𝜵𝒚𝒏 + 𝜵 𝒚𝒏 + 𝜵 𝒚𝒏 + 𝟎 + 𝟎 + 𝟎 + 𝟎
𝟐! 𝟑!

Here 𝒙𝒏 = 𝟖, 𝒙 = 𝟕. 𝟓 and 𝒉 = 𝟏, then

𝒙 − 𝒙𝒏 𝟕. 𝟓 − 𝟖
⟹𝒑= = = −𝟎. 𝟓
𝒉 𝟏

Substituting these values,we get

(−𝟎. 𝟓)(𝟎. 𝟓) (−𝟎. 𝟓)(𝟎. 𝟓)(𝟏. 𝟓)


𝑷(𝟕. 𝟓) = 𝟓𝟏𝟐 + (−𝟎. 𝟓)(𝟏𝟔𝟗) + (𝟒𝟐) + (𝟔)
𝟐 𝟔

𝑷(𝟕. 𝟓) = 𝟓𝟏𝟐 – 𝟖𝟒. 𝟓 – 𝟓. 𝟐𝟓 − 𝟎. 𝟑𝟕𝟓 = 𝟒𝟐𝟏. 𝟖𝟕𝟓


Hence

𝒚(𝟕. 𝟓) = 𝒇(𝟕. 𝟓) ≅ 𝑷(𝟕. 𝟓) = 𝟒𝟐𝟏. 𝟖𝟕𝟓

Drill Excercise # 4:-


Evaluate 𝒚(𝟏. 𝟏) and 𝒚(𝟒. 𝟓) from the table:
𝒙 0 1 2 3 4 5
𝒚(𝒙) = 𝒇(𝒙) 0 3 8 15 24 35

Answer:-
𝒇(𝟏. 𝟏) = 𝟑. 𝟒𝟏, 𝒇(𝟒. 𝟓) = 𝟐𝟗. 𝟐𝟓

Drill Excercise # 5:-


Compute 𝒚(𝟎. 𝟓) and 𝒚(𝟔. 𝟕) from the table:
𝒙 0 1 2 3 4 5 6 7
𝒚(𝒙) = 𝒇(𝒙) 0 7 26 63 124 215 342 511

Answer:-
𝒇(𝟎. 𝟓) = 𝟐. 𝟑𝟕𝟓, 𝒇(𝟔. 𝟕) = 𝟒𝟓𝟓. 𝟓𝟑𝟑

Dr. Jamil Book Series 2 Page 19


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

The DIVIDED DIFFRENCES


Let the values of 𝒚(𝒙) = 𝒇(𝒙) be given at (𝒏 + 𝟏) distinct points 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 … . 𝒙𝒏 . We
define the Newton’s divided differences as:

𝒇(𝒙𝟏 ) − 𝒇(𝒙𝟎 )
𝒇[ 𝒙 𝟎 , 𝒙 𝟏 ] =
𝒙𝟏 − 𝒙 𝟎

𝒇(𝒙𝟐 ) − 𝒇(𝒙𝟏 )
𝒇[ 𝒙 𝟏 , 𝒙 𝟐 ] =
𝒙𝟐 − 𝒙 𝟏
. . .
. . .
. . .

𝒇(𝒙𝒏 ) − 𝒇(𝒙𝒏−𝟏 )
𝒇[𝒙𝒏−𝟏 , 𝒙𝒏 ] =
𝒙𝒏 − 𝒙𝒏−𝟏

These are called first divided differences and is devoted by 𝚫𝒇. Higher divided differences
operators are defined as:

𝒇[ 𝒙 𝟏 , 𝒙 𝟐 ] − 𝒇[ 𝒙 𝟎 , 𝒙 𝟏 ]
𝒇[ 𝒙 𝟎 , 𝒙 𝟏 , 𝒙 𝟐 ] =
𝒙𝟐 − 𝒙𝟎
𝒇[ 𝒙 𝟐 , 𝒙 𝟑 ] − 𝒇[ 𝒙 𝟏 , 𝒙 𝟐 ]
𝒇[ 𝒙 𝟏 , 𝒙 𝟐 , 𝒙 𝟑 ] =
𝒙𝟑 − 𝒙𝟏

𝒇[ 𝒙 𝟏 , 𝒙 𝟐 , 𝒙 𝟑 ] − 𝒇[ 𝒙 𝟎 , 𝒙 𝟏 , 𝒙 𝟐 ]
𝒇[ 𝒙 𝟎 , 𝒙 𝟏 , 𝒙 𝟐 , 𝒙 𝟑 ] =
𝒙𝟑 − 𝒙𝟎

. . . . .
. . . . .
. . . . .

𝒇[𝒙𝟏 ,𝒙𝟐 ,…,𝒙𝒌 ]−𝒇[𝒙𝟎 ,…,𝒙𝒌−𝟏 ]


𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒌−𝟏 , 𝒙𝒌, ] = for 𝒌 = 𝟑, 𝟒, 𝟓, . . . , 𝒏
𝒙𝒌 −𝒙𝟎

These differences are denoted by 𝚫𝟐 𝒇, 𝚫𝟑 𝒇 … … . 𝚫𝒌 𝒇.

Dr. Jamil Book Series 2 Page 20


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Divided Difference Table”

𝒙 𝒇 ∆𝒇 ∆𝟐 𝒇 ∆𝟑 𝒇

𝒙𝟎 𝒇( 𝒙 𝟎 )
𝒇(𝒙𝟏 )−𝒇(𝒙𝟎 )
𝒇[𝒙𝟎 , 𝒙𝟏 ] =
𝒙𝟏 −𝒙𝟎

𝒇[𝒙𝟏 ,𝒙𝟐 ]−𝒇[𝒙𝟎 ,𝒙𝟏 ]


𝒙𝟏 𝒇( 𝒙 𝟏 ) 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ] = 𝒙𝟐 −𝒙𝟎

𝒇(𝒙𝟐 )−𝒇(𝒙𝟏 ) 𝒇[𝒙𝟏 ,𝒙𝟐 ,𝒙𝟑 ]−𝒇[𝒙𝟎 ,𝒙𝟏 ,𝒙𝟐 ]


𝒇[𝒙𝟏 , 𝒙𝟐 ] = 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] =
𝒙𝟐 −𝒙𝟏 𝒙𝟑 −𝒙𝟎

𝒇[𝒙𝟐 ,𝒙𝟑 ]−𝒇[𝒙𝟏 ,𝒙𝟐 ]


𝒙𝟐 𝒇( 𝒙 𝟐 ) 𝒇[𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] =
𝒙𝟑 −𝒙𝟏

𝒇(𝒙𝟑 )−𝒇(𝒙𝟐 )
𝒇[𝒙𝟐 , 𝒙𝟑 ] =
𝒙𝟑 −𝒙𝟐

𝒙𝟑 𝒇( 𝒙 𝟑 )

Example # 10:-
Make divided difference table for the data:

𝒙 -1 0 1 3
𝒚(𝒙) = 𝒇(𝒙) 2 1 0 -1

Solution:-
“Divided Difference Table”

𝒙 𝒇 𝚫𝐟 ∆𝟐 𝒇 ∆𝟑 𝒇

−𝟏𝒙𝟎 𝟐𝒇(𝒙𝟎)
𝟏−𝟐
= −𝟏𝒇[𝒙𝟎,𝒙𝟏]
𝟎−(−𝟏)
−𝟏−(−𝟏)
𝟎𝒙𝟏 𝟏𝒇(𝒙𝟏) = 𝟎𝒇[𝒙𝟎,𝒙𝟏 ,𝒙𝟐]
𝟏−(−𝟏)
𝟏
𝟎−𝟏 𝟔
−𝟎 𝟏
= −𝟏𝒇[𝒙𝟏,𝒙𝟐] =
𝟏−𝟎 𝟑−(−𝟏) 𝟐𝟒𝒇[𝒙 ,𝒙 ,𝒙 ,𝒙 ]
𝟎 𝟏 𝟐 𝟑
𝟏
−𝟐−(−𝟏) 𝟏
𝟏𝒙𝟐 𝟎𝒇(𝒙𝟐) =
𝟑−𝟎 𝟔𝒇[𝒙𝟏 ,𝒙𝟐 ,𝒙𝟑 ]

−𝟏−𝟎 𝟏
=−
𝟑−𝟏 𝟐𝒇[𝒙𝟐 ,𝒙𝟑 ]

𝟑𝒙𝟑 −𝟏𝒇(𝒙𝟑)

Dr. Jamil Book Series 2 Page 21


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

5): Newton’s Divided Difference Interpolation Formula:-


The Newton’s divided difference interpolation polynominal formula is give by (without
proof):

𝒚 = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝒇(𝒙𝟎 ) + (𝒙 − 𝒙𝟎 )𝒇[𝒙𝟎 , 𝒙𝟏 ] + (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]


+(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] + ⋯
+ (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏−𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 ]

Example # 11:-
For the data:

𝒙 -1 0 2 5
𝒚(𝒙) = 𝒇(𝒙) 7 10 22 235

Find the divided difference polynominal and estimate 𝒚(𝟏).


Solution:-
“Divided difference table”

𝒙 𝒇 𝜟𝒇 ∆𝟐 𝒇 ∆𝟑 𝒇
-1 7
3
0 10 1
6 2
2 22 13
71
5 235

From the above table, we have


𝒇(𝒙𝟎 ) = 𝟕, 𝒇[𝒙𝟎 , 𝒙𝟏 ] = 𝟑, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ] = 𝟏, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] = 𝟐

The Newton’s divided difference interpolation polynominal formula is given by

𝑷(𝒙) = 𝒇(𝒙𝟎 ) + (𝒙 − 𝒙𝟎 )𝒇[𝒙𝟎 , 𝒙𝟏 ] + (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]

+(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ]

Substituting values, we get

𝑷(𝒙) = 𝟕 + (𝒙 + 𝟏) (𝟑) + (𝒙 + 𝟏) (𝒙 − 𝟎) (𝟏) + (𝒙 + 𝟏) (𝒙 + 𝟎) (𝒙 − 𝟐)(𝟐)

Dr. Jamil Book Series 2 Page 22


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒚(𝒙) = 𝒇(𝒙) = 𝑷(𝒙) = 𝟐𝒙𝟑 − 𝒙𝟐 + 𝟏𝟎

Hence

𝒚(𝟏) = 𝒇(𝟏) ≅ 𝑷(𝟏) = 𝟐(𝟏)𝟑 − (𝟏)𝟐 + 𝟏𝟎 = 𝟏𝟏

Example # 12:-
Using Newton’s divided difference formula find the value of 𝒚(𝟐), 𝒚(𝟖) and 𝒚(𝟏𝟓) given the
following table:

𝒙 4 5 7 10 11 13
𝒚(𝒙) = 𝒇(𝒙) 48 100 294 900 1210 2028

𝒙 𝒇 ∆𝒇 ∆𝟐 𝒇 ∆𝟑 𝒇 ∆𝟒 𝒇 ∆𝟓 𝒇

4 48

52

5 100 15

97 1

7 294 21 0

202 1 0

10 900 27 0

310 1

11 1210 33

409

13 2028

Solution:-
“Divided difference table”

From the above table, we have

⇒ 𝒇(𝒙𝟎 ) = 𝟒𝟖, 𝒇[𝒙𝟎 , 𝒙𝟏 ] = 𝟓𝟐, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ] = 𝟏𝟓, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] = 𝟏,


𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 , 𝒙𝟒 ] = 𝟎, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 , 𝒙𝟒 , 𝒙𝟓 ] = 𝟎

The Newton’s divided difference interpolation polynomial formula is given by:

Dr. Jamil Book Series 2 Page 23


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒇(𝒙𝟎 ) + (𝒙 − 𝒙𝟎 )𝒇[𝒙𝟎 , 𝒙𝟏 ] + (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ] +

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] + 𝟎 + 𝟎


Substituting values we get

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝟒𝟖 + (𝒙 − 𝟒)(𝟓𝟐) + ((𝒙 − 𝟒)(𝒙 − 𝟓)(𝟏𝟓) + (𝒙 − 𝟒)(𝒙 − 𝟓)(𝒙 − 𝟕)(𝟏)

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝟒𝟖 + 𝟓𝟐 (𝒙 − 𝟒) + 𝟏𝟓(𝒙 − 𝟒)(𝒙 − 𝟓) + (𝒙 − 𝟒)(𝒙 − 𝟓)(𝒙 − 𝟕)

Then
𝒚(𝟐) ≅ 𝑷(𝟐) = 𝟒𝟖 − 𝟏𝟎𝟒 + 𝟗𝟎 − 𝟑𝟎 = 𝟒

𝒚(𝟖) ≅ 𝑷(𝟖) = 𝟒𝟖 + 𝟓𝟐(𝟒) + 𝟏𝟓(𝟒)(𝟑) + (𝟒)(𝟑)(𝟏) = 𝟒𝟒𝟖

𝒚(𝟏𝟓) ≅ 𝑷(𝟏𝟓) = 𝟒𝟖 + 𝟓𝟐(𝟏𝟏) + 𝟏𝟓(𝟏𝟏)(𝟏𝟎) + (𝟏𝟏)(𝟏𝟎)(𝟖) = 𝟑𝟏𝟓𝟎

Drill Excercise # 6:-


Find the Newton’s divided difference polynominal of the following data, and find 𝒚(𝟐. 𝟓)

𝒙 0 1 3 4

𝒚(𝒙) = 𝒇(𝒙) 1 4 40 85

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝒙𝟑 + 𝒙𝟐 + 𝒙 + 𝟏

Drill Excercise # 7:-


Find the missing values in the following data using Newton’s divided difference
formula:

𝒙 3 6 7 8 9 10

𝒚(𝒙) = 𝒇(𝒙) 168 - 120 - 72 63

Answer:-
𝒇(𝟔) = 𝟏𝟒𝟕 , 𝒇(𝟖) = 𝟗𝟑

Dr. Jamil Book Series 2 Page 24


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 8:-


The Pressure drop that occurs when water flows through an orifice meter is measured using a
differential Pressure transmitter. The output current is converted to voltage drop by a resister.
The objective is to correlate the flow rate 𝑭 (𝒈 𝒎𝒊𝒏−𝟏 ) with the voltage drop 𝑷 (𝒎 𝑽). The
following data were collected from an experiment:

𝑭 (𝒈 𝒎𝒊𝒏−𝟏 ) 3 5 6 9

𝑷 (𝒎 𝑽) 293 508 585 764

(i): Derive a polynomial passing through these data points using Newton’s Divided
interpolation method
(ii): Write Polynomial in simplest form.
(iii): Use this Polynomial to estimate 𝑷 at 𝟕 (𝒈 𝒎𝒊𝒏−𝟏 ) flow rate.
(iv): Interpret and conclude your results.
Answer:-
𝑷(𝑭) = 𝒇 (𝑭) ≈ 𝑷 (𝑭) =

Dr. Jamil Book Series 2 Page 25


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Lines, Parabolas & Cubic Curves

S.N. Linear, First Degree Parabolic, Second Cubic Equation, 3rd Degree
Equation Degree, Quadratic Equation
Equation

𝒂𝒙 + 𝒃 = 𝟎 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄 = 𝟎 𝒂𝒙𝟑 + 𝒃𝒙𝟐 + 𝒄𝒙 + 𝒅 = 𝟎

Dr. Jamil Book Series 2 Page 26


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

6): Cubic Spline Interpolation Polynomial Method


Introduction:-
We are given the (𝒏 + 𝟏) data points (𝒙𝒊 , 𝒚𝒊 ), 𝒊 = 𝟎, 𝟏, 𝟐, … … , 𝒏

Our aim is to find the value of 𝒚 corresponding to 𝒙, where 𝒙𝒊−𝟏 < 𝒙 < 𝒙𝒊 , 𝒊 = 𝟎, 𝟏, 𝟐, … . . 𝒏,
by using a smooth polynomial curve. We have already seen many methods. A recent one
which is becoming important is the spline-fitting.

Dr. Jamil Book Series 2 Page 27


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Assumption for Cubic Spline Polynomial 𝑺(𝒙):-


1): 𝑺(𝒙) is a polynomial of degree one for 𝒙 < 𝒙𝟎 and 𝒙 > 𝒙𝒏

2): 𝑺(𝒙) is at most a cubic polynomial in each interval (𝒙𝒊−𝟏 , 𝒙𝒊 ), 𝒊 = 𝟏, 𝟐, … . , 𝒏

3): 𝑺(𝒙), 𝑺′(𝒙) and 𝑺"(𝒙)are continuous at each point (𝒙𝒊 , 𝒚𝒊 ), 𝒊 = 𝟎, 𝟏, 𝟐, … . 𝒏

4): 𝑺(𝒙𝒊 ) = 𝒚𝒊 , 𝒊 = 𝟎, 𝟏, 𝟐, … . , 𝒏

Cubic Spline Interpolation Polynomial Method:-


The cubic spline interpolation polynomial 𝑺(𝒏) in the 𝒊𝒕𝒉 interval (𝒙𝒊−𝟏 , 𝒙𝒊 ) is given by

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏 (1)
𝟔

𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = 𝒉𝟐 [𝒚𝒊−𝟏 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ], 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏 − 𝟏 (2)

and

𝑴𝟎 = 𝑴𝒏 = 𝟎 (3)

Equations (2) and (3) give (𝒏 + 𝟏) equations in (𝒏 + 𝟏) unknowns, 𝑴𝟎 , 𝑴𝟏 , 𝑴𝟐 , … . , 𝑴𝒏 .


Hence, we can solve for 𝑴𝟎 , 𝑴𝟏 , 𝑴𝟐 , … . , 𝑴𝒏 , substituting in (1), we get the cubic spline in
each interval.
Note:-
Some authors do not assume linearity of 𝑺(𝒙) for 𝒙 < 𝒙𝟎 and 𝒙 > 𝒙𝒏 .In that case 𝑴𝟎 , 𝑴𝒏
will not be zero.
Examples

Points Range of Eq. (1) 𝑴 𝟎 = 𝑴𝒏 = 𝟎 Range of Eq. (2)

9 𝒊 = 𝟏, 𝟐, 𝟑, 𝟒, 𝟓, 𝟔, 𝟕, 𝟖 𝑴 𝟎 = 𝑴𝟖 = 𝟎 𝒊 = 𝟏, 𝟐, 𝟑, 𝟒, 𝟓, 𝟔, 𝟕
𝑴𝟏 , 𝑴𝟐 , 𝑴𝟑 , 𝑴𝟒 , 𝑴𝟓 , 𝑴𝟔 , 𝑴𝟕
7 𝒊 = 𝟏, 𝟐, 𝟑, 𝟒, 𝟓, 𝟔 𝑴 𝟎 = 𝑴𝟔 = 𝟎 𝒊 = 𝟏, 𝟐, 𝟑, 𝟒, 𝟓
𝑴𝟏 , 𝑴𝟐 , 𝑴𝟑 , 𝑴𝟒 , 𝑴𝟓
5 𝒊 = 𝟏, 𝟐, 𝟑, 𝟒 𝑴 𝟎 = 𝑴𝟒 = 𝟎 𝒊 = 𝟏, 𝟐, 𝟑
𝑴𝟏 , 𝑴𝟐 , 𝑴𝟑
3 𝒊 = 𝟏, 𝟐 𝑴 𝟎 = 𝑴𝟐 = 𝟎 𝒊=𝟏
𝑴𝟏

Dr. Jamil Book Series 2 Page 28


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Example # 13:-
From the following table:

𝒙 1 2 3
𝒙𝟎 𝒙𝟏 𝒙𝟐

𝒚(𝒙) -8 -1 18
𝒚𝟎 𝒚𝟏 𝒚𝟐

Compute 𝒚(𝟏. 𝟓)and 𝒚′(𝟏),using Cubic Spline.


Solution:-
Here 𝒉 = 𝟏 , 𝒏 = 𝟐, then 𝑴𝟎 = 𝑴𝟐 = 𝟎. We have
𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = 𝟐 [𝒚𝒊−𝟏 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ], 𝒊=𝟏
𝒉

For 𝒊 = 𝟏, we get:-
𝟔
⟹ 𝑴𝟎 + 𝟒𝑴𝟏 + 𝑴𝟐 = [𝒚 − 𝟐𝒚𝟏 + 𝒚𝟐 ]
𝟏𝟐 𝟎

⟹ 𝟒𝑴𝟏 = 𝟔[−𝟖 − 𝟐(−𝟏) + 𝟏𝟖] = 𝟕𝟐

⟹ 𝑴𝟏 = 𝟏𝟖

The cubic spline interpolation polynomial is given by

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐 (1)
𝟔

For 𝟏 ≤ 𝒙 ≤ 𝟐, Putting 𝒊 = 𝟏, in Eq. (1), we get:-


𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝟏 − 𝒙) 𝑴𝟎 + (𝒙 − 𝒙𝟎 ) 𝑴𝟏 ] + (𝒙𝟏 − 𝒙) [𝒚𝟎 − 𝑴𝟎 ]
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟎 ) [𝒚𝟏 − 𝑴𝟏 ]
𝒉 𝟔
Substituting the values, we get

𝟏 𝟏 𝟏 𝟏
𝑺(𝒙) = [𝟎 + (𝟐 − 𝒙)(−𝟖 − 𝟎) + (𝒙 − 𝟏)[−𝟏 − (𝟏𝟖)]
𝟔 𝟏 𝟏 𝟔

Dr. Jamil Book Series 2 Page 29


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟏
𝑺(𝒙) = [𝟏𝟖(𝒙 − 𝟏)𝟑 ] + (𝟐 − 𝒙)(−𝟖) + (𝒙 − 𝟏)(−𝟒)
𝟔𝒉

𝑺(𝒙) = 𝟑(𝒙 − 𝟏)𝟑 + 𝟒𝒙 − 𝟏, For 𝟏 ≤ 𝒙 ≤ 𝟐

𝑺(𝒙) = 𝟑𝒙𝟑 − 𝟗𝒙𝟐 + 𝟏𝟑𝒙 − 𝟏𝟓 , For 𝟏 ≤ 𝒙 ≤ 𝟐

Hence
−𝟒𝟓
𝒚(𝟏. 𝟓) ≅ 𝑺(𝟏. 𝟓) = 𝟑(𝟏. 𝟓)𝟑 − 𝟗(𝟏. 𝟓)𝟐 + 𝟏𝟑(𝟏. 𝟓) − 𝟏𝟓 =
𝟖
𝟒𝟓
𝒚(𝟏. 𝟓) = −
𝟖
and

𝒚′ (𝒙) ≅ 𝑺′ (𝒙) = 𝟗𝒙𝟐 − 𝟏𝟖𝒙 + 𝟏𝟑

Therefore

𝒚′ (𝟏) = 𝑺′ (𝟏) = 𝟗(𝟏)𝟐 − 𝟏𝟖(𝟏) + 𝟏𝟑 = 𝟒

Note:-
We can also find 𝑺(𝒙) in the interval (𝟐, 𝟑)using equation (1) for 𝒊 = 𝟐. Since 𝒚(𝟏. 𝟓) is
required, we have not cared to find 𝑺(𝒙) in (𝟐, 𝟑).

Example # 14:-
Using Cubic Spline, find 𝒚(𝟎. 𝟓) and 𝒚′(𝟏) given that 𝑴𝟎 = 𝑴𝟐 = 𝟎 and the table:

𝒙 0 1 2
𝒙𝟎 𝒙𝟏 𝒙𝟐

𝒚(𝒙) -5 -4 3
𝒚𝟎 𝒚𝟏 𝒚𝟐

Solution:-
Here 𝒉 = 𝟏 and 𝒏 = 𝟐 and 𝑴𝟎 = 𝑴𝟐 = 𝟎. We have
𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = [𝒚 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ], 𝒊=𝟏
𝒉𝟐 𝒊−𝟏

For 𝒊 = 𝟏, we get:-
𝟔
𝑴𝟎 + 𝟒𝑴𝟏 + 𝑴𝟐 = [𝒚 − 𝟐𝒚𝟏 + 𝒚𝟐 ]
𝟏𝟐 𝟎

Dr. Jamil Book Series 2 Page 30


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟒𝑴𝟏 = 𝟔[−𝟓 − 𝟐(−𝟒) + 𝟑] = 𝟑𝟔

⟹ 𝟒𝑴𝟏 = 𝟑𝟔

⟹ 𝑴𝟏 = 𝟗

The cubic spline interpolation polynomial is given by

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐 (1)
𝟔

For 𝟏 ≤ 𝒙 ≤ 𝟐, Putting 𝒊 = 𝟏, in Eq. (1), we get:-


𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝟏 − 𝒙) 𝑴𝟎 + (𝒙 − 𝒙𝟎 ) 𝑴𝟏 ] + (𝒙𝟏 − 𝒙) [𝒚𝟎 − 𝑴𝟎 ]
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟎 ) [𝒚𝟏 − 𝑴 ]
𝒉 𝟔 𝟏
Substituting the values, we get

𝟏 𝟗
⟹ 𝑺(𝒙) = [𝟎 + (𝒙 − 𝟎)𝟑 (𝟗)] + (𝟏 − 𝒙)(−𝟓 − 𝟎) + (𝒙 − 𝟎) (−𝟒 − )
𝟔 𝟔

𝟑 𝟑𝟑
⟹ 𝑺(𝒙) = (𝒙)𝟑 − 𝟓(𝟏 − 𝒙) − 𝒙
𝟐 𝟔

𝟑 𝒙
⟹ 𝑺(𝒙) = (𝒙)𝟑 − − 𝟓 , For 𝟎 ≤ 𝒙 ≤ 𝟏
𝟐 𝟐

𝟑 𝟏 𝟑 𝟏 𝟏 𝟖𝟏
⟹ 𝒚(𝟎. 𝟓) ≅ 𝑺(𝟎. 𝟓) = ( ) − ( ) ( ) − 𝟓 = −
𝟐 𝟐 𝟐 𝟐 𝟏𝟔
and
𝟗 𝟏
𝒚′ (𝒙) ≅ 𝑺′ (𝒙) = (𝒙)𝟐 − ( )
𝟐 𝟐
Therefore
𝟗 𝟏
𝒚′(𝟏) ≅ 𝑺′(𝟏) = (𝟏)𝟐 − ( ) = 𝟒
𝟐 𝟐

Dr. Jamil Book Series 2 Page 31


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Example # 15:-
Find the Cubic Spline Interpolation Polynomial for the data given below under the conditions
𝑴(𝟎) = 𝑴(𝟑) = 𝟎 and valid in the sub-interval [𝟏, 𝟐]. Hence find 𝒇(𝟏. 𝟓):

𝒙 𝟎 𝟏 𝟐 𝟑
𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑
𝒚 = 𝒇(𝒙) 𝟏 𝟒 𝟏𝟎 𝟖
𝒚𝟎 𝒚𝟏 𝒚𝟐 𝒚𝟑

Answer:-
Here 𝒉 = 𝟏, 𝒏 = 𝟑 and 𝑴𝟎 = 𝑴𝟑 = 𝟎. We have

𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = [𝒚𝒊−𝟏 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ] , 𝒊 = 𝟏, 𝟐
𝒉𝟐

For 𝒊 = 𝟏, 𝟐 in above equation, we get:-

𝟔
𝑴𝒐 + 𝟒𝑴𝟏 + 𝑴𝟐 = [𝒚𝟎 − 𝟐𝒚𝟏 + 𝒚𝟐 ]
𝒉𝟐

𝟔
𝑴𝟏 + 𝟒𝑴𝟐 + 𝑴𝟑 = [𝒚𝟏 − 𝟐𝒚𝟐 + 𝒚𝟑 ]
𝒉𝟐

Since 𝑴𝟎 = 𝑴𝟑 = 𝟎 𝒂𝒏𝒅 𝒉 = 𝟏, and substituting values, we get

⇒ 𝟒𝑴𝟏 + 𝑴𝟐 = 𝟔(𝟏 − 𝟐(𝟒) + 𝟏𝟎) = 𝟏𝟖 ⇒ 𝟒𝑴𝟏 + 𝑴𝟐 = 𝟏𝟖

⇒ 𝑴𝟏 + 𝟒𝑴𝟐 = 𝟔(𝟐 − 𝟐(𝟏𝟎) + 𝟖) = −𝟒𝟖 ⇒ 𝑴𝟏 + 𝟒𝑴𝟐 = −𝟒𝟖

Solving simultaneously, we get 𝑴𝟏 = 𝟖 , 𝑴𝟐 = −𝟏𝟒. The cubic Spline interpolation


Polynomial is given by:

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐,3 (1)
𝟔

For 𝟏 ≤ 𝒙 ≤ 𝟐 , Putting 𝒊 = 𝟐 in Eq. (1), we get:-

𝟏 𝟑 𝟑 𝟏 𝒉𝟐
𝑺(𝒙) = 𝟔𝒉 [(𝒙𝟐 − 𝒙) 𝑴𝟏 + (𝒙 − 𝒙𝟏 ) 𝑴𝟐 ] + 𝒉 (𝒙𝟐 − 𝒙) [𝒚𝟏 − 𝑴𝟏 ]
𝟔

𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟐 ) [𝒚𝟐 − 𝑴 ]
𝒉 𝟔 𝟐
Dr. Jamil Book Series 2 Page 32
Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Substituting values, we have

𝟏 𝟏 𝟏 𝟏 𝟏𝟒
𝑺(𝒙) = [(𝟐 − 𝒙)𝟑 . 𝟖 + (𝒙 − 𝟏)𝟑 (−𝟏𝟒)] + (𝟐 − 𝒙) [𝟒 − 𝟖] + (𝒙 − 𝟐) [𝟏𝟎 + ]
𝟔 𝟏 𝟔 𝟏 𝟔

𝟏
𝒚(𝒙) = 𝒇(𝒙) = 𝑺(𝒙) = (−𝟏𝟏𝒙𝟑 + 𝟒𝟓𝒙𝟐 − 𝟒𝟎𝒙 + 𝟏𝟖), 𝐅𝐨𝐫 𝟏 ≤ 𝒙 ≤ 𝟐 → (𝟐)
𝟑

For 𝒚(𝟏. 𝟓) we use Eq. (2), therefore

𝟏
𝒚(𝟏. 𝟓) = 𝑺(𝟏. 𝟓) = {−𝟏𝟏(𝟏. 𝟓)𝟑 + 𝟒𝟓(𝟏. 𝟓)𝟐 − 𝟒𝟎(𝟏. 𝟓) + 𝟏𝟖} = 𝟕. 𝟑𝟕𝟓
𝟑

Example # 16:-
Find the Cubic Spline Polynomial in each interval for the function given below:

𝒙 0 1 2 3
𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑

𝒚 = 𝒇(𝒙) 1 2 33 244
𝒚𝟎 𝒚𝟏 𝒚𝟐 𝒚𝟑

Assume 𝑴(𝟎) = 𝑴(𝟑) = 𝟎, 𝑨𝒍𝒔𝒐 𝒇𝒊𝒏𝒅 𝒇(𝟐. 𝟓)


Solution:-
Here 𝒉 = 𝟏, 𝒏 = 𝟑 and 𝑴𝟎 = 𝑴𝟑 = 𝟎. We have

𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = [𝒚𝒊−𝟏 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ] , 𝒊 = 𝟏, 𝟐
𝒉𝟐

For 𝒊 = 𝟏, 𝟐 in above equation, we get:-


𝟔
𝑴𝒐 + 𝟒𝑴𝟏 + 𝑴𝟐 = [𝒚𝟎 − 𝟐𝒚𝟏 + 𝒚𝟐 ]
𝒉𝟐

𝟔
𝑴𝟏 + 𝟒𝑴𝟐 + 𝑴𝟑 = [𝒚𝟏 − 𝟐𝒚𝟐 + 𝒚𝟑 ]
𝒉𝟐

Since 𝑴𝟎 = 𝑴𝟑 = 𝟎, and substituting values, we get

⇒ 𝟒𝑴𝟏 + 𝑴𝟐 = 𝟔(𝟏 − 𝟒 + 𝟑𝟑) = 𝟏𝟖𝟎

⇒ 𝑴𝟏 + 𝟒𝑴𝟐 = 𝟔(𝟐 − 𝟔𝟔 + 𝟐𝟒𝟒) = 𝟏𝟎𝟖𝟎

Dr. Jamil Book Series 2 Page 33


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Solving simultaneously, we get 𝑴𝟏 = −𝟐𝟒 , 𝑴𝟐 = 𝟐𝟕𝟔. The cubic Spline interpolation


Polynomial is given by:

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐, 𝟑 (1)
𝟔

1): For 𝟎 ≤ 𝒙 ≤ 𝟏 , Putting 𝒊 = 𝟏 in Eq. (1), we get:-

We get
𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝟏 − 𝒙) 𝑴𝟎 + (𝒙 − 𝒙𝟎 ) 𝑴𝟏 ] + (𝒙𝟏 − 𝒙) [𝒚𝟎 − 𝑴𝟎 ]
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟎 ) [𝒚𝟏 − 𝑴𝟏 ]
𝒉 𝟔

Substituting values we have,

𝟏 𝟏 (−𝟐𝟒)
⇒ 𝑺(𝒙) = [(𝟏 − 𝒙)𝟑 (𝟎) + (𝒙 − 𝟎)𝟑 (−𝟐𝟒) + (𝟏 − 𝒙) [𝟏 − (𝟎)] + (𝒙 − 𝟎)[𝟐 − ]
𝟔 𝟔 𝟔

⇒ 𝑺(𝒙) = −𝟒𝒙𝟑 + (𝟏 − 𝒙) + 𝟔𝒙

⇒ 𝑺(𝒙) = −𝟒𝒙𝟑 + 𝟓𝒙 + 𝟏 , 𝑭𝒐𝒓 𝟎 ≤ 𝒙 ≤ 𝟏 (2)

2): For 𝟏 ≤ 𝒙 ≤ 𝟐 , Putting 𝒊 = 𝟐 in Eq. (1), we get:-


𝟏 𝟑 𝟑 𝟏 𝒉𝟐
𝑺(𝒙) = 𝟔𝒉 [(𝒙𝟐 − 𝒙) 𝑴𝟏 + (𝒙 − 𝒙𝟏 ) 𝑴𝟐 ] + 𝒉 (𝒙𝟐 − 𝒙) [𝒚𝟏 − 𝑴𝟏 ]
𝟔

𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟐 ) [𝒚𝟐 − 𝑴 ]
𝒉 𝟔 𝟐
Substituting values, we have

𝑺(𝒙) = 𝟏/𝟔[(𝟐 − 𝒙)𝟑 (−𝟐𝟒) + (𝒙 − 𝟏) (𝟐𝟕𝟔)] + (𝟐 − 𝒙)[𝟐 − (−𝟐𝟒/𝟔)]


+ (𝒙 − 𝟏)[𝟑𝟑 − 𝟐𝟕𝟔/𝟔]

⇒ 𝑺(𝒙) = 𝟓𝟎𝒙𝟑 − 𝟏𝟔𝟐𝒙𝟐 + 𝟏𝟔𝟕𝒙 − 𝟓𝟑, 𝑭𝒐𝒓 𝟏 ≤ 𝒙 ≤ 𝟐 (3)

3): For 𝟐 ≤ 𝒙 ≤ 𝟑 , Putting 𝒊 = 𝟑 in Eq. (1), we get:-


We get

Dr. Jamil Book Series 2 Page 34


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟏 𝟑 𝟑 𝟑 𝟏 𝒉𝟐
𝑺(𝒙) = 𝟔𝒉 [(𝒙 − 𝒙) 𝑴𝟐 + (𝒙 − 𝒙𝟐 ) 𝑴𝟑 ] + 𝒉 (𝒙𝟑 − 𝒙) [𝒚𝟐 − 𝑴𝟐 ]
𝟔

𝟏 𝒉𝟐
+ (𝒙 − 𝒙𝟐 ) [𝒚𝟑 − 𝑴 ]
𝒉 𝟔 𝟑

Substituting values, we have

𝟏 𝟏 𝟏
⇒ 𝑺(𝒙) = [(𝟑 − 𝒙)𝟑 (𝟐𝟕𝟔) + (𝒙 − 𝟐)𝟑 (𝟎)] +(𝟑 − 𝒙) [𝟑𝟑 − (𝟐𝟕𝟔)] + (𝒙 − 𝟐)[𝟐𝟒𝟒 − (𝟎)]
𝟔 𝟔 𝟔

⇒ 𝑺(𝒙) = 𝟒𝟔(𝟑 − 𝒙)𝟑 − 𝟏𝟑(𝟑 − 𝒙) + 𝟐𝟒𝟒(𝒙 − 𝟐)

⇒ 𝑺(𝒙) = 𝟒𝟔[𝟐𝟕 − 𝟐𝟕𝒙 + 𝟗𝒙𝟐 − 𝒙𝟑 ] − 𝟑𝟗 + 𝟏𝟑𝒙 + 𝟐𝟒𝟒𝒙 − 𝟒𝟖𝟖

⇒ 𝑺(𝒙) = −𝟒𝟔𝒙𝟑 + 𝟒𝟏𝟒𝒙𝟐 − 𝟗𝟖𝟓𝒙 + 𝟕𝟏𝟓 , 𝑭𝒐𝒓 𝟐 ≤ 𝒙 ≤ 𝟑 (4)

Equations (2), (3) and (4) give the cubic Spline Polynomial in each sub-interval.
For 𝒚(𝟐. 𝟓) we use eq (4), therefore

𝒚(𝟐. 𝟓) = 𝑺(𝟐. 𝟓) = −𝟒𝟔(𝟐. 𝟓)𝟑 + 𝟒𝟏𝟒(𝟐. 𝟓)𝟐 − 𝟗𝟖𝟓(𝟐. 𝟓) + 𝟕𝟏𝟓

⇒ 𝒚(𝟐. 𝟓) ≅ 𝑺(𝟐. 𝟓) = 𝟏𝟐𝟏. 𝟐𝟓

Drill Excercise # 9:-


Find the cubic spline polynomial in [𝟎, 𝟏] for the following data:
𝒙 𝟎 𝟏 𝟐
𝒚 = 𝒇(𝒙) 𝟎 𝟐 𝟔

Also find 𝒚(𝟎. 𝟓) and 𝒚′(𝟏)

Answer:-
𝟏
𝑴𝟏 = 𝟑 , 𝑰𝒏 [𝟎, 𝟏] , 𝑺(𝒙) = (𝟑𝒙 + 𝒙𝟑 )
𝟐
𝟏𝟑
𝒚(𝟎. 𝟓) = , 𝒚′ (𝟏) = 𝟑
𝟏𝟔

Dr. Jamil Book Series 2 Page 35


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 10:-


Find the cubic spline polynomial for the data:
𝒙 𝟎 𝟏 𝟐

𝒚 = 𝒇(𝒙) 𝟎 𝟏 𝟎

Also find 𝒚(𝟎. 𝟓) and 𝒚′ (𝟏).


Answer:-
𝟏
𝑰𝒏 [𝟎, 𝟏] , 𝑴𝟏= − 𝟑 , 𝑺(𝒙) = (𝟑𝒙 − 𝒙𝟑 )
𝟐
𝟏𝟏
𝒚(𝟎. 𝟓) = , 𝒚′ (𝟏) = 𝟎
𝟔

Drill Excercise # 10:-


Make a Mathematical model through Cubic Spline Polynomial 𝑺(𝒙), 𝟐 ≤ 𝒙 ≤ 𝟒 for the given
table. Also find 𝒇(𝟑):(assume that 𝑴𝟎 = 𝟎, 𝑴𝟑 = −𝟏𝟐)

𝒙 0 2 4 6

𝒚(𝒙) 1 9 41 41

At the end put down your conclusions and express suitable interpretation either
physical/geometrical/technical or Mechanical on your method or results. What is your
understanding! Is 𝒇(𝟑) determination form Cubic Spline procedure in your thinking is the best
? Why ?

Important Example# 17(Uniquness of Polynomial Proof):-


From the following data:

𝒙 𝟎 𝒙𝟎 𝟏 𝒙𝟏 𝟑 𝒙𝟐 4 𝒙𝟑

𝒚 = 𝒇(𝒙) −𝟏𝟐 𝒚𝟎 𝟎 𝒚𝟏 𝟏𝟐 𝒚𝟐 12 𝒚𝟑

Use any two different method to find the polynomial passing through the data and prove
that the Polynomial is unique form any two different methods.
Solution:-
1): From Lagrange’s Interplation Plynomial Method:-

The Lagrange’s interpolation polynomial formula of degree at most 3 is given by (here 𝒏 =


𝟑):

Dr. Jamil Book Series 2 Page 36


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = 𝑳𝟎 (𝒙)𝒚𝟎 + 𝑳𝟏 (𝒙)𝒚𝟏 + 𝑳𝟐 (𝒙)𝒚𝟐 + 𝑳𝟑 (𝒙)𝒚𝟑 (1)

Now
(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟏)(𝒙 − 𝟑)(𝒙 − 𝟒)
𝑳𝟎 (𝒙) = =
(𝒙𝟎 − 𝒙𝟏 )(𝒙𝟎 − 𝒙𝟐 )(𝒙𝟎 − 𝒙𝟑 ) (𝟎 − 𝟏)(𝟎 − 𝟑)(𝟎 − 𝟒)

−𝟏 𝟑
𝑳𝟎 (𝒙) = (𝒙 − 𝟖𝒙𝟐 + 𝟏𝟗𝒙 − 𝟏𝟐)
𝟏𝟐

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟎)(𝒙 − 𝟑)(𝒙 − 𝟒) 𝟏 𝟑


𝑳𝟏 (𝒙) = = = (𝒙 − 𝟕𝒙𝟐 + 𝟏𝟐𝒙)
(𝒙𝟏 − 𝒙𝟎 )(𝒙𝟏 − 𝒙𝟐 )(𝒙𝟏 − 𝒙𝟑 ) (𝟏 − 𝟎)(𝟏 − 𝟑)(𝟏 − 𝟒) 𝟔

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟑 ) (𝒙 − 𝟎)(𝒙 − 𝟏)(𝒙 − 𝟒) −𝟏 𝟑


𝑳𝟐 (𝒙) = = = (𝒙 − 𝟓𝒙𝟐 + 𝟒𝒙)
(𝒙𝟐 − 𝒙𝟎 )(𝒙𝟐 − 𝒙𝟏 )(𝒙𝟐 − 𝒙𝟑 ) (𝟑 − 𝟎)(𝟑 − 𝟏)(𝟑 − 𝟒) 𝟔

(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 ) (𝒙 − 𝟎)(𝒙 − 𝟏)(𝒙 − 𝟑) 𝟏 𝟑


𝑳𝟑 (𝒙) = = = (𝒙 − 𝟒𝒙𝟐 + 𝟑𝒙)
(𝒙𝟑 − 𝒙𝟎 )(𝒙𝟑 − 𝒙𝟏 )(𝒙𝟑 − 𝒙𝟐 ) (𝟒 − 𝟎)(𝟒 − 𝟏)(𝟒 − 𝟑) 𝟏𝟐

Substituting these values in Eq. (1), we get

𝟏 𝟑 𝟏
𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = − (𝒙 − 𝟖𝒙𝟐 + 𝟏𝟗𝒙 − 𝟐)(−𝟏𝟐) + 𝟎 − (𝒙𝟑 − 𝟓𝒙𝟐 + 𝟒𝒙)(𝟏𝟐)
𝟏𝟐 𝟔
𝟏 𝟑
+ (𝒙 − 𝟒𝒙𝟐 + 𝟑𝒙)(𝟐𝟒)
𝟏𝟐

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒙𝟑 − 𝟖𝒙𝟐 + 𝟏𝟗𝒙 − 𝟏𝟐 − 𝟐𝒙𝟑 + 𝟏𝟎𝒙𝟐 − 𝟖𝒙 + 𝟐𝒙𝟑 − 𝟖𝒙𝟐 + 𝟔𝒙

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒙𝟑 − 𝟔𝒙𝟐 + 𝟏𝟕𝒙 − 𝟏𝟐 (2)

This is the required Lagrange’s interpolation polynomial. Also

2): From Newton’s Divided Interpolation Plynomial Method:-

Dr. Jamil Book Series 2 Page 37


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Divided difference table”

𝒙 𝒇 𝜟𝒇 ∆𝟐 𝒇 ∆𝟑 𝒇

0 -12

12
1 0 -2

6 1
3 12 2

12
4 24

From the above table, we have


𝒇(𝒙𝟎 ) = −𝟏𝟐, 𝒇[𝒙𝟎 , 𝒙𝟏 ] = 𝟏𝟐, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ] = −𝟐, 𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] = 𝟏

The Newton’s divided difference interpolation polynominal formula is given by

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒇(𝒙𝟎 ) + (𝒙 − 𝒙𝟎 )𝒇[𝒙𝟎 , 𝒙𝟏 ] + (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]

+(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ]

Substituting values, we get

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = −𝟏𝟐 + (𝒙 − 𝟎) (𝟏𝟐) + (𝒙 − 𝟎) (𝒙 − 𝟏) (−𝟐)


+ (𝒙 − 𝟎) (𝒙 − 𝟏) (𝒙 − 𝟑)(𝟏)

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = −𝟏𝟐 + 𝟏𝟐𝒙 − 𝟐𝒙𝟐 + 𝟐𝒙 + 𝒙𝟑 − 𝟒𝒙𝟐 + 𝟑𝒙

𝒚 = 𝒇(𝒙) = 𝑷(𝒙) = 𝒙𝟑 − 𝟔𝒙𝟐 + 𝟏𝟕𝒙 − 𝟏𝟐 (3)

This is the required Newton’s divided interpolation polynomial.

Conculusion:-
From Eqs.(2) and (3), it is clear that from two different methods the interpolation polynomial
passes through same data is same that is Unique. This prove the first segment of the theorem
that Polynomial is Unique.

Dr. Jamil Book Series 2 Page 38


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Comparison of Interpolation Methods


S.N. Methods Equal General OR Derivative Accuracy type Evaluation Preference
Spaced Unequal values Process
𝒉 Spaced Required

1 Lagrange’s NO YES NO Normal Difficult 2nd

2 Hermite’s NO YES YES High Highly Difficult 3rd

3 Newton’s Forwad YES NO NO High near Easy First


Initial of table

4 Newton’s Backward YES NO NO High near End Easy First


of table

5 Newton’s Divided NO YES NO Normal Less Difficult First

6 Cubic Spline YES NO NO High Highly Difficult 2nd

Drill Excercise # 10:-


The turbidity 𝑸 of an aqueous dispersion of silica changes over time 𝒕. The following data
represent some of the values when the concentration of solid have some particular value is

𝑻𝒊𝒎𝒆 𝒕 (𝑫𝒂𝒚𝒔) 1 3 4 6

𝑻𝒖𝒓𝒃𝒊𝒅𝒊𝒕𝒚 𝑸 (𝒄𝒎 −𝟏 ) -3 9 30 132

(i): Estimate the polynomial 𝑸 (𝒕) using best interpolation method (why) that you think.
(ii): Write Polynomial 𝑸 (𝒕) in simplest form.
(iii): Use this Polynomial to estimate 𝑸 at 𝟓 (𝑫𝒂𝒚𝒔) time.
(iv): Interpret, conclude and compose final remarks on your method & results.

Drill Excercise # 11:-


The following table gives corresponding values of velocity of a Particle at a given distance.

Distance: 𝒙 0 2 3 6 9 10

Velocity: 𝒚(𝒙) 3 7 24 207 714 983

1): Make a Mathematical Model using suitable interpolation polynomial method.


2): Write polynomial in in powers of (𝒙 − 𝟐).
3): Find the velocity for a distance of 8 kilometer.
4): Interpret and conclude your results.

Dr. Jamil Book Series 2 Page 39


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

CHAPTER # 2
PART-II: CURVE FITTING
Least Squares Method For Curve Fitting Method

Dr. Jamil Book Series 2 Page 40


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Introduction:-
Let 𝒚, 𝒚𝒊 = 𝑬𝒙𝒂𝒄𝒕 𝒗𝒂𝒍𝒖𝒆
̅ = 𝒇(𝒙), 𝒚
𝒚 ̅𝒊 = 𝒇(𝒙𝒊 ) = 𝑨𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒆 𝒗𝒂𝒍𝒖𝒆
Least square approximation is the most commonly used method for finding an approximate
curve for the given data dealing with science and engineering. This method was developed
by Legendre. Suppose we have given the following data:

Dr. Jamil Book Series 2 Page 41


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Table of values”

𝒙 𝒙𝟏 𝒙𝟐 … 𝒙𝒊 … 𝒙𝒏

𝒚(𝒙) = 𝒇(𝒙) 𝒚𝟏 𝒚𝟐 … 𝒚𝒊 … 𝒚𝒏

OR
(𝒙𝒊 , 𝒚𝒊 ), 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏

be the given data. Let 𝒚 = 𝒇(𝒙) be an approximation to the function 𝒚. The 𝒊𝒕𝒉 errors
between 𝒚′𝒔 of the data and 𝒚′𝒔 of the approximation are given by:

𝑬𝒊 = 𝒚𝒊 − 𝒚𝒊 = 𝒚𝒊 − 𝒇(𝒙𝒊 ), 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏

Since the error can be either +𝒗𝒆 or – 𝒗𝒆. We will consider 𝑬𝟐𝒊 .
𝟐
𝑬𝒊 𝟐 = (𝒚𝒊 − 𝒚𝒊 )𝟐 = (𝒚𝒊 − 𝒇(𝒙𝒊 )) , 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏

Then sum of squares of errors or total error is given by


𝒏 𝒏

𝑬 = ∑ 𝑬𝟐𝒊 = ∑[𝒚𝒊 − 𝒇(𝒙𝒊 )]𝟐


𝒊=𝟏 𝒊=𝟏

The basic least square principle is “to find 𝒚


̅ = 𝒇(𝒙) such that the sum of the squares of the
errors is minimum.”

Dr. Jamil Book Series 2 Page 42


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Method-1): Fitting a straight line by the method of least square:-


OR Linear approximation:-

Let
“Table of values”

𝒙 𝒙𝟏 𝒙𝟐 … 𝒙𝒊 … 𝒙𝒏

𝒚(𝒙) = 𝒇(𝒙) 𝒚𝟏 𝒚𝟐 … 𝒚𝒊 … 𝒚𝒏

OR
(𝒙𝒊 , 𝒚𝒊 ), 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏

Dr. Jamil Book Series 2 Page 43


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

be the given data. Suppose the approximate straight line be given by

𝒚(𝒙) = 𝒇(𝒙) = 𝒂𝒙 + 𝒃

Now we have to select 𝒂 and 𝒃 so that the straight line is the best fit to the data. The error is
given by
𝑬𝒊 = 𝒚𝒊 − 𝒚𝒊 = 𝒚𝒊 − 𝒇(𝒙𝒊 ) = 𝒚𝒊 − (𝒂𝒙𝒊 + 𝒃), 𝒊 = 𝟏, 𝟐, … , 𝒏

⟹ 𝑬𝟐𝒊 = [𝒚𝒊 − (𝒂𝒙𝒊 + 𝒃)]𝟐 , 𝒊 = 𝟏, 𝟐, … , 𝒏

The sum of squares of errors is given by

𝒏 𝒏

𝑬 = ∑ 𝑬𝟐𝒊 = ∑[𝒚𝒊 − (𝒂𝒙𝒊 + 𝒃)]𝟐


𝒊=𝟏 𝒊=𝟏

The principle of least squares, 𝑬 minimum condition provides the following normal
equations.
Normal Equations for straight line:-
𝒏 𝒏

𝒂 ∑ 𝒙𝒊 + 𝒏𝒃 = ∑ 𝒚𝒊
𝒊=𝟏 𝒊=𝟏

𝒏 𝒏 𝒏

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊
𝒊=𝟏 𝒊=𝟏 𝒊=𝟏
OR

𝒂 ∑ 𝒙𝒊 + 𝒏𝒃 = ∑ 𝒚𝒊

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

By solving these equations, we can determine 𝒂 and 𝒃 to obtain the best fitted straight
line 𝒚(𝒙) = 𝒇(𝒙) = 𝒂𝒙 + 𝒃 .

Example # 18:-
By the method of least squares find the best fitting straight line to the data given below:

𝒙 5 10 15 20 25

𝒚 = 𝒚(𝒙) 16 19 23 26 30

Solution:-
Let 𝒚 = 𝒂𝒙 + 𝒃 be the best fit straight line to the data. Then the normal equations are:

Dr. Jamil Book Series 2 Page 44


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒂 ∑ 𝒙𝒊 + 𝒏𝒃 = ∑ 𝒚𝒊 (1)

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊 (2)

To calculate ∑ 𝒙𝒊 , ∑ 𝒙𝟐𝒊 , ∑ 𝒚𝒊 , ∑ 𝒙𝒊 𝒚𝒊 we form below the table:

“Table of Values”
𝒙 𝒚 𝒙𝟐 𝒙𝒚

5 16 25 80

10 19 100 190

15 23 225 345

20 26 400 520

25 30 625 750

∑ 𝒙 = 𝟕𝟓 ∑ 𝒚 = 𝟏𝟏𝟒 ∑ 𝒙𝟐 = 𝟏𝟑𝟕𝟓 ∑ 𝒙𝒚 = 𝟏𝟖𝟖𝟓

Substituting the values in 𝑬𝒒. (𝟏) 𝒂𝒏𝒅 (𝟐), we get


𝟕𝟓𝒂 + 𝟓𝒃 = 𝟏𝟏𝟒

𝟏𝟑𝟕𝟓𝒂 + 𝟕𝟓𝒃 = 𝟏𝟖𝟖𝟓


Solving simultaneously these equations, we get

⇒ 𝒂 = 𝟎. 𝟕, 𝒃 = 𝟏𝟐. 𝟑
Hence the best fitting line is

𝒚 = 𝟎. 𝟕𝒙 + 𝟏𝟐. 𝟑

Drill Excercise # 11:-


Fit a straight line to the data, using least squares method. Hence find 𝒚(𝟐. 𝟓) .

𝒙 1 2 3 4 5

𝒚(𝒙) 16 19 23 26 30

Answer:-
𝒚 = 𝟑. 𝟓𝒙 + 𝟏𝟐. 𝟑

Dr. Jamil Book Series 2 Page 45


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 12:-


Fit a straight line to the data using least squares method. Hence find 𝒚(𝟐. 𝟓) .

𝒙 0 1 2 3 4

𝒚(𝒙) 1 1.8 3.3 4.5 6.3

Answer:-
𝒚 = 𝟏. 𝟑𝟑𝒙 + 𝟎. 𝟕𝟐, 𝒚(𝟐. 𝟓) = 𝟒. 𝟎𝟒𝟓

Drill Excercise # 13:-


Fit a straight line to the data using least squares method. Hence find 𝒚(𝟐𝟓) .

𝒙 0 5 10 15 20

𝒚(𝒙) 7 11 16 20 26

Answer:-

𝒚 = 𝟎. 𝟗𝟒𝒙 + 𝟔. 𝟔 , 𝒚(𝟐𝟓) = 𝟑𝟎. 𝟏

Drill Excercise # 14:-


Fit a curve of the form 𝒚(𝒙) = 𝒂𝒙 + 𝒃𝒙𝟐 to the following data by the method of least square:

𝒙 1 2 3 4 5

𝒚(𝒙) 1.8 5.1 8.9 14.1 19.8

Hint:-
Put 𝒀 = 𝒚/𝒙 = 𝒂 + 𝒃𝒙 (straight line case)
Answer:-
𝒚(𝒙) = 𝟏. 𝟑𝟕𝟏𝟖𝒙 + 𝟎. 𝟓𝟐𝟗𝟓𝒙𝟐

Drill Excercise # 15:-


Fit a curve of the form 𝒙𝒚 = 𝒂 + 𝒃𝒙𝟐 to the following data by the method of least square:

𝒙 1 2 4 6 8

𝒚(𝒙) 5.43 6.28 10.32 14.86 19.51

Hint:-
Put 𝒀 = 𝒙𝒚 , 𝑿 = 𝒙𝟐 (straight line case)
Answer:-
𝒙𝒚 = 𝟑. 𝟎𝟐𝟎𝟓 + 𝟐. 𝟑𝟗𝟏𝟖𝒙𝟐

Dr. Jamil Book Series 2 Page 46


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Method-2): Fitting a Parabola or fitting a second degree curve by the method of


least squares: OR Second degree approximation:-
Let
“Table of values”

𝒙 𝒙𝟏 𝒙𝟐 … 𝒙𝒊 … 𝒙𝒏

𝒚(𝒙) = 𝒇(𝒙) 𝒚𝟏 𝒚𝟐 … 𝒚𝒊 … 𝒚𝒏

OR
(𝒙𝒊 , 𝒚𝒊 ), 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏

be the given data. Suppose the approximate second degree curve be given by

𝒚(𝒙) = 𝒇(𝒙) = 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄

Now we have to select 𝒂, 𝒃 and 𝒄 so that the second degree curve is the best fit to the data.
The 𝒊𝒕𝒉 error is given by
𝑬𝒊 = 𝒚𝒊 − 𝒚𝒊 = 𝒚𝒊 − 𝒇(𝒙𝒊 ) = 𝒚𝒊 − (𝒂𝒙𝟐𝒊 + 𝒃𝒙𝒊 + 𝒄), 𝒊 = 𝟏, 𝟐, … , 𝒏

𝟐
⟹ 𝑬𝟐𝒊 = [𝒚𝒊 − (𝒂𝒙𝟐𝒊 + 𝒃𝒙𝒊 + 𝒄)]

Then sum of squares of errors is given by


𝒏 𝒏
𝟐
𝑬 = ∑ 𝑬𝟐𝒊 = ∑[𝒚𝒊 − (𝒂𝒙𝟐𝒊 + 𝒃𝒙𝒊 + 𝒄)]
𝒊=𝟏 𝒊=𝟏

Dr. Jamil Book Series 2 Page 47


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

By the principle of least squares, 𝑬 minimum condition provides the following normal
equations:

Normal Equations for Parabola or fitting a second degree curve:-

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 + 𝒏𝒄 = ∑ 𝒚𝒊

𝒂 ∑ 𝒙𝟑𝒊 + 𝒃 ∑ 𝒙𝟐𝒊 + 𝒄 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

𝒂 ∑ 𝒙𝟒𝒊 + 𝒃 ∑ 𝒙𝟑𝒊 + 𝒄 ∑ 𝒙𝟐𝒊 = ∑ 𝒙𝟐𝒊 𝒚𝒊

By solving these equations, we can determine 𝒂, 𝒃 and 𝒄 to obtain the best fit second degree
polynomial 𝒚(𝒙) = 𝒇(𝒙) = 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄 .

Example # 19:-
Fit a parabola, by the method of least squares, to the following data; also estimate 𝒚(𝟔) .

𝒙 1 2 3 4 5

𝒚(𝒙) 5 12 26 60 97

Solution:-

Let 𝒚 = 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄 be the best fit parabola. Then the normal equations are:

𝒂∑𝒙𝒊 𝟐 + 𝒃∑𝒙𝒊 + 𝒏𝒄 = ∑𝒚𝒊 (1)

𝒂∑𝒙𝒊 𝟑 + 𝒃∑𝒙𝒊 𝟐 + 𝒄∑𝒙𝒊 = ∑𝒙𝒊 𝒚𝒊 (2)

𝟑 𝟐
𝒂∑𝒙𝒊 𝟒 + 𝒃∑𝒙𝒊 + 𝒄∑𝒙𝒊 = ∑𝒙𝒊 𝟐 𝒚𝒊 (3)

Dr. Jamil Book Series 2 Page 48


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Tables of values”

𝒙 𝒚 𝒙𝟐 𝒙𝟑 𝒙𝟒 𝒙𝒚 𝒙𝟐 𝒚

1 5 1 1 1 5 5

2 12 4 8 16 24 48

3 26 9 27 81 78 234

4 60 16 64 256 240 960

5 97 25 125 625 485 2425

15 200 55 225 979 832 3672

∑𝒙𝒊 ∑𝒚𝒊 ∑𝒙𝒊 𝟐 ∑𝒙𝒊 𝟑 ∑𝒙𝒊 𝟒 ∑𝒙𝒊 𝒚𝒊 ∑𝒙𝒊 𝟐 𝒚𝒊

Hence the equation (𝟏), (𝟐) and (𝟑) become


𝟓𝟓𝒂 + 𝟏𝟓𝒃 + 𝟓𝒄 = 𝟐𝟎𝟎

𝟐𝟐𝟓𝒂 + 𝟓𝟓𝒃 + 𝟏𝟓𝒄 = 𝟖𝟑𝟐

𝟗𝟕𝟗𝒂 + 𝟐𝟐𝟓𝒃 + 𝟓𝟓𝒄 = 𝟑𝟔𝟕𝟐

Solving simultaneously these equations, we get

𝒂 = 𝟓. 𝟕𝟏𝟒𝟑 , 𝒃 = −𝟏𝟏. 𝟎𝟖𝟓𝟖 𝒂𝒏𝒅 𝒄 = 𝟏𝟎. 𝟒𝟎𝟎𝟏

Hence the best fitting Parabola is;

𝒚(𝒙) = 𝟓. 𝟕𝟏𝟒𝟑𝒙𝟐 − 𝟏𝟏. 𝟎𝟖𝟓𝟖𝒙 + 𝟏𝟎. 𝟒𝟎𝟎𝟏

and
𝒚(𝟔) = 𝟓. 𝟕𝟏𝟒𝟑(𝟔)𝟐 − 𝟏𝟏. 𝟎𝟖𝟓𝟖(𝟔) + 𝟏𝟎. 𝟒𝟎𝟎𝟏

𝒚(𝟔) = 𝟏𝟒𝟗. 𝟔𝟎𝟎𝟏

Dr. Jamil Book Series 2 Page 49


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 16:-


Fit a Parabola to the data; and find 𝒇(𝟒. 𝟓)

𝒙 𝟏 𝟐 𝟑 𝟒 𝟓
𝒚 𝟐 𝟑 𝟓 𝟖 𝟏𝟎

Answer:-

𝒚(𝒙) = 𝟎. 𝟒𝟎𝟑 + 𝟎. 𝟑𝟖𝟖𝒙 − 𝟐. 𝟕𝟗𝟎𝒙𝟐

Drill Excercise # 17:-


Fit a second degree Polynomial (Parabola) for the given data

𝒙 5 𝟏𝟎 𝟏𝟓 𝟐𝟎 𝟐𝟓
𝒚 𝟏𝟔 𝟏𝟗 𝟐𝟑 𝟐𝟔 𝟑𝟎

Answer:-

𝒚(𝒙) = 𝟏𝟐. 𝟖𝟎𝟕𝟓 + 𝟎. 𝟔𝟏𝟑𝟎𝒙 + 𝟎. 𝟎𝟎𝟐𝟗𝒙𝟐

Dr. Jamil Book Series 2 Page 50


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Important Note:-
The Normal Equations of the line 𝒚 = 𝒂𝒙 + 𝒃 (𝐇𝐞𝐫𝐞 𝐚 = 𝐒𝐥𝐨𝐩 𝐚𝐧𝐝 𝐛 = 𝐲 − 𝐢𝐧𝐭𝐞𝐫𝐜𝐞𝐩𝐭)
are :

𝒂 ∑ 𝒙𝒊 + 𝒏𝒃 = ∑ 𝒚𝒊

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

These equations can also be represent as:

𝐒𝐥𝐨𝐩 ∑ 𝒙𝒊 + 𝒏(𝐲 − 𝐢𝐧𝐭𝐞𝐫𝐬𝐞𝐩𝐭) = ∑ 𝒚𝒊

𝐒𝐥𝐨𝐩 ∑ 𝒙𝟐𝒊 + (𝐲 − 𝐢𝐧𝐭𝐞𝐫𝐬𝐞𝐩𝐭) ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

Method-3): Fitting an Exponential curve 𝒚 = 𝒂𝒃𝒙


Let the curve to be fitted be given by 𝒚 = 𝒂𝒃𝒙 .Then applying logarithm (of base 10) on both
sides, we get

𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒙𝒍𝒐𝒈𝒃

⟹ 𝒀 = 𝑨 + 𝑩𝒙 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑨 = 𝒍𝒐𝒈𝒂 , 𝑩 = 𝒍𝒐𝒈𝒃

This being linear in 𝒙 and 𝒀 , we can find 𝑨, 𝑩 since 𝒙 and 𝒀 = 𝒍𝒐𝒈𝒚 are known. From 𝑨, 𝑩
we can get 𝒂, 𝒃 by antilog (𝒂 = 𝟏𝟎𝑨 , 𝒃 = 𝟏𝟎𝑩 ) and hence 𝒚 = 𝒂𝒃𝒙 is found out.

Normal Equations of Exponential curve:-


In 𝒀 = 𝑨 + 𝑩𝒙, B is Slop representative and A is y-Intercept. Then Normal Equations of
the line 𝒀 = 𝑨 + 𝑩𝒙 are :

𝑩 ∑ 𝒙𝒊 + 𝒏𝑨 = ∑ 𝒀𝒊

𝑩 ∑ 𝒙𝟐𝒊 + 𝑨 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒀𝒊

Dr. Jamil Book Series 2 Page 51


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Method-4): Fitting a Polynomial curve of the form 𝒚 = 𝒂𝒙𝒃


Let the curve to be fitted be given by 𝒚 = 𝒂𝒙𝒃 .Then applying logarithm (of base 10) on both
sides, we get

⟹ 𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒃𝒍𝒐𝒈𝒙

⟹ 𝒀 = 𝑨 + 𝒃𝑿 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑿 = 𝒍𝒐𝒈𝒙 , 𝑨 = 𝒍𝒐𝒈𝒂

Again using this linear fit, we find 𝑨, 𝒃. Hence 𝒂, 𝒃 (𝒂 = 𝟏𝟎𝑨 ) are known. Thus 𝒚 = 𝒂𝒙𝒃 is
found out.
Normal Equations of Polynomial curve:-
In 𝒀 = 𝑨 + 𝒃𝑿are, b is Slop representative and A is y-Intercept. Then Normal Equations of
the line 𝒀 = 𝑨 + 𝒃𝑿are :

𝒃 ∑ 𝑿𝒊 + 𝒏𝑨 = ∑ 𝒀𝒊

𝒃 ∑ 𝑿𝟐𝒊 + 𝑨 ∑ 𝑿𝒊 = ∑ 𝑿𝒊 𝒀𝒊

Example # 20:-
Fit a curve of the form 𝒚 = 𝒂𝒃𝒙 to the data

𝒙 𝟏 𝟐 𝟑 𝟒 𝟓 𝟔

𝒚 = 𝒇(𝒙) 𝟏𝟓𝟏 𝟏𝟎𝟎 𝟔𝟏 𝟓𝟎 𝟐𝟎 𝟖

Solution:-
Since 𝒚 = 𝒂𝒃𝒙 , Applying logarithm on both sides;

⟹ 𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒙𝒍𝒐𝒈𝒃

⟹ 𝒀 = 𝑨 + 𝑩𝒙 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑨 = 𝒍𝒐𝒈𝒂 , 𝑩 = 𝒍𝒐𝒈𝒃

The normal equations are: (Here slope=B and y-intercept=A)

𝑩∑𝒙𝒊 + 𝒏𝑨 = ∑𝒀𝒊 (𝟏)

𝑩∑𝒙𝒊 𝟐 + 𝑨∑𝒙𝒊 = ∑𝒙𝒊 𝒀𝒊 (𝟐)

We form the table:

Dr. Jamil Book Series 2 Page 52


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

“Table of values”

𝒙 𝒚 𝒀 𝒙𝟐 𝒙𝒀

1 𝟏𝟓𝟏 2.1790 1 2.1790

2 𝟏𝟎𝟎 2.0 4 4.0

3 𝟔𝟏 1.7853 9 5.3559

4 𝟓𝟎 1.6990 16 6.7960

5 𝟐𝟎 1.3010 25 6.5050

6 𝟖 0.9031 36 5.4186

21 - 9.8674 91 30.2545

∑𝒙𝒊 ∑𝒚𝒊 ∑𝒀𝒊 ∑𝒙𝒊 𝟐 ∑𝒙𝒊 𝒀𝒊

Hence the equation (𝟏) 𝒂𝒏𝒅 (𝟐) becomes


𝟐𝟏𝑩 + 𝟔𝑨 = 𝟗. 𝟖𝟔𝟕𝟒
𝟐𝟏𝑨 + 𝟗𝟏𝑩 = 𝟑𝟎. 𝟐𝟓𝟒𝟓
Solving these equations, we get

𝑨 = 𝟐. 𝟓𝟎𝟏𝟎 , 𝑩 = −𝟎. 𝟐𝟒𝟒𝟕

Since

𝐥𝐨𝐠𝐚 = 𝐀 ⇒ 𝐚 = 𝟏𝟎𝐀 = 𝟏𝟎𝟐.𝟓𝟎𝟏𝟎 = 𝟑𝟏𝟔. 𝟗𝟓𝟔𝟖

𝐥𝐨𝐠𝐛 = 𝐁 ⇒ 𝐛 = 𝟏𝟎𝑩 = 𝟏𝟎−𝟎.𝟐𝟒𝟒𝟕 = 𝟎. 𝟓𝟔𝟗𝟐

Hence the required equation is:

⟹ 𝒚(𝒙) = 𝟑𝟏𝟔. 𝟗𝟓𝟔𝟖(𝟎. 𝟓𝟔𝟗𝟐)𝒙

Example # 21:-
Fit a curve of the 𝒚 = 𝒂𝒙𝒃 to the data

𝒙 𝟏 𝟐 𝟑 𝟒 𝟓 𝟔

𝒚 𝟏𝟐𝟎𝟎 𝟗𝟎𝟎 𝟔𝟎𝟎 𝟐𝟎𝟎 𝟏𝟏𝟎 𝟓𝟎

Solution:-
Since 𝒚 = 𝒂𝒙𝒃 , Applying logarithm on both sides;
⟹ 𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒃𝒍𝒐𝒈𝒙

Dr. Jamil Book Series 2 Page 53


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

⟹ 𝒀 = 𝑨 + 𝒃𝑿 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑿 = 𝒍𝒐𝒈𝒙 , 𝑨 = 𝒍𝒐𝒈𝒂

Then the normal equations are

𝒃∑𝑿𝒊 + 𝒏𝑨 = ∑𝒀𝒊 (𝟏)

𝒃∑𝑿𝒊 𝟐 + 𝑨∑𝑿𝒊 = ∑𝑿𝒊 𝒀𝒊 (𝟐)

We form the table:

“Tables of values”

𝒙 𝒚 𝑿 𝒀 𝑿𝟐 𝑿𝒀

1 1200 0.000 3.0792 0.000 0.000

2 900 0.3010 2.9542 0.0906 0.8892

3 600 0.4771 2.7782 0.2276 1.3255

4 200 0.6021 2.3010 0.3625 1.3854

5 110 0.6990 2.0414 0.4886 1.4269

6 50 0.7781 1.6990 0.6054 1.3220

- - 2.8573 14.8530 1.7747 6.3490

∑𝒙𝒊 ∑𝒚𝒊 ∑𝑿𝒊 ∑𝒀𝒊 ∑𝑿𝒊 𝟐 ∑𝑿𝒊 𝒀𝒊

Hence the equations (𝟏) 𝒂𝒏𝒅 (𝟐) become


𝟔𝑨 + 𝟐. 𝟖𝟓𝟕𝟑𝒃 = 𝟏𝟒. 𝟖𝟓𝟑𝟎

𝟐. 𝟖𝟓𝟕𝟑𝑨 + 𝟏. 𝟕𝟕𝟒𝟕𝒃 = 𝟔. 𝟑𝟒𝟗𝟎

Solving these equations, we get

𝑨 = 𝟑. 𝟑𝟎𝟖𝟔 , 𝒃 = −𝟏. 𝟕𝟒𝟗𝟒

Since

𝒍𝒐𝒈𝒂 = 𝑨 ⇒ 𝒂 = 𝟏𝟎𝑨 = 𝟏𝟎𝟑.𝟑𝟎𝟖𝟔 = 𝟐𝟎𝟑𝟓

Hence the required equation is

⟹ 𝒚(𝒙) = 𝟐𝟎𝟑𝟓𝒙−𝟏.𝟕𝟒𝟗𝟒

Dr. Jamil Book Series 2 Page 54


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Drill Excercise # 18:-


Fit a curve of the form 𝒚 = 𝒂𝒙𝒃 to the data:
𝒙 𝟏 𝟐 𝟑 𝟒 𝟓

𝒚 𝟕. 𝟏 𝟐𝟕. 𝟖 𝟔𝟐. 𝟏 𝟏𝟏𝟎 𝟏𝟔𝟏

Answer:-

𝒚(𝒙) = 𝟕. 𝟏𝟕𝟑𝒙𝟏.𝟗𝟓𝟐
Drill Excercise # 19:-
Fit a curve of the form 𝒚 = 𝒂𝒆𝒃𝒙 to the data by the method of least squares:
𝒙 𝟎 𝟓 𝟖 𝟏𝟐 𝟐𝟎

𝒚 𝟑. 𝟎 𝟏. 𝟓 𝟏. 𝟎 𝟎. 𝟓𝟓 𝟎. 𝟏𝟖

Answer:-
𝒚(𝒙) = 𝟑. 𝟎𝟑𝟎𝟒𝒆−𝟎.𝟏𝟒𝟏𝟏𝒙
Drill Excercise # 20:-
A glass of water containing approximately 𝒏𝟎 bacteria was exposed to UV radiation. The
number of bacteria remaining in the glass was recorded with time 𝒕. The number of
bacteria is known to vary with time following the model
𝒏 = 𝒏𝟎 𝒆𝜶𝒕
where 𝒏𝟎 is the number of bacteria at the start of the experiment and 𝜶 is the rate of
destruction.

𝑻𝒊𝒎𝒆 𝒕(𝒎𝒊𝒏) 5 10 15 20 25 30

𝒏 637 386 234 142 86 52

(𝜶): Find 𝒏𝟎 and 𝜶 by the methods of Least Square Method and complete the above model.
(𝜷): Determine number of bacteria at time 𝒕 = 𝟐𝟕 𝒎𝒊𝒏. from this relation.
(𝜸): Use this Polynomial to estimate 𝑷 at 𝟕 (𝒈 𝒎𝒊𝒏−𝟏 ) flow rate.
(𝜹): Interpret and conclude your results.

Drill Excercise # 21:-


The result of measurement of electric resistance 𝑹 of a copper wire at various temperatures is
listed below:

𝒕 1 2 3 4 5

𝑹 0.5 2 4.5 8 12.5

(i): Design a Mathematical Model of Polynomial Fit of the form 𝑹 = 𝜶𝒙𝜷 through Least
Square Method.
(ii): Try to roughly Draw/plot the graph of 𝑹 = 𝜶𝒙𝜷 (after finding 𝜶 and 𝜷). Is the curve is
Passes through the Origin. What is the best name you suggest this curve ?
(iii): Use this Polynomial to estimate Resistance 𝑹 at 𝒕 = 𝟔.
(iv): Interpret and conclude your results.

Dr. Jamil Book Series 2 Page 55


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

EXERCISE-2
Lagrange’s Interpolation Polynomial Method

Question # 1:-
Determine the Lagrange’s interpolation Polynomial for the data:

𝒙 𝟎 𝟏 𝟑

𝒚 = 𝒇(𝒙) 𝟏 𝟑 𝟓𝟓

and estimate the value at 𝒙 = 𝟐 i.e. find 𝒇(𝟐).

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) = 𝟖𝒙𝟐 − 𝟔𝒙 + 𝟏 and 𝒇(𝟐) = 𝟐𝟏

Question # 2:-
Find the missing value from the following data using Lagrange interpolation Polynomial:

𝒙 𝟎 𝟏 𝟐 𝟑 𝟒

𝒚 = 𝒇(𝒙) −𝟏𝟐 𝟎 − 𝟔 𝟏𝟐

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) = 𝒙𝟑 − 𝟕𝒙𝟐 + 𝟏𝟖𝒙 − 𝟏𝟐 and 𝒇(𝟐) = 𝟒

Question # 3:-
Use Lagrange interpolation Polynomial, find (𝟏) :

𝒙 −𝟏 𝟎 𝟐 𝟑

𝒚 = 𝒇(𝒙) 𝟓 𝟐 𝟎 𝟏

Answer:-
𝟏
𝒇(𝟏) =
𝟑

Question # 4:-
The Chemical Oxygen Demand(COD) is found to increase downstream a river. The data
collected from the experiment are tabulated below:

𝑫𝒊𝒔𝒕𝒂𝒏𝒄𝒆 (𝑲𝒎) 𝒅 0 1 2 5

𝑪𝑶𝑫 (𝒎𝒈 𝑳−𝟏 ) 𝑪 2 3 12 147

Dr. Jamil Book Series 2 Page 56


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

1): Design a Mathematical Model through Polynomial using Lagrange interpolation


method,
2): Write Polynomial in simplest form.
3): Use this Polynomial to estimate COD at 3Km downstream.
4): Interpret and conclude your results.

Answer:-

𝑪(𝒅) = 𝒇(𝒅) = 𝒅𝟑 + 𝒅𝟐 − 𝒅 + 𝟐

Question # 5:-
The following table gives corresponding values of Pressure of a steam at a given
temperature.
1): Make a Mathematical Model using Lagrange interpolation polynomial,
2): Write Polynomial in simplest form.
3): Find the pressure for a temperature of 𝟏𝟔𝟓° 𝑪
4): Interpret and conclude your results.

𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆° 𝑪 , 140 150 160 170

Pressure. Kgf per cm sq. 3.685 4.854 6.302 8.076

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) =

Question # 6:-
Use the following data :

𝒙 0 1 3 4

𝒚 = 𝒇(𝒙) 5 6 50 105

1): Make a Mathematical Model through Polynomial using Lagrange interpolation method,
2): Write Polynomial in simplest form.
3): Use this Polynomial to estimate 𝒇(𝟐. 𝟓).
4): Interpret and conclude your results.

Answer:-

𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) =

Dr. Jamil Book Series 2 Page 57


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 7:-
Find Lagrange’s interpolation Polynomial fitting the Points (𝟏) = −𝟑 , 𝒚(𝟑) = 𝟎 , 𝒚(𝟒) =
𝟑𝟎 , 𝒚(𝟔) = 𝟏𝟑𝟐. Hence find 𝒇(𝟓).

Answer:-
𝟏
𝒚(𝒙) = 𝒇(𝒙) = (−𝒙𝟑 + 𝟐𝟕𝒙𝟐 − 𝟗𝟐𝒙 + 𝟔𝟎)
𝟐

𝒚(𝟓) = 𝒇(𝟓) = 𝟕𝟓

Question # 8:-
Given the following data, evaluate 𝒇(𝟑) using Lagrange’s interpolation Polynomial:

𝒙 𝟏 𝟐 𝟓

𝒚 = 𝒇(𝒙) 𝟏 𝟒 𝟏𝟎

Answer:-
𝒇(𝟑) = 𝟔. 𝟒𝟗𝟗𝟗

Question # 9:-
Determine by Lagrange’s method the percentage number of patients over 40 years, using
the following data:

Age over 𝒙 years 30 35 45 55

% 𝒏𝒖𝒎𝒃𝒆𝒓 𝒚 𝒐𝒇 patients 148 96 68 34

Answer:-
𝒚(𝟒𝟎) = 𝒇(𝟒𝟎) = 𝟕𝟒. 𝟕

Question # 9:-
Obtain the Lagrange’s interpolation Polynomial of 𝒚(𝒙) from the following data; and
obtain 𝒚(𝟐. 𝟓):

𝒙 𝟎 𝟏 𝟑 𝟒

𝒚 = 𝒇(𝒙) 𝟓 𝟔 𝟓𝟎 𝟏𝟎𝟓

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) = 𝒙𝟑 + 𝟑𝒙𝟐 − 𝟑𝒙 + 𝟓

Dr. Jamil Book Series 2 Page 58


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 10:-
The following data give the percentage of criminals for different age groups:

𝑨𝒈𝒆(𝒍𝒆𝒔𝒔 𝒕𝒉𝒂𝒏 𝒙 𝒚𝒆𝒂𝒓𝒔) 𝟐𝟓 𝟑𝟎 𝟒𝟎 𝟓𝟎

% 𝒐𝒇 𝒄𝒓𝒊𝒎𝒊𝒏𝒂𝒍𝒔 𝟐𝟔 𝟑𝟒 𝟒𝟐 𝟒𝟕

Using Lagrange’s formula, estimate the percentage of criminals under the age of 35.

Answer:-
𝒇(𝟑𝟓) ≈ 𝑷(𝟑𝟓) = 𝟑𝟖. 𝟗𝟓

Question # 11:-
Use Lagrange’s interpolation formula to fit a Polynomial to the following data:

𝒙 𝟎 𝟏 𝟑 𝟒

𝒚 = 𝒇(𝒙) −𝟏𝟐 𝟎 𝟔 𝟏𝟐

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) = 𝒙𝟑 − 𝟕𝒙𝟐 + 𝟏𝟖𝒙 − 𝟏𝟐

Question # 12:-
The following table are the measurement 𝑻 made on a curve record by oscilograph
representing a change of current 𝑰 due to a change in the conditions of an electric current:
1): Construct a Mathematical Model by Lagrange interpolation polynomial,
2): Write Polynomial in uncomplicated form.
3): Find the current 𝑰 for a 𝑻 = 𝟑.
4): Interpret and conclude your results.

𝑻, 0 1 4 5

Current 𝑰 8 11 68 123

Answer:-
𝑰(𝑻) =≈ 𝑷(𝑻) = 𝑻𝟑 − 𝑻𝟐 + 𝟑𝑻 + 𝟖

Dr. Jamil Book Series 2 Page 59


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Hermite’s Interpolation Polynomial Method


Lagrange’s Interpolation Polynomial Methods
Question # 13:-
From the following table of values of 𝒇(𝒙) and 𝒇′(𝒙) obtain 𝒇(−𝟎. 𝟓) and 𝒇(𝟎. 𝟓), using
hermit’s interpolation formula:

𝒙 −𝟏 𝟎 𝟏

𝒚 = 𝒇(𝒙) 𝟏 𝟏 𝟑

𝒚′ = 𝒇’(𝒙) −𝟓 𝟏 𝟕

Answer:-
𝟏𝟏 𝟑
𝒇(𝒙) ≈ 𝑷(𝒙) = 𝟐𝒙𝟒 − 𝒙𝟐 + 𝒙 + 𝟏 and (−𝟎. 𝟓) = , 𝒇(𝟎. 𝟓) =
𝟖 𝟖

Question # 14:-
From the following data find 𝑷(𝒙) using hermit’s interpolation formula and find 𝒇(𝟎. 𝟓).

𝒙 𝒚 = 𝒇(𝒙) 𝒚 = 𝒇’(𝒙)

−𝟏 𝟏 −𝟏

𝟎 𝟎 𝟏

𝟏 𝟏 𝟎

Answer:-
𝟏
𝒇(𝒙) ≈ 𝑷(𝒙) = (𝟑𝒙𝟓 − 𝟑𝒙𝟒 − 𝟕𝒙𝟑 + 𝟕𝒙𝟐 + 𝟒𝒙) and 𝒇(𝟎. 𝟓) = 𝟎. 𝟔𝟗𝟓𝟑𝟏𝟐𝟓
𝟒

Question # 15:-
Using hermit’s interpolation, find cubic Polynomial from the data, also find 𝒇(𝟎. 𝟓).

𝒙 𝟎 𝟏

𝒚 = 𝒇(𝒙) 𝟎 𝟏

𝒚′ = 𝒇’(𝒙) 𝟎 𝟏

Answer:-
𝟑
𝒇(𝒙) = 𝟐𝒙𝟐 − 𝒙𝟑 , 𝒇(𝟎. 𝟓) =
𝟖

Dr. Jamil Book Series 2 Page 60


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 16:-
Find 𝒇(𝟎. 𝟓) from the data below by hermit’s interpolation formula:

𝒙 𝟎 𝟏

y=𝒇(𝒙) 𝟏 𝟏

y’=𝒇’(𝒙) 𝟎 𝟏

Answer:-
𝟕
𝒇(𝟎. 𝟓) =
𝟖

Question # 17:-
Express 𝒚 as a Polynomial in 𝒙 from the following data, using hermit’s interpolating
formula:

𝒙 −𝟏 0 1

𝒚(𝒙) −𝟏𝟎 -4 −2

𝒚′(𝒙) 𝟏𝟎 3 2

Answer:-
𝒚(𝒙) ≈ 𝑷(𝒙) = 𝒙𝟑 − 𝟐𝒙𝟐 + 𝟑𝒙 − 𝟒

Question # 18:-
Express 𝒇(𝒙) as a Polynomial in 𝒙 from the following data, using hermit’s interpolation
formula.

𝒙 0 1 2

𝒚 = 𝒇(𝒙) 1 2 33

𝒚 = 𝒇′(𝒙) 0 4 64

Answer:-
𝒇(𝒙) ≈ 𝑷(𝒙) = −𝟒𝒙𝟓 + 𝟐𝟏𝒙𝟒 − 𝟐𝟖𝒙𝟑 + 𝟏𝟐𝒙𝟐 + 𝟏
Question # 19:-
Express y as a polynomial in 𝒙 from the following data, using interpolation method.

𝒙 -2 0 1

𝒚(𝒙) 13 -1 1

𝒚′(𝒙) -31 1 5

Dr. Jamil Book Series 2 Page 61


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) = 𝒙𝟒 + 𝒙 − 𝟏

Question # 20:-
Express y as a polynomial in 𝒙 from the following data, using hermit’s interpolation
method:

𝒙 1 2 3

𝒚(𝒙) -4 5 60

𝒚’(𝒙) 0 24 96

Answer:-
𝒚 (𝒙) = 𝒇 (𝒙) ≈ 𝒙𝟒 − 𝟐 𝒙𝟐 – 𝟑

Newton’s Interpolation Polynomial Methods

Question # 21:-
Estimate 𝒇(𝟑. 𝟏𝟕) from the following data using newton’s forward interpolation formula:

𝒙 3.1 3.2 3.3 3.4 3.5

𝒚 = 𝒇(𝒙) 0 0.6 1.0 1.2 1.3

Answer:-
𝒇 (𝟑. 𝟏𝟕) = 𝟎. 𝟒𝟑𝟖𝟒

Question # 22:-
Find the forward interpolation polynomial for the data:

𝒙 -1 0 1 2

𝒚 = 𝒇(𝒙) 4 2 2 4

Answer:-
𝒇 (𝒙) = 𝒙𝟐 − 𝒙 + 𝟐

Dr. Jamil Book Series 2 Page 62


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 23:-
Express 𝒇(𝟒𝟐) from the following data using newton’s backward interpolation formula:

𝒙 20 25 30 35 40 45

𝒚 = 𝒇(𝒙) 354 332 291 260 231 204

Answer:-
𝒇 (𝟒𝟐) = 𝟐𝟏𝟖. 𝟔𝟔𝟑𝟎

Question # 24:-
Given:

𝒙 1 2 3 4 5 6 7 8

𝒚 = 𝒇(𝒙) 1 8 27 64 125 216 343 512

Find
a): 𝒇(𝟏. 𝟓) b): 𝒇(𝟕. 𝟓)

Answer:-
𝒇 (𝟏. 𝟓) = 𝟑. 𝟑𝟕𝟓 , 𝒇 (𝟕. 𝟓) = 𝟒𝟐𝟏. 𝟖𝟕𝟓

Question # 25:-
Evaluate 𝒇(𝟏. 𝟏) and 𝒇(𝟒. 𝟓) from the table:

𝒙 0 1 2 3 4 5

𝒚 = 𝒇(𝒙) 0 3 8 15 24 35

Answer:-
𝒇 (𝟏. 𝟏) = 𝟑. 𝟒𝟏, 𝒇 (𝟒. 𝟓) = 𝟐𝟗. 𝟐𝟓

Question # 26:-
Compute 𝒇(𝟎. 𝟐𝟑) and 𝒇(𝟎. 𝟐𝟗) using the following data:

𝒙 0 1 2 3 4 5 6 7

𝒚 = 𝒇(𝒙) 0 7 26 63 124 215 342 511

Answer:-
𝒇 (𝟎. 𝟓) = 𝟐. 𝟑𝟕𝟓, 𝒇(𝟕. 𝟓) = 𝟒𝟓𝟓. 𝟓𝟑𝟑

Dr. Jamil Book Series 2 Page 63


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 27:-
Compute 𝒇(𝟎. 𝟐𝟑) and 𝒇(𝟎. 𝟐𝟗) using the data:

𝒙 0.20 0.22 0.24 0.26 0.28 0.30

y=𝒇(𝒙) 1.6596 1.6698 1.6804 1.6912 1.7024 1.7139

Answer:-
𝒇(𝟎. 𝟐𝟑) = 𝟏. 𝟔𝟕𝟓𝟏, 𝒇(𝟎. 𝟐𝟗) = 𝟏. 𝟕𝟎𝟖𝟏

Question # 28:-
For the data find the divided difference polynomial and estimate 𝒇(𝟏).

𝒙 -1 0 2 5

𝒚 = 𝒇(𝒙) 7 10 22 235

Answer:-
𝒚 (𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) = 𝟐𝒙𝟑 − 𝒙𝟐 + 𝟏𝟎 , 𝒇 (𝟏) = 𝟏𝟏

Question # 29:-
Using Newton’s divided difference formula, find the value of 𝒇(𝟐), 𝒇(𝟖) and 𝒇(𝟏𝟓) given
the following table:

𝒙 4 5 7 10 11 13

𝒚 = 𝒇(𝒙) 48 100 294 900 1210 2028

Answer:-
𝒇(𝒙) ≈ 𝑷 (𝒙) = 𝟒𝟖 + 𝟓𝟐 (𝒙 − 𝟒) + 𝟏𝟓(𝒙 − 𝟒) (𝒙 − 𝟓) + (𝒙 − 𝟒) (𝒙 − 𝟓) (𝒙 − 𝟔)
𝒇(𝟐) = 𝟒 , 𝒇 (𝟖) = 𝟒𝟒𝟖, 𝒇 (𝟏𝟓) = 𝟑𝟏𝟓𝟎

Question # 30:-
Use Newton’ s divided difference formula to find 𝒇(𝟖) and 𝒇(𝟏𝟐) from the table:

𝒙 4 5 7 10 11 13

𝒚 = 𝒇(𝒙) 48 100 294 900 1210 2028

Answer:-
𝒇(𝟖) = 𝟒𝟒𝟖 , 𝒇 (𝟏𝟓) = 𝟑𝟏𝟓𝟎

Dr. Jamil Book Series 2 Page 64


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 31:-
Find the Newton’s divided difference polynomial of the following data: and find 𝒇(𝟐. 𝟓):

𝒙 0 1 3 4

𝒚 = 𝒇(𝒙) 1 4 40 85

Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) = 𝒙𝟑 + 𝒙𝟐 + 𝒙 + 𝟏

Question # 32:-
For the following data, find the cubic polynomial using Newton’s divided difference
formula:

𝒙 0 1 2 5

𝒚 = 𝒇(𝒙) 2 3 12 147

Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) = 𝒙𝟑 + 𝒙𝟐 – 𝒙 – 𝟐

Question # 33:-
From the following data, find the Newton’s divided difference polynomial:

𝒙 0 2 3 4 7 9

𝒚 = 𝒇(𝒙) 4 26 58 112 466 922

Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) =

Question # 34:-
The rocket is launched from the ground and its velocity during first 10 seconds.
1): Study the system using Newton’s interpolation polynomial,
2): Explain your interpolation polynomial physically
3): Find the velocity at 𝒕 = 𝟏 𝒔𝒆𝒄 and 𝒕 = 𝟗 𝒔𝒆𝒄
4): Interpret and give final remarks on your findings.

𝑻𝒊𝒎𝒆 𝒕 0 2 4 6 8 10

Velocity V 50 210 2610 13010 41010 100050

Dr. Jamil Book Series 2 Page 65


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) =

Question # 35:-
Find the missing values in the following data:

𝒙 45 50 55 60 65

𝒚(𝒙) 3.0 ? 2.0 ? -2.4

Answer:-
𝒇(𝟓𝟎) = 𝟐. 𝟗𝟐𝟓, 𝒇(𝟔𝟎) = 𝟎. 𝟐𝟐𝟓

Question # 36:-
The following table gives pressure of a steam at a given temperature. Using Newton’s
formula, compute the pressure for a temperature of 𝟏𝟒𝟐𝑪.

Temperature C. 140 150 160 170 180

Pressure, Kgf/cm2 3.685 4.854 6.302 8.076 10.225

Answer:-
𝒇(𝟏𝟒𝟐) = 𝟑. 𝟖𝟗𝟖𝟖𝑲𝒈𝒇/𝒄𝒎𝟑

Question # 37:-
Find the missing values in the following data, using Newton’s divided difference formula:

𝒙 3 6 7 8 9 10

𝒚(𝒙) 168 ? 120 ? 72 63

Answer:-
𝒇(𝟔) = 𝟏𝟒𝟕, 𝒇(𝟖) = 𝟗𝟑
Question # 38:-
Express y as a polynomial in powers of (𝒙 − 𝟐) from the following data:

𝒙 0 2 3 6 9 10

𝒚(𝒙) 3 7 24 207 714 983

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑷(𝒙) = (𝒙 − 𝟐)𝟑 + 𝟔(𝒙 − 𝟐)𝟐 + 𝟏𝟎(𝒙 − 𝟐) +

Dr. Jamil Book Series 2 Page 66


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 39:-
Find 𝒇(𝒙) as a polynomial in powers of (𝒙 − 𝟔) from the following data:

𝒙 -1 0 2 3 7 10

y=𝒇(𝒙) -11 1 1 1 141 561

Answer:-
𝒇(𝒙) = (𝒙 − 𝟔) + 𝟏𝟑(𝒙 − 𝟔)𝟐 + 𝟓𝟒(𝒙 − 𝟔) + 𝟕𝟑

Question # 40:-
The Pressure drop that occurs when water flows through an orifice meter is measured
using a differential Pressure transmitter. The output current is converted to voltage drop
by a resister. The objective is to correlate the flow rate 𝑭 (𝒈 𝒎𝒊𝒏−𝟏 ) with the voltage drop
𝑷 (𝒎 𝑽). The following data were collected from an experiment:

𝑭 (𝒈 𝒎𝒊𝒏−𝟏 ) 3 5 6 9

𝑷 (𝒎 𝑽) 293 508 585 764

(i): Derive a polynomial passing through these data points using Newton’s Divided
interpolation method
(ii): Write Polynomial in simplest form.
(iii): Use this Polynomial to estimate 𝑷 at 𝟕 (𝒈 𝒎𝒊𝒏−𝟏 ) flow rate.
(iv): Interpret and conclude your results.
Answer:-
𝒚(𝒙) = 𝒇 (𝒙) ≈ 𝑷 (𝒙) =

Dr. Jamil Book Series 2 Page 67


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Cubic Spline Interpolation Polynomial Methods


Question # 41:-
From the following table, compute 𝒚(𝟏. 𝟓) and 𝒚’(𝟏), using cubic spline.

𝒙 1 2 3

𝒚(𝒙) -8 -1 18

Finally write your comments and give suitable interpretation either physical/geometrical
or Mechanical on your finding. What you think !
Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑺(𝒙) = 𝟑𝒙𝟑 − 𝟗𝒙𝟐 + 𝟏𝟑𝒙 − 𝟓, 𝟏 ≤ 𝒙 ≤ 𝟐
𝒚(𝟏. 𝟓) = −𝟒𝟓/𝟖, 𝒚’(𝟏) ≈ 𝑺’(𝟏) = 𝟒

Question # 42:-
Using cubic spline, find 𝒚(𝟎. 𝟓) and 𝒚’(𝟏) given that 𝑴𝟎 = 𝑴𝟐 = 𝟎, and the table:

𝒙 0 1 2

𝒚(𝒙) -5 -4 3

Answer:-
𝒚(𝒙) = 𝒇(𝒙) ≈ 𝑺(𝒙) = (𝟑/𝟐)𝒙𝟑 − (𝒙/𝟐) − 𝟓, 𝟎 ≤ 𝒙 ≤ 𝟏
𝒚(𝟎. 𝟓) ≈ 𝑺(𝟎. 𝟓) = −𝟖𝟏/𝟏𝟔, 𝒚’(𝟏) ≈ 𝑺’(𝟏) = 𝟒

Question # 43:-
Find the cubic spline polynomial in each interval for the function given below:
Assume that 𝑴𝟎 = 𝑴𝟑 = 𝟎. Also find 𝒇(𝟐. 𝟓).

𝒙 0 1 2 3

𝒚 = 𝒇(𝒙) 1 2 33 244

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟒𝒙𝟑 + 𝟓𝒙 + 𝟏, 𝟎 ≤ 𝒙 ≤ 𝟏

𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟓𝟎𝒙𝟑 − 𝟏𝟔𝟐𝒙𝟐 + 𝟏𝟔𝟕𝒙 − 𝟓𝟑, 𝟏 ≤ 𝒙 ≤ 𝟐

𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟒𝟔𝒙𝟑 + 𝟒𝟏𝟒𝒙𝟐 − 𝟗𝟖𝟓𝒙 + 𝟕𝟏𝟓 𝟐 ≤ 𝒙 ≤ 𝟑

Dr. Jamil Book Series 2 Page 68


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 44:-
Find the cubic spline given the table:(assume that 𝑴(𝟎) = 𝟎, 𝑴(𝟑) = −𝟏𝟐)

𝒙 0 2 4 6

𝒚(𝒙) 1 9 41 41

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = 𝒙𝟑 + 𝟏 𝟎 ≤ 𝒙 ≤ 𝟐

𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟐𝒙𝟑 + 𝟏𝟖𝒙𝟐 − 𝟑𝟔𝒙 − 𝟐𝟓, 𝟐 ≤ 𝒙 ≤ 𝟒

𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟔𝒙𝟐 + 𝟔𝟎𝒙 − 𝟏𝟎𝟑, 𝟒 ≤ 𝒙 ≤ 𝟔

Question # 45:-
Obtain the cubic spline approximation for the function 𝒚 = 𝒇(𝒙) from the following data,
given by 𝑴𝟎 = 𝑴𝟑 = 𝟎. Find 𝒚(𝟏. 𝟓).

𝒙 -1 0 1 2

𝒚(𝒙) 0 1 2 18

At the end put down your conclusions and express suitable interpretation either
physical/geometrical or Mechanical on your results. What is your understanding!

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = −𝒙𝟑 − 𝟑𝒙𝟐 − 𝒙 + 𝟏, −𝟏 ≤ 𝒙 ≤ 𝟎

𝒚(𝒙) ≈ 𝑺(𝒙) = 𝟓𝒙𝟑 − 𝟑𝒙𝟐 − 𝒙 + 𝟏, 𝟎 ≤ 𝒙 ≤ 𝟏

𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟒𝒙𝟑 + 𝟐𝟒𝒙𝟐 − 𝟐𝟖𝒙 + 𝟏𝟎, 𝟏 ≤ 𝒙 ≤ 𝟐

Question # 46:-
Find the cubic spline interpolation polynomial for the data given below under the condition
𝑴(𝟎) = 𝑴(𝟑) = 𝟎 and valid in the sub-interval [𝟏, 𝟐]. Hence, find 𝒇(𝟏. 𝟓):

𝒙 0 1 2 3

𝒚(𝒙) 1 4 10 8

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = (𝟏/𝟑)(−𝟏𝟏𝒙𝟑 + 𝟒𝟓𝒙𝟐 − 𝟒𝟎𝒙 + 𝟏𝟖), 𝟏 ≤ 𝒙 ≤ 𝟐

Question # 47:-
Find the cubic spline polynomial in [𝟎, 𝟏] for the following data:
Also find 𝒚(𝟎. 𝟓) and 𝒚’(𝟏).

Dr. Jamil Book Series 2 Page 69


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝒙 0 1 2

𝒚 = 𝒇(𝒙) 0 2 6

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = (𝒙𝟑 + 𝟑𝒙)(𝟏/𝟐)

𝒚(𝟎. 𝟓) = 𝟏𝟑/𝟏𝟔, 𝒚’(𝟏) = 𝟑

Question # 48:-
Find the cubic spline polynomial for the data. Also find 𝒚(𝟎. 𝟓) and 𝒚’(𝟏).

𝒙 0 1 2

𝒚 = 𝒇(𝒙) 0 1 0

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = (−𝒙𝟑 + 𝟑𝒙)(𝟏/𝟐)

𝒚(𝟎. 𝟓) = 𝟏𝟏/𝟔, 𝒚’(𝟏) = 𝟎

Question # 49:-
Find the natural cubic spline in the range [𝟎, 𝟔] for the following data. Also find 𝒚(𝟑) and
𝒚’(𝟑).

𝒙 0 6 12

𝒚 = 𝒇(𝒙) 1 3 11

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = (𝟏/𝟏𝟒𝟒)(𝒙𝟑 + 𝟏𝟐𝒙 + 𝟏𝟒𝟒)
𝒚(𝟑) = 𝟐𝟎𝟕/𝟏𝟒𝟒, 𝒚’(𝟑) = 𝟑𝟗/𝟏𝟒𝟒

Question # 50:-
Find the cubic spline for the following data with 𝑴(𝟎) = 𝟏𝟎 and 𝑴(𝟐) = 𝟏𝟎

𝒙 -1 0 1

𝒚 = 𝒇(𝒙) 1 0 1

Answer:-
𝒚(𝒙) ≈ 𝑺(𝒙) = −𝟐𝒙𝟑 − 𝒙𝟐 , −𝟏 ≤ 𝒙 ≤ 𝟎

𝒚(𝒙) ≈ 𝑺(𝒙) = 𝟐𝒙𝟑 − 𝒙𝟐 , 𝟎 ≤ 𝒙 ≤ 𝟏

Dr. Jamil Book Series 2 Page 70


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Least Square Curves Fitting Methods


Question # 51:-
By the method of least squares find the best fitting straight line to the data given below:

𝒙 5 10 15 20 25

𝒚(𝒙) 16 19 23 26 30

Answer:-
𝒚(𝒙) = 𝟎. 𝟕𝒙 + 𝟏𝟐. 𝟑

Question # 52:-
Find a straight line to the data, using least square method. Hence find 𝒚(𝟐. 𝟓).

𝒙 1 2 3 4 5

𝒚(𝒙) 16 19 23 26 30

Answer:-
𝒚(𝒙) = 𝟑. 𝟓𝒙 + 𝟏𝟐. 𝟑
Question # 53:-
Fit a straight line to the data using least square method. Hence find 𝒚(𝟐. 𝟓).

𝒙 0 1 2 3 4

𝒚(𝒙) 1 1.8 3.3 4.5 6.3

Answer:-
𝒚(𝒙) = 𝟏. 𝟑𝟑𝒙 + 𝟎. 𝟕𝟐, 𝒚(𝟐) = 𝟒. 𝟎𝟐𝟓

Question # 54:-
Fit a straight line to the data using least square method. Hence find 𝒚(𝟐𝟓).

𝒙 0 5 10 15 20

𝒚(𝒙) 7 11 16 20 26

Answer:-
𝒚(𝒙) = 𝟎. 𝟗𝟒𝒙 + 𝟔. 𝟔, 𝒚(𝟐𝟓) = 𝟑𝟎. 𝟏
Question # 55:-
Fit a straight line of the form 𝒚 = 𝒂𝒙 + 𝒃 to the following data:

𝒙 1 3 5 7 9

𝒚(𝒙) 1.5 2.8 4.0 4.7 6.0

Dr. Jamil Book Series 2 Page 71


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Answer:-
𝒚(𝒙) = 𝟎. 𝟓𝟐𝟑𝟐𝒙 + 𝟏. 𝟏𝟖𝟒

Question # 56:-
Fit a parabola to the data using least square method. Also estimate 𝒚(𝟔).

𝒙 1 2 3 4 5

𝒚(𝒙) 5 12 26 60 97

Answer:-
𝒚(𝒙) = 𝟓. 𝟕𝟏𝟒𝟑𝒙𝟐 − 𝟏𝟏. 𝟎𝟖𝟓𝟖𝒙 + 𝟏𝟎. 𝟒𝟎𝟎𝟏

𝒚(𝟔) = 𝟏𝟒𝟗. 𝟔𝟎𝟎𝟏

Question # 57:-
Fit a parabola to the data and find y(4.5).

𝒙 1 2 3 4 5

𝒚(𝒙) 2 3 5 8 10

Answer:-
𝒚(𝒙) = 𝟎. 𝟒𝟎𝟑 + 𝟎. 𝟑𝟖𝟖𝒙 − 𝟐. 𝟕𝟗𝟎𝒙𝟐

Question # 58:-
Fit a second-degree polynomial (parabola) for the given data:

𝒙 5 10 15 20 25

𝒚(𝒙) 16 19 23 26 30

Answer:-
𝒚(𝒙) = 𝟏𝟐. 𝟖𝟎𝟕𝟓 + 𝟎. 𝟔𝟏𝟑𝟎𝒙 + 𝟎. 𝟎𝟎𝟐𝟗𝒙𝟐
Question # 59:-
Fit a curve of the form 𝒚(𝒙) = 𝒂𝒙 + 𝒃𝒙𝟐 to the following data by the method of least
square:

𝒙 1 2 3 4 5

𝒚(𝒙) 1.8 5.1 8.9 14.1 19.8

Hint:-
Put 𝒀 = 𝒚/𝒙 = 𝒂 + 𝒃𝒙 (straight line case)
Answer:-
𝒚(𝒙) = 𝟏. 𝟑𝟕𝟏𝟖𝒙 + 𝟎. 𝟓𝟐𝟗𝟓𝒙𝟐

Dr. Jamil Book Series 2 Page 72


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 60:-
Fit a curve of the form 𝒙𝒚 = 𝒂 + 𝒃𝒙𝟐 to the following data by the method of least square:

𝒙 1 2 4 6 8

𝒚(𝒙) 5.43 6.28 10.32 14.86 19.51

Hint:-
Put 𝒀 = 𝒙𝒚 , 𝑿 = 𝒙𝟐 (straight line case)
Answer:-
𝒙𝒚 = 𝟑. 𝟎𝟐𝟎𝟓 + 𝟐. 𝟑𝟗𝟏𝟖𝒙𝟐

Question # 61:-
Fit a curve of the form 𝒚 = 𝒂𝒙𝒃 to the data:

𝒙 1 2 3 4 5 6

𝒚(𝒙) 151 100 61 50 20 8

Answer:-
𝒚(𝒙) = 𝟑𝟏𝟔. 𝟗𝟓𝟔𝟖(𝟎. 𝟓𝟔𝟗𝟐)𝒙

Question # 62:-
Fit a curve of the form 𝒚 = 𝒂𝒙𝒃 to the data:

𝒙 1 2 3 4 5 6

𝒚(𝒙) 1200 900 600 200 110 50

Answer:-
𝒚(𝒙) = 𝟐𝟎𝟑𝟓 𝒙−𝟏.𝟕𝟒𝟗𝟒

Question # 63:-
Fit a curve of the form 𝒚 = 𝒂𝒙𝒃 to the data:

𝒙 1 2 3 4 5

𝒚(𝒙) 7.1 27.8 62.1 110 161

Answer:-
𝒚(𝒙) = 𝟕. 𝟏𝟕𝟑𝒙𝟏.𝟗𝟓𝟐

Dr. Jamil Book Series 2 Page 73


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 64:-
Fit a curve of the form 𝒚 = 𝒂𝒆𝒃𝒙 to the data by the method of least squares:

𝒙 0 5 8 12 20

𝒚(𝒙) 3.0 1.5 1.0 0.55 0.18

Answer:-
𝒚(𝒙) = 𝟑. 𝟎𝟑𝟎𝟒𝒆−𝟎.𝟏𝟒𝟏𝟏𝐱

Question # 65:-
The following table gives the results of the measurement of Train resistance; 𝑽 is the
Velocity in miles per hours, 𝑹 is the Resistance in pounds per ton:

𝑽 (𝒎𝒊𝒍𝒆𝒔/𝒉𝒐𝒖𝒓𝒔) 10 20 30 40 50

𝑹 (𝒑𝒐𝒖𝒏𝒅𝒔/𝒕𝒐𝒏) 8 10 15 21 30

1): Use the method of Least square to fit the a curve of the form 𝑹 = 𝒂𝑽𝒃 to the above data.
2): Predict 𝑹 at 𝑽 = 𝟑𝟓 𝐦𝐢𝐥𝐞𝐬 𝐩𝐞𝐫 𝐡𝐨𝐮𝐫𝐬 via above relation.
3): How do you see this Exponential relation 𝑹 = 𝒂𝑽𝒃 to fitting this data(It is good!).
4): Give some suitable remarks on your estimation.
Answer:-
𝑹(𝑽) = 𝒇(𝑽) = 𝑷(𝑽) =
Question # 66:-
Determine the values of 𝒂 and 𝒃 so that the equation 𝑸 = 𝒂𝒉𝒃 best fit the following data by
the method of least squares:

𝒉 25 20 12 9 7 5

𝑸 0.22 0.20 0.15 0.13 0.12 0.10

Answer:-
𝑸 = 𝟎. 𝟎𝟒𝟓𝟏𝒉𝟎.𝟒𝟗𝟏𝟖
Question # 67:-
The following table gives the results of measuring the electrical conductivity C of glass at
temperature  Fahrenheit:

 86 148 166 188 202 210

𝑪 0.004 0.018 0.029 0.051 0.073 0.090

If 𝒄 = 𝒂𝒆 find the values of 𝒂 and 𝒃.


Answer:-
𝟎. 𝟎𝟎𝟎𝟒𝟑𝟐𝟎𝒆𝟎.𝟎𝟐𝟓𝟒𝜽

Dr. Jamil Book Series 2 Page 74


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Question # 68:-
Number of bacteria “y” in a culture after 𝒙 hours is given in the following table:

𝒙 0 1 2 3 4 5 6

𝒚(𝒙) 32 47 65 92 132 190 275

Fit a curve of the form 𝒚 = 𝒂𝒃𝒙 by the method of least square.


Answer:-
𝒚(𝒙) = 𝟑𝟐. 𝟖𝟒𝟕𝟐(𝟏. 𝟒𝟏𝟔𝟖)𝒙

Question # 69:-
An experiment on the life of a cutting tool at different cutting speeds are given below:

Speed V 350 400 500 600

Life T 61 26 7 2.6

Fit a relation of the form 𝑽 = 𝒂𝑻𝒃


Answer:-
V = 682.3T (-0.1558)

Question # 70:-
Given the following table:

𝒙 0 1 2 3 4

𝒚(𝒙) 1 5 10 22 38

Find the straight line and the parabola of best fit and calculate the sum of the squares of the
residual in both cases. Which curve is more appropriate and why?
Answer:-
𝒚(𝒔) = 𝟗. 𝟏𝒙 − 𝟑, 𝒚(𝒙) = 𝟐. 𝟐𝒙𝟐 + 𝟎. 𝟑𝒙 + 𝟏. 𝟒
Estraight = 70.7, Eparabola = 2.5, parabola is better

Dr. Jamil Book Series 2 Page 75


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

SUMMARY OF CH#2

1. Interpolation:-
Interpolation is the process of finding the value of a function for any value of argument or
independent variable in an interval (𝒙𝟎 , 𝒙𝒏 ).
Thus interpolation is the art of reading between the lines in a given table.

2. Extrapolation:-
Extrapolation is the process of finding the value of a function outside an interval
(𝒙𝟎 , 𝒙𝒏 ).

3. Polynomial Interpolation 𝑷(𝒙):-


Approximation by the polynomial of least degree satisfying the given data is called
Polynomial Interpolation and the corresponding polynomial is called the interpolating
polynomial.
The following theorem guarantees the existence and uniqueness of such a polynomial.

4. Theorem:-
Let 𝒚(𝒙) = 𝒇(𝒙) be known at the distinct points 𝒙𝟎 , 𝒙𝟏 , … 𝒙𝒏 . Then there exists a unique
polynomial 𝑷(𝒙) of degree less than or equals to 𝒏 and satisfying the condition:

𝑷(𝒙𝒊 ) = 𝒚(𝒙𝒊 ) = 𝒚𝒊 = 𝒇𝒊 , 𝒊 = 𝟎, 𝟏, 𝟐, … . , 𝒏

4. Lagrange’s Interpolation formula:-


The Lagrange’s interpolation polynomial formula of degree at most (𝒏 + 𝟏) is given by:

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑳𝒊 (𝒙)𝒚𝒊


𝒊=𝟎

Where 𝑳𝒊 (𝒙) are called Lagrange’s interpolation coefficients and defined as:
(𝒙−𝒙 )(𝒙−𝒙 )… (𝒙−𝒙 )(𝒙−𝒙 )…(𝒙−𝒙 )
𝑳𝒊 (𝒙): (𝒙𝒊 −𝒙𝟎𝟎)(𝒙𝒊−𝒙𝟏𝟏 )…(𝒙𝒊−𝒙𝒊−𝟏
𝒊−𝟏 𝒊+𝟏 𝒏
)(𝒙𝒊 −𝒙𝒊+𝟏 )…(𝒙𝒊 −𝒙𝒏 ) [ 𝑫𝒆𝒍𝒆𝒕𝒆 𝒊𝒕𝒉 𝒇𝒂𝒄𝒕𝒐𝒓 (𝒙𝒊 − 𝒙𝒊 ) ]

5. Hermite’s Interpolation polynomial formula:-


𝒏 𝒏

𝒚(𝒙) = 𝒇(𝒙) ≅ 𝑷(𝒙) = ∑ 𝑨𝒊 (𝒙)𝒇𝒊 + ∑ 𝑩𝒊 (𝒙)𝒇′𝒊


𝒊=𝟎 𝒊=𝟎
where
𝑨𝒊 (𝒙) = [𝟏 − 𝟐𝑳′ 𝒊 (𝒙𝒊 )(𝒙 − 𝒙𝒊 )][𝑳𝒊 (𝒙)]𝟐

𝑩𝒊 (𝒙) = (𝒙 − 𝒙𝒊 )[𝑳𝒊 (𝒙)]𝟐


where 𝒇′𝒊 and 𝐋′𝒊 (𝐱) are derivatives of 𝒇(𝒙) and 𝑳𝒊 (𝒙) respectively.

Dr. Jamil Book Series 2 Page 76


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

6. Newton’s forward Interpolation Polynomial formula:-

𝒑(𝒑−𝟏) 𝒑(𝒑−𝟏)(𝒑−𝟐) 𝒑(𝒑−𝟏)(𝒑−𝟐)…(𝒑−𝒏+𝟏)


𝑷(𝒙) = 𝒚𝟎 + 𝒑𝜟𝒚𝟎 + 𝚫𝟐 𝒚𝟎 + 𝚫𝟑 𝒚𝟎 +. . . + 𝜟𝒏 𝒚𝟎
𝟐! 𝟑! 𝒏!

𝒙−𝒙𝟎
where 𝒑 =
𝒉

7. Newton’s backward Interpolation Polynomial formula:-

𝒑(𝒑+𝟏) 𝒑(𝒑+𝟏)(𝒑+𝟐) 𝒑(𝒑+𝟏)(𝒑+𝟐)…(𝒑+𝒏−𝟏)


𝑷(𝒙) = 𝒚𝒏 + 𝒑𝛁𝒚𝒏 + 𝛁𝟐 𝒚𝒏 + 𝛁𝟑 𝒚𝒏 +. . . + 𝛁𝒏 𝒚𝒏
𝟐! 𝟑! 𝒏!

𝒙−𝒙𝒏
where 𝒑 =
𝒉

8.The divided differences:-

𝒇(𝒙𝒏 ) − 𝒇(𝒙𝒏−𝟏 )
𝒇[𝒙𝒏−𝟏 , 𝒙𝒏 ] =
𝒙𝒏 − 𝒙𝒏−𝟏

These are called first divided differences and is devoted by 𝚫𝒇. Higher divided differences
operators are defined as:

𝒇[𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒌 ] − 𝒇[𝒙𝟎 , … , 𝒙𝒌−𝟏 ]


𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒌−𝟏 , 𝒙𝒌, ] =
𝒙𝒌 − 𝒙𝟎

for 𝒌 = 𝟑, 𝟒, 𝟓, . . . , 𝒏

these differences are denoted by 𝚫𝟐 𝒇, 𝚫𝟑 𝒇 … … . 𝚫𝒌 𝒇

9. Newton’s divided difference interpolation formula:-

𝑷(𝒙) = 𝒇(𝒙𝟎 ) + (𝒙 − 𝒙𝟎 )𝒇[𝒙𝟎 , 𝒙𝟏 ] + (𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 ]

+(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )𝒇[𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑 ] + ⋯

+(𝒙 − 𝒙𝟎 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏−𝟏 )𝒇[𝒙𝟎 , 𝒙𝟏 , … , 𝒙𝒏 ]

10. Cubic Spline Interpolation:-

𝟏 𝟑 𝟑
𝟏 𝒉𝟐
𝑺(𝒙) = [(𝒙𝒊 − 𝒙) 𝑴𝒊−𝟏 + (𝒙 − 𝒙𝒊−𝟏 ) 𝑴𝒊 ] + (𝒙𝒊 − 𝒙) [𝒚𝒊−𝟏 − 𝑴𝒊−𝟏 ] +
𝟔𝒉 𝒉 𝟔
𝟏 𝒉𝟐
+ 𝒉 (𝒙 − 𝒙𝒊−𝟏 ) [𝒚𝒊 − 𝑴𝒊 ] , 𝒊 = 𝟏, 𝟐, 𝟑, … , 𝒏 (1)
𝟔

Dr. Jamil Book Series 2 Page 77


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

𝟔
𝑴𝒊−𝟏 + 𝟒𝑴𝒊 + 𝑴𝒊+𝟏 = 𝒉𝟐 [𝒚𝒊−𝟏 − 𝟐𝒚𝒊 + 𝒚𝒊+𝟏 ], 𝐢 = 𝟏, 𝟐, 𝟑, … . . , 𝐧 − 𝟏 (2)

and

𝑴𝟎 = 𝑴𝒏 = 𝟎 (3)

11.Least squares method for curve fitting

12. Fitting a straight line by the method of least square:-


Let 𝒚 = 𝒂𝒙 + 𝒃 be the best fit straight line to the data. Then the normal equations are:

𝒂 ∑ 𝒙𝒊 + 𝒏𝒃 = ∑ 𝒚𝒊

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

13. Fitting a Parabola or fitting a second degree curve by the method of least
squares: OR Second degree approximation:-
Let 𝒚 = 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄 be the best fit parabola. Then the normal equations are:

𝒂 ∑ 𝒙𝟐𝒊 + 𝒃 ∑ 𝒙𝒊 + 𝒏𝒄 = ∑ 𝒚𝒊

𝒂 ∑ 𝒙𝟑𝒊 + 𝒃 ∑ 𝒙𝟐𝒊 + 𝒄 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒚𝒊

𝒂 ∑ 𝒙𝟒𝒊 + 𝒃 ∑ 𝒙𝟑𝒊 + 𝒄 ∑ 𝒙𝟐𝒊 = ∑ 𝒙𝟐𝒊 𝒚𝒊

By solving these equations, we can determine 𝒂, 𝒃 and 𝒄 to obtain the best fit second-degree
polynomial 𝒚(𝒙) = 𝒇(𝒙) = 𝒂𝒙𝟐 + 𝒃𝒙 + 𝒄 .

14. Fitting an exponential curve (𝒚 = 𝒂𝒃𝒙 ):-


Let the curve to be fitted be given by 𝒚 = 𝒂𝒃𝒙 .Then applying logarithm (of base 10) on both
sides, we get

𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒙𝒍𝒐𝒈𝒃

⟹ 𝒀 = 𝑨 + 𝑩𝒙 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑨 = 𝒍𝒐𝒈𝒂 , 𝑩 = 𝒍𝒐𝒈𝒃

Dr. Jamil Book Series 2 Page 78


Applied Numerical Methods Chapter#2 Interpolation & Curve Fitting

Then Normal Equations of the line 𝒀 = 𝑨 + 𝑩𝒙 are :

𝑩 ∑ 𝒙𝒊 + 𝒏𝑨 = ∑ 𝒀𝒊

𝑩 ∑ 𝒙𝟐𝒊 + 𝑨 ∑ 𝒙𝒊 = ∑ 𝒙𝒊 𝒀𝒊

15. Fitting a curve of the form 𝒚 = 𝒂𝒙𝒃 :-


Let the curve to be fitted be given by 𝒚 = 𝒂𝒙𝒃 .Then applying logarithm (of base 10) on both
sides, we get

⟹ 𝒍𝒐𝒈𝒚 = 𝒍𝒐𝒈𝒂 + 𝒃𝒍𝒐𝒈𝒙

⟹ 𝒀 = 𝑨 + 𝒃𝑿 , where 𝒀 = 𝒍𝒐𝒈𝒚 , 𝑿 = 𝒍𝒐𝒈𝒙 , 𝑨 = 𝒍𝒐𝒈𝒂

Then Normal Equations of the line 𝒀 = 𝑨 + 𝒃𝑿are :

𝒃 ∑ 𝑿𝒊 + 𝒏𝑨 = ∑ 𝒀𝒊

𝒃 ∑ 𝑿𝟐𝒊 + 𝑨 ∑ 𝑿𝒊 = ∑ 𝑿𝒊 𝒀𝒊

Dr. Jamil Book Series 2 Page 79

You might also like