You are on page 1of 34

ES-341:

Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Piecewise
Polynomial
Interpolation
Piecewise Linear
ES-341: Numerical Analysis
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation
Dr. Mazhar Ali
Mehboob ul Haq (TA)

Faculty of Engineering Sciences

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology

20 − 24th April 2022

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 1 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Piecewise
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
1 Piecewise Polynomial Interpolation
Interpolation
Piecewise Linear Interpolation
Piecewise Quadratic Interpolation
Piecewise Cubic Interpolation

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 2 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Piecewise
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation

Piecewise Polynomial Interpolation

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 3 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA) Piecewise Polynomial Interpolation
Piecewise Previously proposed techniques, such as Lagrange, Newton
Polynomial
Interpolation Divided Difference, and Hermite Interpolating Methods
Piecewise Linear
Interpolation
approximates a function f (x) around some specified x using a
Piecewise Quadratic
Interpolation
single interpolatory Polynomial.
Piecewise Cubic
Interpolation The main drawback is that high degree of polynomial can oscillate
erratically i,e, some minor fluctuations over small portion of the
intervals can include large fluctuations over the entire range.

Piecewise Polynomial Interpolation


To over these issues, we can divide the approximation intervals
into a collection of sub-intervals, and construct an approximating
polynomial on each sub interval ⇒ known as “Piecewise
Polynomial Interpolation ” or ”Spline functions”.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 4 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA) 𝑠(𝑥)

Piecewise
Polynomial
Interpolation
Piecewise Linear
𝑠0 (𝑥)
Interpolation 𝑠1 (𝑥) 𝑠0 (𝑥)
𝑠0 (𝑥)
Piecewise Quadratic
Interpolation 𝑠𝑗 (𝑥)

Piecewise Cubic
Interpolation

𝑥0 𝑥1 𝑥2 𝑥𝑗 𝑥𝑗+1 𝑥𝑛−2 𝑥𝑛−2 𝑥𝑛 𝑥

Definition
We can divide an interval [x0 , xn ] into set of n number of small
intervals {[x0 , x1 ], [x1 , x2 ], . . . , [xn−1 , xn ]} and then for each
sub-interval [xj , xj+1 ], j = 0, 1, 2, . . . , n − 1 we approximate with
collection of n number of spline polynomials sj (x) (either linear,
quadratic, or cubic) as shown in the Fig.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 5 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Spline Interpolation: Piecewise Linear Interpolation
Piecewise
Polynomial
Interpolation
The most common type of spline interpolation is based on
Piecewise Linear
Interpolation
piecewise linear interpolation, in which set of sub-interval
Piecewise Quadratic [xj , xj+1 ], j = 0, 1, 2, . . . , n − 1 can be joined by straight lines.
Interpolation
Piecewise Cubic Consequently, we can describe the n number of spline
Interpolation
s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 in this case as,

a0 + b0 (x − x0 ) x0 ≤ x ≤ x1
 

 

a1 + b1 (x − x1 ) x1 ≤ x ≤ x2

 

 
s(x) = ..



 . 



 
an−1 + bn−1 (x − xn−1 ) xn−1 ≤ x ≤ xn

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 6 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Conditions!
Piecewise
Polynomial
Interpolation
As we have n number of spline
Piecewise Linear s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 and each spline is a linear
Interpolation
Piecewise Quadratic interpolatory polynomial, we got 2n unknown coefficients i.e.,
Interpolation
Piecewise Cubic a0 , a1 , . . . an−1 and b0 , b1 , . . . , bn−1 .
Interpolation

In case of linear polynomial splines (piecewise linear interpolation)


We can just use the following criteria to find all those 2n unknown
coefficients,

if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2, . . . , n − 1

if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2, . . . , n − 1

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 7 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali Example 1:


Mehboob ul Haq
(TA)
Fit the data in the table with first order (linear) splines to evaluate
Piecewise f (2.5)
Polynomial
Interpolation
Piecewise Linear
Interpolation
i xi f (xi )
Piecewise Quadratic 0 1 2
Interpolation
Piecewise Cubic 1 2 3
Interpolation
2 3 5

Solution
In this case we will construct only two linear splines i.e., s0 (x) between
[x0 , x1 ] = [1, 2] and another ons1 (x) between [x1 , x2 ] = [2, 3],
( )
s0 (x) = a0 + b0 (x − 1) 1≤x ≤2
s(x) =
s1 (x) = a1 + b1 (x − 2) 2≤x ≤3

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 8 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


We have two four unknowns a0 , a1 and b0 , b1 ,
Mehboob ul Haq
(TA) Applying conditions
Piecewise
Polynomial
Interpolation
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2
Piecewise Cubic
Interpolation
s0 (x0 ) = a0 = f (x0 ) = 2
f (x1 ) − a0
s0 (x1 ) = a0 + b0 (x1 − x0 ) = f (x1 ) ⇒ b0 =
x1 − x0
b0 = 1
Similarly,
s1 (x1 ) = a1 = f (x1 ) = 3
f (x2 ) − a1
s1 (x2 ) = a1 + b1 (x2 − x1 ) = f (x2 ) ⇒ b0 =
x2 − x1
b1 = 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 9 / 27
ES-341:
Numerical
Analysis Hence, the spline is,
Dr. Mazhar Ali
Mehboob ul Haq
( )
(TA) s0 (x) = 2 + 1(x − 1) 1≤x ≤2
s(x) =
Piecewise s1 (x) = 3 + 2(x − 2) 2≤x ≤3
Polynomial
Interpolation
Piecewise Linear
Interpolation We can evaluate f (2.5) as,
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation s1 (2.5) = 4

Figure: Linear Spline Interpolation.


Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 10 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Spline Interpolation: Piecewise Quadratic Interpolation
Piecewise
Polynomial A more precise spline interpolation is based on piecewise quadratic
Interpolation
Piecewise Linear
interpolation, in which set of sub-interval
Interpolation
Piecewise Quadratic
[xj , xj+1 ], j = 0, 1, 2, . . . , n − 1 can be joined by quadratic
Interpolation
Piecewise Cubic
polynomials. Consequently, we can describe the n number of
Interpolation
spline s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 in this case as,

a0 + b0 (x − x0 ) + c0 (x − x0 )2 x0 ≤ x ≤ x1 
 

 
2
 a1 + b1 (x − x1 ) + c1 (x − x1 ) x1 ≤ x ≤ x2 

 
 

s(x) = ..


 . 


..

 

 
.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 11 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA) Conditions!
Piecewise
As we have n number of spline
Polynomial
Interpolation
s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 and each spline is a
Piecewise Linear
Interpolation
quadratic interpolatory polynomial, we got 3n unknown coefficients
Piecewise Quadratic
Interpolation
i.e., a0 , a1 , . . . an−1 , b0 , b1 , . . . , bn−1 , & c0 , c1 , . . . , cn−1 .
Piecewise Cubic
Interpolation In case of quadratic polynomial splines (piecewise quadratic
interpolation), we can just use the following criteria to find 2n
conditions (equations) as,

if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2, . . . , n − 1

if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2, . . . , n − 1

We are still short of n more conditions to solve for all the unknown
coefficients.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 12 / 27
ES-341:
Numerical
Analysis Conditions
Dr. Mazhar Ali
Mehboob ul Haq We can exploit this fact that adjacent splines i.e., sj (x) and
(TA)
sj+1 (x) must coincide at xj+1 (for instance, s0 (x1 ) = s1 (x1 ))
Piecewise
Polynomial
Interpolation sj (xj+1 ) = sj+1 (xj+1 ) j = 0, 1, . . . , n − 2
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
The above criteria can be used to ensure that the set of splines
Piecewise Cubic
Interpolation
s(x) = {sj (x)} are smooth on the adjacent nodes xj+1 , we can
derive the condition about differentiability from the following
relation,

sj′ (xj+1 ) = sj+1



(xj+1 ) j = 0, 1, . . . , n − 2

Consequently, we have n − 1 more conditions.


Finally, we can apply the following boundary conditions,

s ′ (xn ) = 0

Above boundary conditions constitute as 1 more conditions.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 13 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali Example 2:


Mehboob ul Haq
(TA)
Fit the data in the table with second order (quadratic) splines to
Piecewise evaluate f (2.5)
Polynomial
Interpolation
Piecewise Linear
Interpolation
i xi f (xi )
Piecewise Quadratic 0 1 2
Interpolation
Piecewise Cubic 1 2 3
Interpolation
2 3 5

Solution
In this case we will construct only two quadratic splines i.e., s0 (x)
between [x0 , x1 ] = [1, 2] and another ons1 (x) between [x1 , x2 ] = [2, 3],
( )
s0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 1≤x ≤2
s(x) =
s1 (x) = a1 + b1 (x − 2) + c1 (x − 2)2 2≤x ≤3

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 14 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA) We have six unknowns a0 , a1 , b0 , b1 and c0 , c1 ,
Piecewise Applying conditions
Polynomial
Interpolation
Piecewise Linear
Interpolation
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2

s0 (x0 ) = a0 = f (x0 ) = 2

s0 (x1 ) = a0 + b0 (x1 − x0 ) + c0 (x1 − x0 )2 = f (x1 ) ⇒ b0 + c0 = 1


Similarly,
s1 (x1 ) = a1 = f (x1 ) = 3

s1 (x2 ) = a1 + b1 (x2 − x1 ) + c1 (x2 − x1 )2 = f (x2 ) ⇒ b1 + c1 = 2

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 15 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali Applying the differentiability condition,


Mehboob ul Haq
(TA)

sj′ (xj+1 ) = sj+1



(xj+1 ) j = 0, 1, . . . , n − 2
Piecewise
Polynomial
Interpolation
Piecewise Linear
Interpolation
s0′ (x1 ) = s1′ (x1 )
s0′ (x) = b0 + 2c0 (x − x0 )
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation
s1′ (x) = b1 + 2c1 (x − x1 )
s0′ (x1 ) = s1′ (x1 ) ⇒ b0 + 2c0 = b1
Finally, we can apply one of the boundary condition

s ′ (xn ) = 0

s1′ (x2 ) = b1 + 2c1 = 0


After solving all equations simultaneously, we get
b0 = −2, c0 = 3, b1 = 4 and c1 = −2.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 16 / 27
ES-341:
Numerical
Analysis Hence, the spline is,
Dr. Mazhar Ali
Mehboob ul Haq
( )
(TA) s0 (x) = 2 − 2(x − 1) + 3(x − 1)2 1≤x ≤2
s(x) =
Piecewise s1 (x) = 3 + 4(x − 2) − 2(x − 2)2 2≤x ≤3
Polynomial
Interpolation
Piecewise Linear
Interpolation We can evaluate f (2.5) as,
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation s1 (2.5) = 4.5

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 17 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)
Spline Interpolation: Piecewise Cubic Interpolation
Piecewise
Polynomial Now, we can describe cubic spline interpolation is based on
Interpolation
Piecewise Linear piecewise cubic interpolation, in which set of sub-interval
Interpolation
Piecewise Quadratic
[xj , xj+1 ], j = 0, 1, 2, . . . , n − 1 can be joined by cubic
Interpolation
Piecewise Cubic
polynomials. Consequently, we can describe the n number of
Interpolation
spline s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 in this case as,

a0 + b0 (x − x0 ) + c0 (x − x0 )2 + d0 (x − x0 )3 [x0 , x1 ]
 

 

 2 3 
 a1 + b1 (x − x1 ) + c1 (x − x1 ) + d1 (x − x1 ) [x1 , x2 ]

 


s(x) = ..

 . 

 
..

 

 
.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 18 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq Conditions!
(TA)
As we have n number of spline
Piecewise
Polynomial s(x) = {sj (x)}, j = 0, 1, 2, . . . , n − 1 and each spline is a cubic
Interpolation
Piecewise Linear
interpolatory polynomial, we got 4n unknown coefficients i.e.,
Interpolation
Piecewise Quadratic
a0 , a1 , . . . an−1 , b0 , b1 , . . . , bn−1 , c0 , c1 , . . . , cn−1 &
Interpolation
Piecewise Cubic
d0 , d1 , . . . , dn−1 .
Interpolation
In case of cubic polynomial splines (piecewise cubic interpolation)
We can just use the following criteria to find 2n conditions
(equations) as,

if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2, . . . , n − 1

if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2, . . . , n − 1

We are still short of 2n more conditions to solve for all the


unknown coefficients.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 19 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Conditions
(TA)
Similar to quadratic spline, we can exploit this fact that adjacent
Piecewise splines i.e., sj (x) and sj+1 (x) must coincide at xj+1 (for instance,
Polynomial
Interpolation s0 (x1 ) = s1 (x1 ))
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
sj (xj+1 ) = sj+1 (xj+1 ) j = 0, 1, . . . , n − 2
Piecewise Cubic
Interpolation
The above criteria can be used to ensure that the set of splines
s(x) = {sj (x)} are smooth on the adjacent nodes xj+1 , we can
derive the condition about differentiability from the following
relation,

sj′ (xj+1 ) = sj+1 (xj+1 ) j = 0, 1, . . . , n − 2

sj′′ (xj+1 ) = sj+1


′′
(xj+1 ) j = 0, 1, . . . , n − 2

Consequently, we have 2n − 2 more conditions.

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 20 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Conditions
Piecewise
Polynomial
Interpolation Finally, we can apply the following boundary conditions,
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
s ′′ (x0 ) = 0 & s ′′ (xn ) = 0
Piecewise Cubic
Interpolation

Above boundary conditions constitute as 2 more conditions. These


conditions are referred to as “free/natural boundary”.
Alternatively, we can us the clamped boundary conditions

s ′ (x0 ) = f ′ (x0 ) & s ′ (xn ) = f ′ (xn )

However, for this we need information about f ′ (x0 ) and f ′ (x1 ).

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 21 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Example 3:
(TA)
Fit the data in the table with third order (cubic) splines to evaluate
Piecewise
Polynomial
f (2.5)
Interpolation
Piecewise Linear
Interpolation
i xi f (xi )
Piecewise Quadratic
Interpolation
0 1 2
Piecewise Cubic
Interpolation
1 2 3
2 3 5

Solution
In this case we will construct only two cubic splines i.e., s0 (x) between
[x0 , x1 ] = [1, 2] and another on s1 (x) between [x1 , x2 ] = [2, 3],

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 22 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Example 3:
(TA)
Fit the data in the table with third order (cubic) splines to evaluate
Piecewise
Polynomial
f (2.5)
Interpolation
Piecewise Linear
Interpolation
i xi f (xi )
Piecewise Quadratic
Interpolation
0 1 2
Piecewise Cubic
Interpolation
1 2 3
2 3 5

Solution
In this case we will construct only two cubic splines i.e., s0 (x) between
[x0 , x1 ] = [1, 2] and another on s1 (x) between [x1 , x2 ] = [2, 3],

s0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3



1≤x ≤2
s(x) =

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 22 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
Example 3:
(TA)
Fit the data in the table with third order (cubic) splines to evaluate
Piecewise
Polynomial
f (2.5)
Interpolation
Piecewise Linear
Interpolation
i xi f (xi )
Piecewise Quadratic
Interpolation
0 1 2
Piecewise Cubic
Interpolation
1 2 3
2 3 5

Solution
In this case we will construct only two cubic splines i.e., s0 (x) between
[x0 , x1 ] = [1, 2] and another on s1 (x) between [x1 , x2 ] = [2, 3],

s0 (x) = a0 + b0 (x − 1) + c0 (x − 1)2 + d0 (x − 1)3


 
1≤x ≤2
s(x) =
s1 (x) = a1 + b1 (x − 2) + c1 (x − 2)2 + d1 (x − 2)3 2≤x ≤3

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 22 / 27
ES-341:
Numerical
Analysis We have eight unknowns a0 , a1 , b0 , b1 c0 , c1 and d0 , d1 ,
Dr. Mazhar Ali
Mehboob ul Haq
Applying conditions
(TA)

Piecewise
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 23 / 27
ES-341:
Numerical
Analysis We have eight unknowns a0 , a1 , b0 , b1 c0 , c1 and d0 , d1 ,
Dr. Mazhar Ali
Mehboob ul Haq
Applying conditions
(TA)

Piecewise
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2
Interpolation
Piecewise Cubic
Interpolation

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 23 / 27
ES-341:
Numerical
Analysis We have eight unknowns a0 , a1 , b0 , b1 c0 , c1 and d0 , d1 ,
Dr. Mazhar Ali
Mehboob ul Haq
Applying conditions
(TA)

Piecewise
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2
Interpolation
Piecewise Cubic
Interpolation

s0 (x0 ) = a0 = f (x0 ) = 2

s0 (x1 ) = a0 + b0 (x1 − x0 ) + c0 (x1 − x0 )2 + d0 (x1 − x0 )3 = f (x1 )


b0 + c0 + d0 = 1

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 23 / 27
ES-341:
Numerical
Analysis We have eight unknowns a0 , a1 , b0 , b1 c0 , c1 and d0 , d1 ,
Dr. Mazhar Ali
Mehboob ul Haq
Applying conditions
(TA)

Piecewise
if x = xj ⇒ sj (xj ) = f (xj ) j = 0, 1, 2
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic if x = xj+1 ⇒ sj (xj+1 ) = f (xj+1 ) j = 0, 1, 2
Interpolation
Piecewise Cubic
Interpolation

s0 (x0 ) = a0 = f (x0 ) = 2

s0 (x1 ) = a0 + b0 (x1 − x0 ) + c0 (x1 − x0 )2 + d0 (x1 − x0 )3 = f (x1 )


b0 + c0 + d0 = 1

Similarly,
s1 (x1 ) = a1 = f (x1 ) = 3

s1 (x2 ) = a1 + b1 (x2 − x1 ) + c1 (x2 − x1 )2 + d1 (x2 − x1 )3 = f (x2 )


b1 + c1 + d1 = 2
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 23 / 27
ES-341:
Numerical
Analysis Applying the differentiability conditions for cubic splines,
Dr. Mazhar Ali
Mehboob ul Haq
(TA) sj′ (xj+1 ) = sj+1

(xj+1 ) j = 0, 1, . . . , n − 2
Piecewise
Polynomial
Interpolation
s0′ (x1 ) = s1′ (x1 )
Piecewise Linear
Interpolation
s0′ (x) = b0 + 2c0 (x − x0 ) + 3d0 (x − x0 )2
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation
s1′ (x) = b1 + 2c1 (x − x1 ) + 3d1 (x − x1 )2
s0′ (x1 ) = s1′ (x1 ) ⇒ b0 + 2c0 + 3d0 = b1
applying second differentiability condition,

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 24 / 27
ES-341:
Numerical
Analysis Applying the differentiability conditions for cubic splines,
Dr. Mazhar Ali
Mehboob ul Haq
(TA) sj′ (xj+1 ) = sj+1

(xj+1 ) j = 0, 1, . . . , n − 2
Piecewise
Polynomial
Interpolation
s0′ (x1 ) = s1′ (x1 )
Piecewise Linear
Interpolation
s0′ (x) = b0 + 2c0 (x − x0 ) + 3d0 (x − x0 )2
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation
s1′ (x) = b1 + 2c1 (x − x1 ) + 3d1 (x − x1 )2
s0′ (x1 ) = s1′ (x1 ) ⇒ b0 + 2c0 + 3d0 = b1
applying second differentiability condition,

sj′′ (xj+1 ) = sj+1


′′
(xj+1 ) j = 0, 1, . . . , n − 2

s0′′ (x1 ) = s1′′ (x1 )


s0′′ (x) = 2c0 + 6d0 (x − x0 )
s1′′ (x) = 2c1 + 6d1 (x − x1 )
s0′′ (x1 ) = s1′′ (x1 ) ⇒ 2c0 + 6d0 = 2c1
Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 24 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


Mehboob ul Haq
(TA)

Piecewise
Applying necessary free/natural boundary conditions
Polynomial
Interpolation
Piecewise Linear
Interpolation
s ′′ (x0 ) = 0
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation
s0′′ (x) = 2c0 + 6d0 (x − 1)
s0′′ (x0 ) = 2c0 = 0 ⇒ c0 = 0

s ′′ (xn ) = 0

s1′′ (x) = 2c1 + 6d1 (x − x1 )


s1′′ (x2 ) = 2c1 + 6d1 = 0

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 25 / 27
ES-341:
Numerical
Analysis

Dr. Mazhar Ali


We have following equations
Mehboob ul Haq
(TA)
b0 + d0 = 1
Piecewise
Polynomial
Interpolation
Piecewise Linear b1 + c1 + d1 = 2
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
b0 + 3d0 − b1 = 0
Interpolation

6d0 − 2c1 = 0

2c1 + 6d1 = 0
From all the conditions we can assemble following system of linear
equations,     
1 1 0 0 0 b0 1
0 0 1 1 1 d0  2
    
1 3
 −1 0 0
 b1  = 0
   
0 6 0 −2 0  c1  0

0 0 0 2 6 d1 0

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 26 / 27
ES-341:
Numerical After solving the system of equations we get,
Analysis

Dr. Mazhar Ali 3 1 3 3 −1


Mehboob ul Haq b0 = d0 = b1 = c1 = d1 =
(TA) 4 4 2 4 4
Piecewise Hence, the spline is,
Polynomial
Interpolation
Piecewise Linear
Interpolation
Piecewise Quadratic
Interpolation
Piecewise Cubic
Interpolation

Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 27 / 27
ES-341:
Numerical After solving the system of equations we get,
Analysis

Dr. Mazhar Ali 3 1 3 3 −1


Mehboob ul Haq b0 = d0 = b1 = c1 = d1 =
(TA) 4 4 2 4 4
Piecewise Hence, the spline is,
Polynomial
Interpolation
 s0 (x) = 2 + 3 (x − 1) + (0)(x − 1)2 + 1
 
Piecewise Linear
Interpolation (x − 1)3 ; [1, 2] 
Piecewise Quadratic s(x) = 4 4
Interpolation
 s (x) = 3 + 3 (x − 2) + 3 (x − 2)2 − 1
(x − 2)3 ; [2, 3] 
Piecewise Cubic 1
Interpolation 2 4 4
We can evaluate f (2.5) as,
s1 (2.5) = 3.8125

Figure: Cubic Splines Interpolation.


Dr. Mazhar Ali Mehboob ul Haq (TA) (Ghulam Ishaq Khan Institute
ES-341:
of Engineering
NumericalSciences
Analysis
and Technology) 20 − 24th April 2022 27 / 27

You might also like