Spline Iterpolation: Problem Formulation
Spline Iterpolation: Problem Formulation
Problem formulation
Let y = f ( x ) be a function defined in the interval [a, b] and a known table for the
values yi = f ( xi ) of the function in the points (nodes) a ≤ x0 < x1 < x2 < ... < xn ≤ b .
Generally nodes are unequally distanced and we will mark the steps between them with
hk = xk − xk −1 . Let the table be the following type:
xi x0 x1 ... xi ... xn
yi y0 y1 ... yi ... yn
1. Linear spline
Here k = 1 i.e. in every sub-interval [ xi −1 , xi ] , i = 1, n , the spline S1 ( f , x) is a first
degree polynomial (segment) which according to interpolation rule (2) connects points
( xi −1, yi −1 ) and ( xi , yi ) . Since between two points can exist only one segment, the linear
spline is only one. When we interpolate the table for every interval we get the formulas
given below which are used to calculate the coefficients of the linear spline using an
output data table. The graphic of the spline is a broken line.
General formula of a linear spline Spline coefficient
⎧ f1 = a1 + b1 ( x − x0 ) , x ∈ [ x0 , x1 ]
⎪ . .. ai = yi −1 ,
⎪⎪
S1 ( f , x) = ⎨ f i = ai + bi ( x − xi −1 ) , x ∈ [ xi −1 , xi ] y − yi −1
⎪ . .. bi = i , i = 1, n
hi
⎪
⎪⎩ f n = a n + bn ( x − xn −1 ) , x ∈ [ xn −1 , xn ]
Let it be so that we have calculated the coefficients of the linear spline using the formulas
above and x′ is a random point from [a, b] . To find the approximated value of the
function y = f ( x) , (i.e. y ( x′) ) we first determine in which sub-interval [ xi −1 , xi ] is located
x′ , after which we substitute x = x′ in the respective row of S1 ( f , x) .
2. Quadratic spline
When k = 2 according to property (1) the sought spline is a second degree
polynomial (part of a parabola) in every sub-interval [ xi −1 , xi ] and its coefficients are 3n in
number. For their definition we use interpolation property (2), from which we get 2n
equations and property (3) for the continuity of the first derivative, which results in n-1
more equations for all intermediate internal points x1, x2 ,..., xn −1 . One condition remains
unfulfilled, i.e. the quadratic spline isn’t the only one and can be determined by giving an
additional condition. The formulas for calculation of coefficients for S2 ( x) are given in the
table below where for definiteness the unfulfilled condition is given in the left side of the
interval with b1 = γ1 . If b1 = γ1 = 0 the spline is called natural. The procedure for the
calculation of its coefficients is recurrent.
Construct the stated spline and with its help find the approximate values of the
function in points: z1 = 4 and z 2 = 5 :
a) linear spline
b) natural quadratic spline
c) natural cubic spline
Solution:
We calculate the steps: h1 = 4,5 - 3 = 1,5; h2 = 7 - 4,5 = 2,5; h3 = 9 – 7 = 2.
a) Using the formulas for S1 we calculate consecutively coefficients ai , bi :
y − y 0 1 − 2,5
when i = 1 interval [3,0; 4,5]: a1 = y 0 = 2,5 , b1 = 1 = = −1 ;
h1 1,5
y − y1 2,5 − 1
when i = 2 interval [4,5; 7]: a 2 = y1 = 1 , b2 = 2 = = 0,6 ;
h2 2,5
y − y 2 0,5 − 2,5
when i = 3 interval [7; 9]: a3 = y 2 = 2,5 , b3 = 3 = = −1 .
h3 2
To calculate the approximate value of the function in point z1 = 4 with the help of
the spline we determine that it is located in the first interval and will approximate using
the formula for f1 . Then
f (4) ≈ f1 (4) = a1 + b1 ( z1 − x0 ) = 2,5 + (−1)(4 − 3) = 1,5 .
b) In the case of a natural quadratic spline S 2 the calculations are carried out using
recurrent formulas from the respective table. For ai , bi , ci when i = 1, 2, 3 and γ1 = 0 :
i ai bi ci Quadratic spline S 2 ( f , x) from example 1b)
2 when
1 2,5 0,0 -0,6667 f1 = 2,5 − 0,6667 ( x − 3) x ∈ [3; 4,5]
when
2 1,0 -2,0 1,0400 f 2 = 1 − 2 ( x − 4,5) + 1,04 ( x − 4,5) 2 x ∈ [ 4,5; 7]
3 2,5 3,2 -2,1000 f 3 = 2,5 + 3,2 ( x − 7) − 2,1 ( x − 7) 2 when x ∈ [7; 9]
4 - -5,2 - -
c) Now let us also construct the cubic spline S 3 . For this we form the linear system
for the auxiliary coefficients li where i = 1, 2, 3, 4 and γ1 = γ 2 = 0 :
l1 =0
⎛ y − y1 y1 − y0 ⎞
h1l1 + 2(h1 + h2 )l 2 + h2 l3 = 6 ⎜⎜ 2 − ⎟
⎝ h2 h1 ⎟⎠
.
⎛ y3 − y 2 y 2 − y1 ⎞
h2 l 2 + 2(h2 + h3 )l3 + h3l 4 = 6 ⎜⎜ − ⎟
⎝ h3 h2 ⎟⎠
l4 =0
Fig. 1. The graphics of the resulting splines for problem 1a), 1b) and 1c).
By substituting the concrete data we get the following system:
8 l 2 + 2,5 l3 = 9,6
.
2,5 l 2 + 9 l3 = −9,6
After substituting in the formulas we get the following table for the coefficients:
i li ai bi ci di
1 0,0000 2,5 -1,4198 0,0000 0,1866
2 1,6791 1,0 -0,1605 0,8395 -0,2141
3 -1,5331 2,5 0,0221 -0,7666 0,1278
4 0,0000 - - 0,0000 -
With the help of these coefficients the sought cubic spline is written down in the
following way:
Table for cubic spline S 3 ( f , x) from example 1c)
f1 = 2,5 − 1, 4198( x − 3) + 0,1866 ( x − 3)3 when x ∈ [3; 4,5]
f 2 = 1 − 0,1605 ( x − 4,5) + 0,8395 ( x − 4,5) 2 − 0,2141( x − 4,5) 3 when x ∈ [4,5; 7]
f 3 = 2,5 + 0,0221 ( x − 7) − 0,7666 ( x − 7) 2 + 0,1278 ( x − 7) 3 when x ∈ [7; 9]
depending on the interval in which the point is located. For the first point we have
f ( 4) ≈ f1 (4) = a1 + b1 ( z1 − x0 ) + c1 ( z1 − x0 ) 2 + d1 ( z1 − x0 ) 3 =