Spline Interpolation Techniques
Spline Interpolation Techniques
By
May 2024
KOTEBE UNIVERISTY OF EDUCATION
College of Science and Mathematics Education
Department of Mathematics
Declaration
HAILEMARIAM WELDEGEBREAL declare that this paper is an original work and is
submitted to Department of Mathematics, College of Science and Mathematics Education,
Kotebe University of Education in partial fulfillment for the degree of Bachelor of Science in
Mathematics entitled:
It has never been presented to any university or authority as clarified project. All the sources
used on the project have been acknowledged and given credit.
I|Page
Acknowledgment
Firstly, I am highly grateful to my advisor, Mr. Adolla Guyie who gave me unlimited advice,
instructions, and encouragement at every step of this project and gave me the necessary
materials, suggestions and comments. Secondly, I would like to express my thanks to all my
classmates especially Gelana Alemayehu who helped me not only in this project but throughout
my academic year in KUE. Last but certainly not least, I would like to express my sincere thanks
to all mathematics department staff and some of their students who provided valuable
information like reference books and personal notes for the project. I am indebted to all
individuals, friends and others for their support in the success of this project. I would like to say
thank you sincerely.
II | P a g e
Table of Contents
Declaration...................................................................................................................................................I
Acknowledgment.........................................................................................................................................II
List of graphs...............................................................................................................................................V
List of figures...............................................................................................................................................V
ABSTRACT...................................................................................................................................................VI
UNIT ONE.....................................................................................................................................................1
1. INTRODUCTION...................................................................................................................................1
1.1. DEFINITION..................................................................................................................................2
1.2. Statement of the problem...........................................................................................................4
1.3. Objective......................................................................................................................................4
1.3.1. General objective.................................................................................................................4
1.3.2. Specific objective.................................................................................................................4
1.4. SCOPE..........................................................................................................................................4
1.5. Delimitation of the project..........................................................................................................4
UNIT TWO....................................................................................................................................................5
2. Review Literature................................................................................................................................5
2.1. Introduction.................................................................................................................................5
2.2. Curve fitting.................................................................................................................................5
2.3. Interpolation................................................................................................................................6
2.4. Linear Interpolation.....................................................................................................................6
2.5. Quadratic Spline..........................................................................................................................6
2.6. Cubic Spline.................................................................................................................................7
2.7. Application of Cubic Spline Interpolation....................................................................................7
UNIT THREE.................................................................................................................................................8
3. ANALYSIS.............................................................................................................................................8
Issues with linear spline.........................................................................................................................11
3.2. Quadratic Spline Interpolation.......................................................................................................12
3.3. Cubic spline interpolation..............................................................................................................18
Natural cubic spline interpolation example.......................................................................................20
III | P a g e
Clamped cubic spline interpolation example.....................................................................................23
Another approach to using cubic spline....................................................................................................26
Curve Fitting with Splines......................................................................................................................37
Data interpretation................................................................................................................................39
Representing functions by approximating polynomials.........................................................................40
Unit four....................................................................................................................................................41
4. Conclusion.........................................................................................................................................41
References.................................................................................................................................................42
Appendices............................................................................................................................................43
Python codes.........................................................................................................................................43
Graph 1..............................................................................................................................................43
Graph 2..............................................................................................................................................43
graph 3...............................................................................................................................................43
Gauss elimination with partial pivoting.............................................................................................43
IV | P a g e
List of graphs
Graph 1: linear, quadratic and cubic interpolation......................................................................................3
Graph 2: linear interpolation........................................................................................................................8
Graph 3: cubic interpolation graph............................................................................................................18
Graph 4: clamped cubic spline Graph 5: comparison between
natural and clamped spline.......................................................................................................................25
Graph 6:function y =sin(x).........................................................................................................................37
Graph 7:six data points with a cubic spline function Graph 8: comparison of true value and
cubic spline................................................................................................................................................38
Graph 9: curve fitting illustrative example.................................................................................................38
Graph 10: the natural cubic interpolation of a solid line...........................................................................40
List of figures
Figure 1: a graph showing the difference between global and local interpolation......................................1
Let us see for 2 splines 3*n = 6 unknowns Figure 2: showing quadratic spline
p 1 x=a 1 x 2+ b 1 x +c 1..........................................................................................................................12
Figure 3: random data...............................................................................................................................39
Figure 4: polynomial graph 99 degree.......................................................................................................39
Figure 5: data interpretation with cubic spline..........................................................................................40
V|Page
ABSTRACT
Spline interpolation is a powerful mathematical tool with a wide range of applications in various
fields, including engineering, data analysis, and computer graphics. This project aims to provide
a comprehensive understanding of the different types of spline interpolation and their practical
applications.
The first part of the project will explore linear, quadratic, and cubic spline interpolation. Linear
spline interpolation is the simplest method, where the interpolating function is a piecewise linear
function. Quadratic spline interpolation uses a series of quadratic polynomials to connect the
given data points, providing a smoother curve than linear interpolation. The project will then
delve into the more sophisticated cubic spline interpolation, which uses third-degree polynomials
to connect the data points, resulting in a smooth, continuous, and differentiable curve.
The core of the project will focus on the cubic spline interpolation method. This approach offers
several advantages, including the ability to control the first and second derivatives of the
interpolating function at the data points, ensuring a smooth and continuous curve. The
mathematical formulation of the cubic spline interpolation will be presented, including the
derivation of the system of linear equations that must be solved to determine the coefficients of
the polynomial segments.
The project will also investigate the applications of spline interpolation in various domains. This
includes the use of spline interpolation in data fitting, function approximation, and numerical
integration. Additionally, the project will explore the implementation of spline interpolation
algorithms in software, such as MATLAB or Python, and demonstrate their performance on real-
world datasets.
Through this project, the undergraduate student will gain a deep understanding of the
fundamental concepts of spline interpolation, its mathematical properties, and its practical
applications. The focus on the cubic spline interpolation method will provide valuable insights
into the more advanced techniques used in modern numerical analysis and scientific computing.
VI | P a g e
UNIT ONE
1. INTRODUCTION
As an undergraduate mathematics student, I have come to appreciate the importance of
interpolation methods in a wide range of fields. Interpolation is a fundamental mathematical
concept that allows us to estimate the values of a function at points between known data points.
This technique is invaluable in situations where we have limited information about a function or
process, but need to make inferences or predictions about its behavior.
Broadly speaking, there are two main types of interpolation: global interpolation and local
interpolation. Global interpolation involves finding a single function that passes through all the
given data points, providing a continuous representation of the entire function. This is often
achieved using polynomial functions, such as Lagrange or spline interpolation. In contrast, local
interpolation techniques construct piecewise functions, each of which is valid only within a
specific interval of the data. Examples of local interpolation include linear and cubic spline
interpolation.
The choice of interpolation method depends on the characteristics of the data and the desired
properties of the interpolating function. Global interpolation methods are well-suited for smooth,
well-behaved functions, as they can capture the overall trend of the data. However, if the
function being interpolated has sharp changes or discontinuities, local interpolation techniques
may be more
1|Page
Figure 1: a graph showing the difference between global and local interpolation
1.1. DEFINITION
Spline interpolation is a technique used to construct a smooth, piecewise polynomial function
that passes through a set of given data points. The polynomial function is divided into multiple
segments, each of which is a low-degree polynomial (typically a cubic polynomial) that connects
two adjacent data points. These individual polynomial segments are referred to as "splines."
The advantage of using spline interpolation over other interpolation methods, such as linear or
polynomial interpolation, is its ability to provide a smooth and continuous function that closely
approximates the underlying data. Linear interpolation, for example, can result in a piecewise
linear function that may not capture the nuances of the data, while higher-order polynomial
interpolation can lead to unwanted oscillations, particularly when dealing with large datasets.
2|Page
Spline interpolation overcomes these limitations by using a series of lower-degree polynomials,
which results in a more flexible and accurate representation of the data. The continuity of the
first and second derivatives across the spline segments ensures that the resulting function is
smooth and has a continuous curvature, making it particularly useful in applications where the
smoothness of the interpolated function is crucial, such as in computer graphics, engineering, and
scientific modeling.
Suppose you have a set of data points representing the temperature measurements at various
locations along a coastline. You want to use interpolation to estimate the temperature at
intermediate points where measurements were not taken.
The blue dots represent the given data points, while the lines represent the interpolated functions.
As you can see, the linear interpolation (red line) provides a piecewise linear approximation,
which may not capture the subtle changes in temperature along the coastline. The polynomial
interpolation (green line) exhibits unwanted oscillations, which can be problematic when dealing
with noisy or irregular data.
In contrast, the spline interpolation (blue line) provides a smooth, continuous function that
closely follows the underlying data. The spline curve is composed of multiple cubic polynomial
segments that seamlessly connect the data points, ensuring a smooth transition between them.
The advantage of spline interpolation is that it can accurately represent the underlying function
3|Page
while maintaining a high degree of smoothness, making it a valuable tool in various scientific
and engineering applications where the continuity and curvature of the interpolated function are
crucial.
1.3. Objective
1.3.1. General objective
By using liner interpolation solve problems solve problems in hand and in python
1.4. SCOPE
The scope of this project starts from defining and looking at the theories of spline interpolation and
working on some problems to illustrate the use of spline interpolation in addition it will look at some of
the applications of spline interpolation in particular cubic spline interpolation in the application area of
curve fitting and data interpretation.
4|Page
UNIT TWO
2. Review Literature
2.1. Introduction
Spline interpolation is a form of interpolation where the interpolate is a special type of piecewise
polynomial called spline. Spline interpolation is often preferred over polynomial interpolation because
the interpolation error can be made small even when using low degree polynomials for the spline
(Hazewinkel, Michiel, 2001)
Orthodontic teeth movement is influenced by the characteristics of the applied force, including
its magnitude and direction and the physiological condition of the periodontal tissue of
individual patients. However, researches carry out on teeth treatments in clinics indicated no sign
of application of this mechanical theory. What really happens is that dentists compare the actual
teeth conformation and the perfect one to confer the braces. In this study, analysis of dental
arches conformation could be done through cubic spline method. (Rokiah Rozita Ahmad,Najah
Ghazali, 2012)
This paper aims to explore a new technique for structural damage identification using cubic
spline interpolation. The method is based on the interpolation of modal rotations measured with
shearography, making use of the analytical derivative of the spline to compute the modal
curvature, which is known to be very sensitive to damage. As a means of reducing noise and
measurement uncertainty propagation to a minimum, an expression for an optimal spatial
sampling is derived. Furthermore, a baseline-free damage factor, allied with an optimal
sampling, is also introduced. The proposed identification method is validated using experimental
data of a beam. Using a damage localization quality index, a comparison between the present
7|Page
method and one using finite deference is carried out, showing that the differentiation of spline
interpolation leads to better damage identifications. (L. Pedroso1 | A. Arco, 2021)
UNIT THREE
3. ANALYSIS
3.1. Linear Spline Interpolation
This often leads to “knots”/ sharp changes in our function which is unideal as we want smooth
and continuous functions.
How do go about finding p1(x) and the point along it?
We assume the function is linear then each segment is simply a straight-line equation.
Recall: the general equation of a straight line is y=mx+b
Then p1 ( x ) = y 1 +
( y 2− y 1
x 2−x 1 )( x−x 1 ) ; x 1 ≤ x ≤ x 2------------------ Equation 1
p2 ( x ) = y 2 +
( y 3− y 2
x 3−x 2 )( x−x 2 ) ; x2 ≤ x ≤ x3------------------Equation 2
X 1 6 7 9 12 20
Y 2 8 6 10 14 41 P2(x)
P1(x)
P4(x)
Using equation 1 P3(x)
p1 ( x ) = y 0 +
( y 2− y 1
x 2−x 1 )
( x−x 1 ) ;( x ¿¿ 1=1)≤ x ≤ (x¿ ¿2=6)¿¿
8|Page
¿ 1.2 x+0.8−−−−−−−−−−−[1]
p4 ( x ) = y 4 +
( y 5− y 4
x 5−x 4 )( x−x 3 ) ; (x ¿¿ 4=9)≤ x ≤(x ¿¿ 5=12)¿ ¿
4x
¿ −2−−−−−−−−−−−−−−¿[2]
3
For B substituting 2 and 5 in [1] because the domain D :1≤ x ≤ 6
The value of y at x=2 can be given y=1.2 ( 2 ) +0.8=3.2 and
The value of y at x=5 can be given y=1.2 ( 5 ) +0.8=6.8
4 ( 5) 14
The value of y at x=10 can be given y= −2=
3 3
Problem 1: - state whether the following piecewise polynomials are splines or not
{
X +1−1 ≤ x ≤ 0
f ( x )=¿ 2 x +1 0 ≤ x ≤1
4 – x1≤ x≤2
Solution: - x o=−1 , x 1=0, x 2=1, x 3=2then n=4
f 1 ( x) = x +1
f 2 (x) = 2 x+1
f 3 ( x) = 4−x
Then f 1 (x1 ) = 0+1 ¿1
f 2 ( x1 ) = 2(0)+1 ¿1
f 2 (x 2) = 2(1)+1 ¿3
f 3 ( x 2) = 4−1=¿ 3
9|Page
Therefore f 1 ( x 1 ) = f 2 (x1 ) and f 2 (x 2) = f 3 (x 2)
Its liner spline function
10 | P a g e
Problem 2
Obtain the piecewise liner interpolating polynomial for the function f (x)defined by the data
x 1 2 4 8
y 3 7 21 73
{
4 x −11 ≤ x ≤ 2
p ( x )= 7 x−7 2≤ x ≤ 4
13 x−31 4 ≤ x ≤ 8
3 ∈[ 2 , 4 ]
11 | P a g e
f ( 3 )=7 ( 3 )−7
f ( 3 ) = 21
7 ∈ [ 4 , 8] ,
f ( 7 )=13 ( 7 ) −31 f ( 7 )=60
2. Inflection points: With linear splines, any change in slope occurs at the knot points. This
means there will be sharp corners or inflection points at the knot locations, which may
not be desirable in some applications.
4. Sensitivity to knot placement: The quality of the linear spline approximation is highly
dependent on where the knot points are placed. Choosing an appropriate knot spacing is
important to balance accuracy and computational cost.
5. Limited flexibility: Compared to higher-order splines, linear splines have less flexibility
in shape and cannot capture more complex functional forms as effectively.
6. Potential oscillations: In some cases, linear splines can exhibit unwanted oscillatory
behavior, particularly near regions with abrupt changes in the underlying function.
12 | P a g e
3.2. Quadratic Spline Interpolation
quadratic spline interpolation method is a local interpolation method which uses the quadratic
polynomial to approximate the required data from the sub sets of the total data set. With global
interpolation method such as newton’s divided difference interpolation data points supplied to us
which can create very high order polynomials whereas spline interpolation can use only a sub set
of the total data.
2
pi ( x ) =ai x + bi x +c i
Let us see for 2 splines 3*n = 6 unknowns Figure 2: showing quadratic spline
2
p1 ( x ) =a1 x +b 1 x +c 1
. p2 ( x ) =a2 x 2+b 2 x +c 2
For the system to be smooth the interior data points must be equal
dp1 ( x 2) dp 2 ( x 2 )
=
dx dx
This must be true for every interior data point which will give us n−1 equations
13 | P a g e
2 n+n−1=3 n−1
3) Assumption
Commonly we assume f
''
( p1 ( x ) ) =0and this will be our final missing equation.
Illustrating example
a. find all relevant interpolating functions between the following data points using quadratic
spline interpolation.
b. Find outputs at x= 2,4 and 7.
X 1 3 5 8
Y 2 3 9 10 p3 ( x )
n-spline
Polynomial to find
. p1 ( x ) =a1 x2 +b 1 x +c 1
. p2 ( x ) =a2 x 2+b 2 x +c 2
. p3 ( x )=a3 x 2+ b3 x + c3
14 | P a g e
9 unknowns: a 1 , b1 , c 1 , a 2 , b2 , c 2 , a 3 , b3 , c 3
p1 ( x1 ) = y 1=2=a1 (1 )2 +b 1 ( 1 ) +c 1
2
p1 ( x2 ) = y 2=3=a1 ( 3 ) +b1 ( 3 ) +c 1
3=9 a1 +3 b1 +c 1−−−−−−−−[2]
p2 ( x 2) = y 2=3=a2 ( 3 )2 +b2 ( 3 ) +c 2
3=9 a2 +3 b2 +c 2−−−−−−−−[3]
2
p2 ( x3 ) = y 3=9=a 2 ( 5 ) +b 2 ( 5 ) + c2
9=25 a2 +5 b2 +c 2−−−−−−−−[4]
p3 ( x 3 )= y 3=9=a 3 ( 5 )2 +b 3 ( 5 )+ c3
9=25 a3 +5 b3 + c3 −−−−−−−−[5 ]
2
p3 ( x 4 )= y 4=10=a3 ( 8 ) +b 3 ( 8 )+ c 3
10=64 a3 +8 b 3 +c 3−−−−−−−−[6]
dp1 ( x 2) dp 2 ( x 2 )
Smoothness =
dx dx
d 2 d 2
(a1 x +b 1 x +c 1)= (a ¿ ¿2 x +b2 x+ c 2)¿
dx dx
2 a1 x2 +b 1=2 a2 x2 +b 2 x 2=3
dp2 ( x 3 ) dp3 ( x3 )
=
dx dx
15 | P a g e
d 2 d 2
(a ¿ ¿ 2 x +b 2 x +c 2)= (a3 x +b3 x +c 3)¿
dx dx
2 a2 x3 + b2=2 a3 x 3+ b3 x3 =5
10 a2 +b 2−10 a3−b3=0−−−−−−−−[8]
2
d
Assume: f
''
( p1 ( x ) ) =0 2
¿
dx
d d
(
dx dx
( ) d
a1 x 2+ b1 x +c 1 ) = ( 2 a 1 x +b1 ) =2 a1=0
dx
2 a1=0−−−−−−−−−−−−−−[9]
Now we have 9 equations and 9 unknows so we can solve this with gauss elimination solver with
partial pivoting on python. 2=a1 +b1 +c 1
3=9 a1 +3 b1 +c 1
3=9 a2 +3 b2 +c 2
9=25 a2 +5 b2 +c 2
9=25 a3 +5 b3 + c3
10=64 a3 +8 b 3 +c 3
0=2 a1
a2 = 1.25 b2 = -7 c2 = 12.75
2
p1 ( x ) =0 x +0.5 x +1.5 D :1≤ x ≤ 3
2
p2 ( x ) =1.25 x −7 x +12.75 D :3 ≤ x ≤5
16 | P a g e
2
p3 ( x )=−1.72 x +22.72 x−61.56 D :5 ≤ x ≤8
Problem 2: - state whether the following piecewise polynomials is 2nd degree spline function or
not
{
2
x +1 0≤ x ≤ 1
f ( x )=¿ 2
2 x 1 ≤ x ≤2
5 x – 2 2 ≤ x ≤3
'
f 1 (x) = x 2+ 1 f 1 ( x )=2 x
'
f 2( x ) = 2 x2 f 2 ( x )=4 x
'
f 3 (x) = 5 x – 2 f 2 ( x )=5
Then f 1 ( x 1 )=1+1=2
'
f 1 ( x 1 )=2
f 2 ( x 1 ) = 2(1)2=2 '
f 2 ( x 1 )=4
f 2 ( x 2 ) = 2(2)2 =8 '
f 2 ( x 2 )=4 ( 2 ) =8
f 3 ( x 2 ) = 5 ( 2 ) – 2=8 '
f 2 ( x 2 )=5
The polynomial is continuous but their derivative is not continuous than it is not 2nd degree spline
function
Problem 3: - state whether the following piecewise polynomials is 2nd degree spline function or
{
x 0≤ x≤1
not f ( x )=¿ 2
x −x+1 1 ≤ x ≤2
3 x – 3 2≤ x ≤ 3
17 | P a g e
'
f 1 ( x) = x f 1 ( x )=1
'
f 2 ( x ) = x 2−x +1 f 2 ( x )=2 x−1
'
f 3 ( x) = 3 x – 3 f 2 ( x )=3
'
f 1 ( x1 ) = 1 f 1 ( x 1 )=1
f 2 ( x1 ) = 1 '
f 2 ( x 1 )=1
'
f 3 ( x 2) = 3 f 2 ( x 2 )=3
But
} left (x right ) =¿
f1
} left (x right ) =¿
f2
} left (x right ) =¿
f3
The second derivation is not continuous and it not 3rd degree spline function
Problem 4 :- Approximation a function f ( x )=4 x on [-1,1] by liner spline method and find the
value of f ( 0.125 )
p4
p3
p2
18 | P a g e
p1
-1 -0.5 0 0.5 1
x -1 -0.5 0 0.5 1
y 0.25 0.5 1 2 4
{
x−(−1)
y 1= [ 0.5−0.25 ] +0.25=0.5 x+0.75 if x ∈ [ −1 ,−0.5 ]
−0.5−(−1)
x +0.5
y 2= [ 1−0.5 ] +0.5=x+ 1if x ∈ [ −0.5 , 0 ]
f ( x )= 0+0.5
x−0
y 3= [ 2−1 ] +1=2 x +1 if x ∈ [ 0 ,0.5 ]
0.5−0
x−0.5
y 4= [ 4−2 ] + 2=4 x if x ∈ [ 0.5 , 1 ]
1−0.5
Similar to linear and quadratic spline interpolation it breaks down the data range in to smaller
segments. However, we will now be going to fit a cubic polynomial to each section and this
ensures the continuity and smoothness at
the connection points which something we
were lucking in both linear and quadratic
splines.
19 | P a g e
p2 ( x )
p1 (x)
xa xb xc
Graph 3: cubic interpolation graph
{
f ( x )= p1 ( x ) x a ≤ x ≤ x b
p2 ( x ) x b ≤ x ≤ x c
In cubic spline interpolation p1 ( x ) ∧p 2 (x) are found through general 3rd order polynomial
20 | P a g e
steps in solving cubic spline interpolation
21 | P a g e
X 1 3 5 8
Y 2 3 9 10
3 2
p1 ( x ) =a1 x +b 1 x +c 1 x +d 1
3 2
p2 ( x ) =a2 x + b2 x +c 2 x +d 2
3 2
p3 ( x )=a3 x + b3 x +c 3 x+ d 3
We have 4 data pints thus we get 3 splines which implies 4*3 = 12 unknowns so we need 12
equations for the degree of freedom to be zero
p1 (x)
1) Evaluate at known points p2 (x )
3 2
(x 1 , y 1 ) 3 (x 2 ,2 y 2 )
p1 ( x1 ) = y 1=a 1 x + b1 x +c 1 x+ d 1 p1 ( x2 ) = y 2=a 1 x +b1 x + c1 x+ d 1
3 2 3 2
p1 (1 )=2=a1 ( 1 ) +b 1 ( 1 ) +c 1 ( 1 ) + d 1 ; p1 (3 )=3=a1 ( 3 ) + b1 ( 3 ) + c 1 ( 3 ) + d1
3 2 3 2
p2 ( x 2) = y 2=a 2 x +b2 x + c2 x+ d 2 ; p2 ( x 3 )= y 3=a2 x +b 2 x +c 2 x +d 2
3 2 3 2
p2 ( 3 )=3=a2 (3) +b 2(3) +c 2 ( 3 ) +d 2 ; p2 ( 5 )=9=a2 (5) + b2 (5) + c 2(5)+d 2
3 2 3 2
p3 ( x 3 )= y 3=a3 x +b 3 x +c 3 x +d 3 ; p 3 ( x 4 )= y 4=a 3 x +b3 x + c 3 x +d 3
3 2 3 2
p3 ( 5 )=9=a3 (5) +b 3 (5) + c3 ( 5 ) +d 3 ; p 3 ( 8 )=10=a3 (8) +b 3 (8) + c3 (8)+ d 3
' '
p1 ( x2 ) = p2 (x 2) '
P1 ( x ) =3 a1 x +2 b1 x+ c1
2
' 2
P2 ( x ) =3 a2 x +2 b2 x+ c 2
22 | P a g e
' '
p2 ( x3 ) = p3 (x 3)
' 2
P2 ( x ) =3 a2 x +2 b2 x+ c 2
' 2
P3 ( x )=3 a3 x +2 b3 x +c 3
'' ''
p1 ( x 2 )= p2 (x 2)
''
P1 ( x )=6 a1 x +2 b1
''
P2 ( x )=6 a2 x +2 b2
'' '
p2 ( x 3 )= p ' 3 (x3 ) ''
P2 ( x )=6 a2 x +2 b2
''
P3 ( x )=6 a3 x +2 b3
'' ''
assume the second derivatives at end points are zero Assume p1 ( x 1 )=0∧ p3 ( x 4 ) =0
''
P1 ( 1 )=6 a1 (1 )+2 b 1=6 a1 + s b1 =0−−−−−−−−−−(11)
''
P3 ( 8 )=6 a3 ( 8 ) +2 b3 =48 a 3+ 2b 3=0−−−−−−−−−(12)
Know we find all 12 of the equations we can find our 12 unknowns by using the system of
equation solver we use in for quadratic spline illustrative example*gauss elimination method
with partial pivoting* on python.
23 | P a g e
We find the values to be as follows
3 2
p1 ( x ) =0.1995 x + 0.5986 x +0.3004 x +2.0986 D :1≤ x ≤ 3
3 2
p2 ( x ) =−0.3728 x + 4.5526 x +−15.153 x +17.5526 D :3 ≤ x ≤5
3 2
p3 ( x )=0.11549 x +−2.7719 x +21.4692 x +−43.4853 D :5 ≤ x ≤8
By using the interpolating cubic function find the output at x=1.5 , x=4∧x=¿ 7
3 2
x=1. 5 ; p 1 ( 1.5 ) =0.1995 ( 1.5 ) +0.5986 ( 1.5 ) +0.300(1.5)+2.0986
=1.875663
p(x)
12
10
8
6
4
2
0
1 2.7 4.4 6.17.80000000000001
3 2
x=4 ; p2 ( 4 )=−0.3728 ( 4 ) +4.5526 ( 4 ) +−15.153(4)+17.5526
=5.923
x=7 ;
3 2
p3 ( 7 )=0.11549 ( 7 ) −2.7719 ( 7 ) +21.4692 ( 7 )−43.485 3
24 | P a g e
=10.58767
X 1 3 5 8
Y 2 3 9 10
3 2
p1 ( x ) =a1 x +b 1 x +c 1 x +d 1
3 2
p2 ( x ) =a2 x + b2 x +c 2 x +d 2
3 2
p3 ( x )=a3 x + b3 x +c 3 x+ d 3
We have 4 data pints thus we get 3 splines which implies 4*3 = 12 unknowns so we need 12
equations for the degree of freedom to be zero
3 2 3 2
p1 ( x1 ) = y 1=a 1 x + b1 x +c 1 x+ d 1 ; p1 ( x2 ) = y 2=a 1 x +b1 x + c1 x+ d 1
3 2 3 2
p1 (1 )=2=a1 ( 1 ) +b 1 ( 1 ) +c 1 ( 1 ) + d 1 ; p1 (3 )=3=a1 ( 3 ) + b1 ( 3 ) + c 1 ( 3 ) + d1
3 2 3 2
p2 ( x 2) = y 2=a 2 x +b2 x + c2 x+ d 2 ; p2 ( x 3 )= y 3=a2 x +b 2 x +c 2 x +d 2
3 2 3 2
p2 ( 3 )=3=a2 (3) +b 2(3) +c 2 ( 3 ) +d 2 ; p2 ( 5 )=9=a2 (5) + b2 (5) + c 2(5)+d 2
3 2 3 2
p3 ( x 3 )= y 3=a3 x +b 3 x +c 3 x +d 3 ; p 3 ( x 4 )= y 4=a 3 x +b3 x + c 3 x +d 3
3 2 3 2
p3 ( 5 )=9=a3 (5) +b 3 (5) + c3 ( 5 ) +d 3 ; p 3 ( 8 )=10=a3 (8) +b 3 (8) + c3 (8)+ d 3
25 | P a g e
9=125 a3 +25 b3 +5 c 3 +d 3−−−−( 5 ) ; 10=512 a3 +64 b3 +8 c 3 +d 3−−−−(6)
' '
p1 ( x2 ) = p2 (x 2) ' 2
P1 ( x ) =3 a1 x +2 b1 x+ c1
' 2
P2 ( x ) =3 a2 x +2 b2 x+ c 2
' '
p2 ( x3 ) = p3 (x 3) '
P2 ( x ) =3 a2 x +2 b2 x+ c 2
2
' 2
P3 ( x )=3 a3 x +2 b3 x +c 3
'' ''
p1 ( x 2 )= p2 (x 2) ''
P1 ( x )=6 a1 x +2 b1
''
P2 ( x )=6 a2 x +2 b2
'' '
p2 ( x 3 )= p ' 3 (x3 ) ''
P2 ( x )=6 a2 x +2 b2
''
P3 ( x )=6 a3 x +2 b3
' '
assume the second derivatives at end points are zero Assume p1 ( x1 ) =4∧ p3 ( x 4 ) =4
' 2
P1 (1 )=3 a1 ( 1 ) + 2b 1 ( 1 ) +c 2=3 a 1+ 2b 1+ c2 =4−−−−−−−−−−(11)
26 | P a g e
' 2
P3 ( 8 )=3 a 3 ( 8 ) + 2b 3 ( 8 )+ c 3=192 a3 +16 b3 + c3=0−−−−−−−−−(12)
Know we find all 12 of the equations we can find our 12 unknowns by using the system of
equation solver we use in for quadratic spline illustrative example*gauss elimination method
with partial pivoting* on python.
3 2
p1 ( x ) =1.0473 x −6.9864 x +14.831 x−6.982 D :1≤ x ≤ 3
3 2
p2 ( x ) =−0.7669 x + 9.3412 x −34.152 x+ 42.0912 D :3 ≤ x ≤5
3 2
p3 ( x )=0.564 x −10.623 x + 65.6697 x+124.278 D :5 ≤ x ≤8
By using the interpolating cubic function find the output at x=1.5 , x=4∧x=¿ 7
3 2
x=1. 5 ; p 1 ( 1.5 ) =1.0473(1. 5) ±6.9864 ( 1. 5 ) + 14.831(1.5)±6.982
= 3.07973
27 | P a g e
3 2
x=4 ; p2 ( 4 )=−0.7669 ( 4 ) +9.3412 ( 4 ) −34.152( 4)+ 42.0912
=5.8608
3 2
x=7 ; p3 ( 7 )=0.564(7) −10.623 (7 ) + 65.6697(7)+124.278
= 8.3349
f ( x i ) =f i
f i (x i)=f i+1 (x i )
' '
f i ( x i ) =f i +1 (xi )
'' ''
f i ( x i )=f i+1 (x i)
'' ''
f i ( x o )=f i ( x n )
Since f 1 ( x ) is cubic spline function in second derivative f ''1 (x 1)is a straight line. the street line
represented by first order Lagrange interpolating polynomial. since the line pass through the
point.
28 | P a g e
( x−x 0 ) ( x−x 1 ) ( x−x 2 ) … … … … … ( x−x i−1) … … ( x −xn )
l i= ……………………..( 1 )
( x i−x 0 ) ( xi −x1 ) ( x i−x 2 ) … … … … … ( x i−x i−1 ) … … ( x i−x n )
} left (x right ) = {left ({x-x} rsub {i} right )} over {left ({{x} rsub {i-1} -x} rsub {i} right )} {f} ^ { ( x−x i−1 ) } left ({x} rsub {i} right ¿
f ( x i−1 )+ f
( x i−x i−1 )
………………………..( 2 )
1
''
⟹ f i ( x )= [ ( x −x ) mi−1 + ( x−x i−1 ) mi ] …………………………………….( 3 )
hi i
[ ]
2 2
' 1 ( x i−x ) ( x −xi−1 )
f i ( x )= mi−1+ mi + ci
hi 2 2
[ ]
3 3
' 1 ( x i−x ) ( x −xi−1 )
f i ( x )= mi−1 + mi + ci x +d i
hi 6 6
1
f i ( x )=
6 hi
[ ( x i−x ) mi−1 + ( x−x i−1 ) mi ] + c i x +d i ……………………………….( 4 )
3 3
Consider
1
f i ( x )= [ ( x −x )3 mi−1 +( x−x i−1 )3 mi ] + ai ( xi −x )+ bi ( x−x i−1) …………( 5 )
6 hi i
29 | P a g e
Now replacing x by x i−1
1
f i−1= [ ( x −x )3 m +( x i−1−x i−1 )3 mi ] + ai ( x i−x i−1 ) +b i ( x i−1−x i−1 )
6 hi i i−1 i−1
1
f i−1=
6 hi
[ ( h i ) mi−1 ] +a i hi
3
2
hi
f i−1= mi−1 + ai h i
6
2
hi
a i hi =f i−1− m
6 i−1
[ ]
2
1 hi
a i= f i−1− mi−1 ………………………………..……..( 6 )
hi 6
[ ]
2
1 hi
Similarly b i= f i− mi ………………………………………..( 7 )
hi 6
[ ] [ ]
2 2
1 1 hi 1 hi
f i ( x )=
6 hi
[ ( x i−x ) mi−1 + ( x−x i−1 ) mi ] + f i −1− mi−1 + f i− mi …………( 8 )
3 3
hi 6 hi 6
Differentiate 8 w r t x
[ ] [ ]
2 2
1 1 hi 1 hi
'
f ( x )=
6 hi
[ −3 ( xi −x ) mi+1 +3 ( x−x i−1 ) mi ] − f i−1− mi−1 + f i− mi
2 3
hi 6 hi 6
[ ] [ ]
2 2
1 1 hi 1 hi
'
f ( x )=
6 hi
[ −3 ( xi −xi ) mi+1 +3 ( x i−x i−1 ) mi ] − f i−1 − mi−1 + f i− mi
2 3
hi 6 hi 6
[ ] [ ]
2 2
1 1 hi 1 hi
'
f ( x )=
6 hi
[ 3 h i mi ]− f i−1− mi−1 + f i− mi
2
hi 6 hi 6
' hi mi f i−1 hi f i hi
f ( x )= − + mi−1+ − m1
2 hi 6 hi 6
30 | P a g e
hi hi 1
mi + mi−1+ [ f i−f i−1 ] ……………………………( 9 )
'
f i ( x 1 )=
3 6 hi
[ ] [ ]
2 2
1 1 hi +1 1 h i+1
f i+1 ( x ) =
6 hi+1
[ ( x i +1−x ) mi +(x−x i) mi +1 ] +
3 3
hi+1
f i−
6
m i ( x i +1−x ) +
hi+1
f i+ 1−
6
mi+1 ( x−x i )
…………………………………………………( 10 )
Differentiate 10 w r t x
[ ] [ ]
2 2
1 1 hi+1 1 hi+1
'
f i+1 ( x ) =
6 hi+1
[−3 ( x i +1−x ) m i +3 ( x−x i ) mi +1 ]−
2 2
hi+ 1
f i−
6
mi +
hi+1
f i +1− m
6 i +1
[ ] [ ]
2 2
1 1 hi +1 1 h i+1
'
f i+1 ( x ) =
6 hi+1
[−3 ( x i +1−x i) mi +3 ( x i−x i ) mi+1 ]−
2 2
hi+1
f i−
6
mi +
hi+1
f i+ 1−
6 i+1
m
[ ] [ ]
2 2
1 1 hi+1 1 hi +1
f
'
i+1 (x )=
6 hi+1
[−3 ( x i +1−x i) mi ]−
2
hi +1
f i−
6
mi +
hi +1
f i+1−
6 i+1
m
−hi+1 mi hi +1 1
'
f i+1 ( x ) =
3
− m + [ f −f ] ……………………………………….( 11 )
6 i+1 hi+1 i+1 i
' '
i.e. f i ( x i ) =f i +1 ( x i )
hi hi 1 −hi+ 1 mi hi+1 1
mi + mi−1+ [ f i−f i−1 ]= − m + [ f −f ]………………………….( 12 )
3 6 hi 3 6 i+1 hi+ 1 i +1 i
m0 , m1 , m2 , m3 ,… … … ,mn
31 | P a g e
∴ Two additional conditions may be taken in one of the following forms
hi =hi+1 =h
Equation 8 becomes
[ ] [ ]
2 2
1 1 h 1 h
f i ( x )=
6h
[ ( x i−x ) mi−1 + ( x−x i−1 ) mi ]+ f i−1− mi−1 ( x i−x ) + f i − mi ( x− xi−1 )
3 3
h 6 h 6
…………………………………………………………….( 13 )
Together with 12
hi hi 1 −hi+ 1 mi hi+1 1
mi + mi−1+ [ f i−f i−1 ]= − mi+1 + [ f −f ]
3 6 hi 3 6 hi+ 1 i +1 i
h h mi h h mi +1 1
mi + + mi−1 + = [ f i +1−f i −f i + f i−1 ]
3 3 6 6 h
2h h h 1
⟹ m + m + m = [ f −f −f +f ]
3 i 6 i−1 6 i +1 h i+1 i i i−1
6
⟹ 4 h mi +h mi−1 +h mi+1= [ f −2 f i + f i−1 ]
h i+ 1
6
2 [ i+1
⟹ 4 mi +mi−1 +mi+1= f −2 f i +f i −1 ] ……………………………………( 14 )
h
32 | P a g e
( )( ) ( )
4 1 0 … 0 0 m1 d1
1 4 1 … 0 0 m2 d2
0 1 4 1 … 0 m3 d3
=
0 0 1 4 1 … . .
… … 0 1 4 1 . .
0 0 0 … 0 0 mi−1 di −1
x: 1 2 3 4
y: 1 2 5 11
4 m1+ m2=12
m1 +4 m2=18
f ( x )=¿
11
y ( 1.5 )=f ( 1.5 )=
8
33 | P a g e
' 14
y (3 )= from both the spline interval [2,3] and [3,4] as they should be
3
x -1 -0.5 0 0.5 1
Solution
{
φ1 ( x ) if x ∈[−1 ,−0.5 ]
f ( x ) φ 2 ( x ) if x ∈[−0.5 , 0]
φ 3 ( x ) if x ∈[0 , 0.5]
φ 4 ( x ) if x ∈[0.5 , 1]
f (x)=¿ ¿ ¿
if k=1
(−0.5−x )3
( )( )( )
3
(x+ 1) 0.25 −0.5− x 0.25 x +1
f 1 ( x) = mo + m1 + 0.37−mo . + 0.6−m1 .
3 3 6 0.5 6 0.5
= m1
(x +1)
3
+ 0.37(−0.5−x
0.5 )(
+ 0.6−
0.25
6
m1
x+ 1
0.5 )
0.5 2 0.5 1
ii, m + (−0.5 ) m1 + m= ¿
6 o 3 6 2 0.5
= 0.08m2=−1.88−0.3 m1 m2=−23.5−3.75 m1
(−0.5−0 ) ( 0+1 )
iii, m2=φ ”(0) = mo +m1 =m2=2m1
0.5 0.5
34 | P a g e
3
−4 (x+ 1) (−0.5−x) x+1
f i (x) = +0.37 +¿)
3 0.5 0.5
K=2
( )
(0−x ) m (x +0.5) + 0.6−m 0.25 ( 0−x ) (1−m 0.25 ) x +0.5
3
f 2 ( x ) = m1 + 2 1 2
3 3 6 0.5 6 0.5
0.5 2 0.5 1
ii, m 1 + ( 0.5 ) m 2+ m 3= ( 1.65−2 ( 1 )+ 0.6 )
6 5 6 0.5
(0.05) (0.5+0.5)
iii, m3 = f (0.5) =m1 +m2
0.5 0.5
If k=3
f 3 (x)= {m} rsub {2} {{(0.5-x)} ^ {3}} over {3} + {m} rsub {3} {{(x-0)} ^ {3}} over {3} + left (1- {m} rsub
0.5 2 0.5 1
ii, m 2 + 0.05m2+ m4 + ¿)
6 5 6 0.5
= 0.083m4 = 0.84-0.09-0.3m3
( 0.5−1 ) ( 1+0.5 )
iii, m4 = f (1) = m2 + m3
0.5 0.5
35 | P a g e
m 3 = 1.54
If k= 4
( ) ( )
3 3
(1−x) (x−0.5) 0.25 1−x 0.25 x−0.5
f 4 ( x )=¿ m3 + m4 + 1.65−m 3 2.72−m4
3 3 6 0.5 6 0.5
= 1.54
( x−x )3
3 (
1.65−1.54
( 0.25 )
6 ) 1−x
0.5
( 2.72 )
( x−0.5 )
0.5
x 0 1 2 3
f (x) 1 2 33 244
m0=0 m3=0
Solution
We have
6
2 [ i ∓1
mi−1+ 4 mi +mi+1= f −2 f i+ f i−1 ] for i=1 , 2
h
m1 +4 m2 +m3=6 [ f 3−2 f 2+ f 1 ]
m1=−24 , m2=276
[ ] [ ]
2 2
1 1 h 1 h
f 0 ( x )=
6h
[ ( x i−x ) mi−1 + ( x−x i−1 ) mi ] + f i−1 mi−1 ( x 1−x )+ f i− mi ( x−x i−1)
3 3
h 6 h 6
36 | P a g e
For [ 0 , 1 ] and i=1
f 1 ( x )=
1
6
[ ( [
x 1−x ) m0 + ( x −x0 ) m1 ] + ( x 1−x ) f 0−
3 3 m0
6 ]
+ ( x−x 0 ) f 1− [
m1
6 ]
¿
1
6
[ 0
[ ] 1
( 1−x )3 (0)+ ( x −0 )3 (−24) ]+ (1−x ) 1− + ( x−0 ) 2− (−24 )
6 6 [ ]
1 3
¿
6
[ x (−24 )]+1−x+ x( 2+ 4)
3
¿−4 x +1−x +6 x
3
¿−4 x +5 x+ 1
at [ 1 ,2 ] and i=2
f 2 ( x )=
1
6
[ ( [
x 2−x ) m1 + ( x−x 1 ) m2 ] + ( x 2−x ) f 1 −
3 3 m1
6 ]
+ ( x−x 1 ) f 2−[m2
6 ]
f 2 ( x )=
1
6
[ [ 1
6 ] 1
( 2−x )3 (−24 ) + ( x−1 )3 ( 276 ) ] + ( 2−x ) 2− (−24 ) + ( x−1 ) 33− 276
6 [ ]
1
¿
6
[ ( 8−12 x+ 6 x2 −x3 ) (−24 ) + x 3−3 x 2+3 x−1+(276)] + ( 2−x ) ( 2+4 ) +(x −1) [ 33−46 ]
1
¿ [−192+288 x−144 x 2 +24 x 3 +276 x 3−828 x 2 +12−6 x−13 x +13 ]
6
3 2
f 2 ( x )=50 x −166 x +167 x−53
at [ 2 ,3 ] for i=3
f 3 ( x )=
1
6
[ ( [
x 3−x ) m2+ ( x −x2 ) m3 ] + ( x 3−x ) f 2−
3 3 m2
6 ]
+ ( x−x 2 ) f 2−
6[
m3
]
¿
1
6 [
[ ( 3−x )3 276+ ( x−2 )3 (0)] +( 3−x ) 33− 276
6 ]
+ ( x−2 ) 244−
0
6 [ ]
1
¿
6
[ ( 27−27 x +9 x 2−x 3 ) 276 ]−39+13 x +244 x −488
3 2
f 3 ( x )=−46 x + 414 x −985 x +715
37 | P a g e
An estimate 2.5 is
3 2
f 3 ( 2.5 )=−46 (2.5) +414 (2.5) −985 ( 2.5 ) +715
=121.25
f ( 2.5 )=121.25
x 0 1 2
f (x) 1 2 3
Solution
We have
6
2 [ i ∓1
mi−1+ 4 mi +mi+1= f −2 f i+ f i−1 ] for i=1
h
4m1=6 (30)
m1=45
We have
[ ] [ ]
2 2
1 1 h 1 h
f 0 ( x )=
6h
[ ( x i−x ) mi−1 + ( x−x i−1 ) mi ] + f i−1− mi−1 ( x 1−x ) + f i − mi ( x −xi−1 )
3 3
h 6 h 6
38 | P a g e
f 1 ( x )=
1
6
[ ( [
x 1−x ) m0 + ( x −x0 ) m1 ] + ( x 1−x ) f 0−
3 3 m0
6 ] [
+ ( x−x 0 ) f 1−
m1
6 ]
f 1 ( x )=
1
6
[ [ ]0
( 1−x )3 (0)+ ( x−0 )3 45 ]+ ( 1−x ) 1− + ( x−0 ) 2−
6
45
6 [ ]
f 1 ( x )=
1 3
6
[ x (45) ] + ( 1−x ) + x
6( )
−33
45 3 33
f 1 ( x )= x +1−x− x
6 6
1
¿ [ 45 x 3 −39 x +6 ]
6
For [ 1 ,2 ] i=2
f 2 ( x )=
1
6
[ ( [
x 2−x ) m1 + ( x−x 1 ) m2 ] + ( x 2−x ) f 1 −
3 3 m1
6 ] [
+ ( x−x 1 ) f 2−
m2
6 ]
f 2 ( x )=
1
6
[ [
( 2−x )3 45+ ( x−1 )3 (0) ] + ( 2−x ) 2−
45
6 ]
+ ( x−1 ) 33−
[
0
6 ]
¿
1
6
[ ( 2−x )3 45 ] +( )
−33
6
( 2−x )+33 ( x−1 )
15 66 33
¿ ( 2−x )3− + x +33 x−33
2 6 6
15 11
f 2 ( x )= ( 2−x )3−11+ x +33 x−33
2 2
15 77
f 2 ( x )= ( 2−x )3+ x−44
2 2
At x=1.5
15 77
f 2 ( 1.5 ) = ( 2−1.5 )3 + (1.5)−44
2 2
15 77
f 2 ( 1.5 ) = ( 0.5 )3 + (1.5)−44
2 2
39 | P a g e
f 2 ( 1.5 ) =0.9375+57.75−44
f 2 ( 1.5 ) =14.6875
This next figure was generated by connecting six data points along the above line with a cubic
spline function.
Graph 7:six data points with a cubic spline function Graph 8: comparison of true value and cubic spline
By superimposing graph 6 on graph 7, we can see the degree to which the cubic curve imitates
the original function y = sin(x). Clearly, the cubic curve closely imitates the sine curve. It has no
40 | P a g e
extreme behavior between data points, and it effectively correlates the points. This characteristic
also works with more erratic functions. Take for instance the function below.
While the fit is not perfect, it does closely approximate the function without a great degree of
divergence.
Data interpretation
The splines other strength lies in its ability to correlate data which doesn’t follow any specific
pattern without a single polynomial’s extreme behavior. Take, for instance, the 100 random data
points below
Clearly there is no relation between these data points. A spline, however, can interpolate all 100
points without the drastic behavior that the necessary 99th degree polynomial would exhibit.
41 | P a g e
Figure 4: polynomial graph 99 degree
Note that, while the spline is not exactly pleasing to the eye, its range stays from 0 to 1.2; a much
more reasonable range than an approximating polynomial. Also, it is not much of a task to
generate an approximating spline which generally correlates the data while being much more
well behaved.
The above figure demonstrates the general trends in the data (of which there are none) without
necessarily connecting all data points. Its curvature is much less severe than that of fig 4.
π π 3π 5π 3π
( , 1.1463),( , 0.4053),( , 0.1274),(π , 0) ,( ,−0.0459) ,( ,−0.0450). With natural
4 2 4 4 2
cubic spline, the interpolating function is shown as a solid line in Fig. 6 below. The exact values
42 | P a g e
of the polynomial function f (x) (red markers) are also shown in Fig. Comparing the results, we
can see that the cubic-spline interpolating function approximates the exact function with a good
accuracy.
43 | P a g e
Unit four
4. Conclusion
From spline interpolation methods three interpolation method are compared namely, linear spline,
quadratic and cubic spline I have presented an overview of the methods of interpolation and especially
the cubic spline interpolation, which is widely used in numerous real-world applications. The study
presents the definition and related theory of linear, quadratic and cubic spline interpolation and
properties of different types of cubic splines, including a natural spline, a clamped spline. I’ve also
analyzed some general applications of cubic spline interpolation such as curve fitting, data interpretation
and Representing functions by approximating polynomials. In conclusion of this study, I can say that
cubic spline is by far the best interpolating method especially in application of curve fitting.
44 | P a g e
References
Hazewinkel, Michiel. (2001). Spline interpolatio. Springer,ISBN 978-1-55608-010-4:
Encyclopedia of Mathematics.
L. Pedroso1 | A. Arco. (2021, Aug 18). Application of cubic spline interpolation with optimal
spatial sampling for damage identification.
Rokiah Rozita Ahmad,Najah Ghazali. (2012). Application of Cubic Spline in the. Journal of
Mathematics and Statistics 8 (1): 144-149, 2012.
Kruger, C. J. C. (n.d): Constrained cubic spline interpolation for chemical engineering application
Hazewinkel, Michiel, ed. (2001): "Spline interpolation", Encyclopedia of Mathematics, Springer,ISBN 978-
1-55608-010-4
Henrici, P. (1982): Essential of numerical analysis, New York. John Wiley & Sons.
McKinley, S., Levine, M., Cubic Spline Interpolation, Math 45: Linear Algebra,
[Link]
Akima, H., 1969, A Method of Smooth Curve Fitting, ESSA Tech. Rep. ERL 101-ITS 73 (Washington,D.C.:
U.S. Government Printing Office)
Jianhua Z. Huang and Charles J. Stone, Extended Linear Modeling with Splines, 1999, 1-20 Ward Cheney,
David Kincaid Numerical Mathematics and Computing, seventh edition, 250-260
Kenneth H. Carpenter, An introduction to interpolation and splines, EECE KSU, November 22, 1999
revised November 20, 2001, April 24, 2002, April 14, 2004, 1-8
45 | P a g e
7. y_linear = interp1d(x, y)
46 | P a g e
10. m = n - 1
11. i = 0
12. x = [Link](n)
13. new_line = "\n" 37. variable_matrix = [Link]([[1,1,1,0,0,0,0,0,0],
14. augmented_matrix = np. concatenate((a_matrix, [0,0,0,9,0,0,0,0,0],
b_matrix), axis=1,dtype=float) [9,3,1,0,0,0,0,0,0],
15. print(f"the initial augmented matrix is: [0,0,0,25,5,1,0,0,0],
{new_line}{augmented_matrix}")
[0,0,0,0,0,0,25,5,1],
16. print("solving for the upper-triangular matrix:")
[0,0,0,0,0,0,64,8,1],
17. while i < n :
[6,1,0,-6,-1,0,0,0,0],
18. for p in range(i+1, n):
[0,0,0,10,1,0,-10,-1,0],
19. if abs(augmented_matrix[i,i]) <
[2,0,0,0,0,0,0,0,0]])
abs(augmented_matrix[p,i]):
20. augmented_matrix[[p,i]]=augmented_matrix[[i,p]] 38. constant_matrix = [Link]([[2],
47 | P a g e