Spline Interpolation: Linear
Spline Interpolation (LSI)
Lecture-1
1
Objectives
❑ Plotting line or curve using providing data sets
❑ Analyze line or curve
Applications
❑ Data analysis numerically in Mathematics
Spline Interpolation
In the mathematical field of numerical analysis, spline interpolation is a form
of interpolation where the interpolant is a special type of piecewise polynomial
called a spline. It is often preferred over polynomial interpolation because the
interpolation error can be made small even when using low degree polynomials
for the spline.
2
Linear spline
x y
𝑥1 𝑦1
Cubic spline 𝑥2 𝑦2
𝑥3 𝑦3
𝑥4 𝑦4
𝑥5 𝑦5
Definition of Spline Interpolation
Spline interpolation function is a piecewise polynomial function
joined together with certain conditions satisfied by them. A
function f(x) of the form
𝑓1 𝑥 , 𝑥1 ≤ 𝑥 < 𝑥2
𝑓2 𝑥 , 𝑥2 ≤ 𝑥 < 𝑥3
𝑓 𝑥 =
⋮
𝑓𝑛−1 𝑥 , 𝑥𝑛−1 ≤ 𝑥 ≤ 𝑥𝑛
is called a spline of degree m if
(i) the domain of 𝑓(𝑥) is the interval [𝑥1 , 𝑥𝑛 ]
(ii) 𝑓 𝑥 , 𝑓 ′ 𝑥 , 𝑓 ′′ 𝑥 … 𝑓 (𝑚−1) are all continuous
functions on the interval [𝑥1 , 𝑥𝑛 ]
(iii) 𝑓(𝑥) is a polynomial of degree less than or equal to m
on each subinterval [𝑥𝑘 , 𝑥𝑘+1 ], 𝑘 = 1, 2, ⋯ , 𝑛.
4
𝑓𝑘 (𝑥) = 𝑎𝑘 𝑥 − 𝑥𝑘 + 𝑏𝑘
Spline Interpolation 𝑦𝑘 = 𝑎𝑘 𝑥𝑘 − 𝑥𝑘 + 𝑏𝑘
❑ Linear Spline Interpolation (LSI) 𝑏𝑘 = 𝑦𝑘
𝑦𝑘+1 = 𝑎𝑘 𝑥𝑘+1 − 𝑥𝑘 + 𝑦𝑘
❑ Cubic Spline Interpolation(CSI) 𝑎𝑘 =
𝑦𝑘+1 − 𝑦𝑘
𝑥𝑘+1 − 𝑥𝑘
▪ Linear Spline Interpolation (LSI)
For a linear spline through (𝑥𝑘 , 𝑦𝑘 ) we may take 𝑓𝑘 (𝑥) is of the
form
𝑓𝑘 𝑥 = 𝑎𝑘 𝑥 − 𝑥𝑘 + 𝑏𝑘 , for 𝑥𝑘 ≤ 𝑥 ≤ 𝑥𝑘+1
Since the line passes through (𝑥𝑘 , 𝑦𝑘 ) and (𝑥𝑘+1 , 𝑦𝑘+1 ) we have
𝑏𝑘 = 𝑦𝑘
𝑦𝑘+1 −𝑦𝑘 ∆𝑦𝑘
and 𝑎𝑘 = =
𝑥𝑘+1 −𝑥𝑘 ℎ𝑘
where ∆𝑦𝑘 = 𝑦𝑘+1 − 𝑦𝑘 and ℎ𝑘 = 𝑥𝑘+1 − 𝑥𝑘 . 5
The resulting linear spline curve 𝑓𝑘 𝑥 in [𝑥𝑘 , 𝑥𝑘+1 ] can be
written as
∆𝑦𝑘
𝑓𝑘 𝑥 = 𝑦𝑘 + 𝑥 − 𝑥𝑘 , 𝑘 = 1, 2, … , 𝑛 − 1 .
ℎ𝑘
Example
Find the linear spline for the following data set
X −1 1 2 5
Y 2.2 3.5 5.4 1.5
Hence estimate the value of 𝑦(1.5).
6
𝑓𝑘 𝑥
∆𝑦𝑘
Solution: = 𝑦𝑘 + 𝑥 − 𝑥𝑘
ℎ𝑘
Linear spline functions in different intervals are
∆𝑦𝑘
x y ℎ𝑘
𝑓1 𝑥 = 2.2 + 0.65 𝑥 + 1 , −1 ≤ 𝑥 ≤ 1
-1 2.2
1 3.5 0.65
𝑓2 𝑥 = 3.5 + 1.9(𝑥 − 1), 1≤𝑥≤2
2 5.4 1.9
𝑓3 𝑥 = 5.4 − 1.3(𝑥 − 2), 2≤𝑥≤5 5 1.5 -1.3
Linear spline function is
2.2 + 0.65 𝑥 + 1 , −1 ≤ 𝑥 ≤ 1
𝑓 𝑥 = ൞ 3.5 + 1.9(𝑥 − 1), 1≤𝑥≤2
5.4 − 1.3 𝑥 − 2 2≤𝑥≤5
The value 𝑥 = 1.5 is in 1 ≤ 𝑥 ≤ 2. Thus
𝑦 1.5 = 3.5 + 1.9 1.5 − 1
= 4.45.
Linear spline is continuous at the common point. When 𝑥 = 1
𝑓1 1 = 2.2 + 0.65 2 = 3.5 𝑎𝑛𝑑
𝑓2 1 = 3.5. So 𝑓(𝑥) is continuous at x=1 7
Outcomes
❑ Numerically get value of a function at specific value belongs to
the given data sets by using LSI.
Try to do yourself
Exercise 1: In a chemical reaction the concentration level y of the
product at time t (minute) was measured every half
hour. The following results were found:
t 1.0 1.5 2.0 2.5
y 0.25 0.27 0.31 0.46
Construct a linear spline interpolation to estimate the concentration
level at 2.2 minute.
8
Exercise 2: Use the portion of the given steam table for superheated
H2O at 200 MPa to find the corresponding entropy, s, for a
specific volume, v, of 0.118 m3/kg with linear spline.
V (m3/kg) 0.2037 0.2114 0.32547 0.33213
S (kJ/kg K) 6.5147 6.6453 6.8664 6.9513
❑ Cubic Spline Interpolation(CSI)
Cubic spline interpolation is used very often. It gives smoother
curves than other types. To determine the cubic spline, we need to
use cubic polynomial for each subintervals.
9
Consider the cubic polynomial 𝑓𝑘 (𝑥) in each subinterval
𝑥𝑘 , 𝑥𝑘+1 , 𝑘 = 1 , 2, … , 𝑛 − 1 of the form
𝑓𝑘 𝑥
= 𝑎𝑘 𝑥 − 𝑥𝑘−1 3 + 𝑏𝑘 𝑥 − 𝑥𝑘−1 2 + 𝑐𝑘 (𝑥 − 𝑥𝑘−1 ) + 𝑑𝑘 ,
𝑎𝑘 ≠ 0 .
where 𝑎𝑘 , 𝑏𝑘 , 𝑐𝑘 and 𝑑𝑘 are to be determined.
Since the spline passes through 𝑥𝑘 , 𝑦𝑘 , and 𝑓𝑘 (𝑥),
𝑓1 𝑥0 = 𝑦0 , and 𝑓𝑘 𝑥𝑘 = 𝑦𝑘 , 𝑘 = 1, 2, 3, ⋯ , 𝑛.
𝑓𝑘 𝑥𝑘 = 𝑓𝑘+1 𝑥𝑘 , 𝑘 = 1, 2, 3, ⋯ , 𝑛 − 1
𝑓𝑘 ′ 𝑥𝑘 = 𝑓𝑘+1 ′ 𝑥𝑘 , 𝑘 = 1, 2, 3, ⋯ , 𝑛 − 1
𝑓𝑘 ′′ 𝑥𝑘 = 𝑓𝑘+1 ′′ 𝑥𝑘 , 𝑘 = 1, 2, 3, ⋯ , 𝑛 − 1
We can see that there are
1 + 𝑛 + 3 𝑛 − 1 = 4𝑛 − 2
conditions but we need to determine 4n constants. 10
Boundary conditions
So we need to add two boundary conditions to get unique solution.
Normally we use three types of boundary conditions:
1. Second derivatives at end points are known
𝑓1′′ 𝑥0 = 𝑀0 and 𝑓𝑛′′ 𝑥𝑛 = 𝑀𝑛 .
The special case
𝑓1′′ 𝑥0 = 0 and 𝑓𝑛′′ 𝑥𝑛 = 0
give spline called natural cubic spline.
2. First derivatives at end points are known
𝑓1′ 𝑥0 = 𝑑0 and 𝑓𝑛′ 𝑥𝑛 = 𝑑𝑛 .
give spline called clamped cubic spline.
11
3. Automatically adjusted boundary conditions known as not-a-knot
cubic spline.
This condition assumes that 𝑓 ′′′ 𝑥 are continuous at the second and
last but one points.
𝑓1′′′ (𝑥1 ) = 𝑓2′′′ 𝑥1 and 𝑓𝑛−1
′′′
(𝑥𝑛−1 ) = 𝑓𝑛′′′ (𝑥𝑛−1 ).
Note that minimum number of data points is four for this condition to
be used.
12
Multiple questions:
S.No. Questions
1 How many Spline interpolation we discussed in Numerical Analysis?
(a) One,
(b) Two,
(c) None of them
2 What is the linear spline curve 𝑓𝑘 𝑥 in [𝑥𝑘 , 𝑥𝑘+1 ] for 𝑘 = 1, 2, … , 𝑛 − 1 ?
Which rule is used for getting Modified Euler’s method-
Taylor series can be expresses as follows:
∆𝑦
(a) 𝑓𝑘 𝑥 = 𝑦𝑘 + 𝑘 𝑥 − 𝑥𝑘 ,
ℎ𝑘
∆𝑦
(b) 𝑓𝑘 𝑥 = 𝑦𝑘−1 + ℎ 𝑘 𝑥 − 𝑥𝑘 ,
𝑘
∆𝑦𝑘
(c) 𝑓𝑘 𝑥 = 𝑦𝑘+1 + ℎ 𝑥 − 𝑥𝑘 ,
𝑘
(d) None of them
4 Which spline is smooth?
(a) Linear Spline interpolation ,
(b) Cubic Spline interpolation,
(c) None of them,
(d) Both of them
13
References
[1] Applied Numerical Methods With Matlab for Engineers and Scientists ( Steven
C.Chapra).
[2] Applied Numerical Analysis – C.F.Gerald & P.O.Wheatley, 7th Edition, 2003,
Pearson Education Limited, USA.
[3] Numerical Analysis & Computing – W. Cheney & D. Kincaid, 6th Edition, 2007,
Cengage Learning, Inc, USA.
[4] Numerical Analysis – J. Douglas Faires , Annette Burden , Richard Burden, 10th
Edition, 2015, Cengage Learning, Inc, USA.
14