0% found this document useful (0 votes)
173 views7 pages

Spline Iterpolation: Problem Formulation

This document discusses different types of spline interpolation used to approximate values of a function from a known table of x and y values. It describes: 1) Linear spline interpolation, which connects points with straight line segments between known x and y values. 2) Quadratic spline interpolation, which uses parabolic curves between points and requires continuity of the first derivative. Additional conditions are needed to define the spline. 3) Cubic spline interpolation, which uses cubic polynomials between points and requires continuity of the first and second derivatives. Two additional conditions are needed to uniquely define the cubic spline. Formulas for calculating the coefficients of each spline type are provided. An example calculates linear, quadratic, and cubic spline

Uploaded by

segorin2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views7 pages

Spline Iterpolation: Problem Formulation

This document discusses different types of spline interpolation used to approximate values of a function from a known table of x and y values. It describes: 1) Linear spline interpolation, which connects points with straight line segments between known x and y values. 2) Quadratic spline interpolation, which uses parabolic curves between points and requires continuity of the first derivative. Additional conditions are needed to define the spline. 3) Cubic spline interpolation, which uses cubic polynomials between points and requires continuity of the first and second derivatives. Two additional conditions are needed to uniquely define the cubic spline. Formulas for calculating the coefficients of each spline type are provided. An example calculates linear, quadratic, and cubic spline

Uploaded by

segorin2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Spline iterpolation

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

The interpolation spline S k ( f , x) of row k is a function with the following


properties:

(1) S k ( f , x) is a polynomial f i (x) with an exponent k in every sub-interval [ xi −1 , xi ] ,


i = 1, n .

(2) S k ( f , x) interpolates the function, i.e. S k ( f , xi ) = yi , i = 0, n ,


(3) S k ( f , x) and its derivatives up to row (k-1) are continuous throughout [a, b] .
When splines also satisfy other additional properties they are found in one way only.
Most frequently used are splines from row k = 1, 2 and 3 which are respectively called
linear, quadratic and cubic spline.

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.

General formula of a quadratic spline Spline coefficient


ai = yi −1,
⎧ f1 = a1 + b1 ( x − x0 ) + c1 ( x − x0 ) 2 , x ∈ [ x0 , x1 ]
⎪ b1 = γ1 ,
⎪... y −y

S 2 = ⎨ f i = ai + bi ( x − xi −1 ) + ci ( x − xi −1 ) 2 , x ∈ [ xi −1, xi ] bi +1 = −bi + 2 i i −1 ,
⎪ hi
⎪... b −b
⎪⎩ f n = an + bn ( x − xn −1 ) + cn ( x − xn −1 ) 2 , x ∈ [ xn −1, xn ] ci = i +1 i , i = 1, n
2hi
3. Cubic spline

The third degree spline is analogically constructed and is defined by finding 4n


coefficients under conditions (1)-(3). Since except interpolation property (2) here it is
required that S3' ( x) and S3'' ( x) are continuous and so 4n-2 conditions are formed and two
conditions remain unfulfilled. Consequently the cubic spline is the only one when two
additional conditions are set. In the table below they are marked with γ1 and γ 2 . To be

more exact we are considering the conditions: S3'' ( a ) = 2c1 = l1 = γ 1 and

S3'' (b) = 2cn + 6d n hn = ln +1 = γ 2 .

If γ1 = γ 2 = 0 the spline is called natural cubic spline.


We will note that the representations of splines given here aren’t the only ones.
Except them there can be a number of other types of additional conditions, for example,
S3' (a ) = γ 1 and S3' (b) = γ 2 as well as different combinations of the conditions above,

periodical conditions etc.

General formula of a cubic spline


⎧ f1 = a1 + b1 ( x − x0 ) + c1 ( x − x0 ) 2 + d1 ( x − x0 ) 3 , x ∈ [ x0 , x1 ]

⎪ .. .

S3 = ⎨ f i = ai + bi ( x − xi −1 ) + ci ( x − xi −1 ) 2 + d i ( x − xi −1 ) 3 , x ∈ [ xi −1 , xi ]

⎪ .. .
⎪⎩ f n = a n + bn ( x − xn −1 ) + cn ( x − xn −1 ) 2 + d n ( x − xn −1 ) 3 , x ∈ [ xn −1 , xn ]
Cubic spline coefficients
y − yi −1 hi
ai = yi −1 , bi = i − (li +1 + 2li ), i = 1, n
hi 6
l l −l
ci = i , d i = i +1 i , i = 1, n − 1
2 6 hi
Here the auxiliary coefficients li are solutions to the following three
diagonal system of linear algebraic equations with a predominating main
diagonal:
l1 = γ1
⎛y −y y −y ⎞
h1l1 +2(h1 + h2 )l2 + h2l3 =6 ⎜ 2 1− 1 0⎟
⎝ h2 h1 ⎠
...
⎛ y − yi −1 yi −1 − yi − 2 ⎞
hi −1li −1 +2(hi −1 + hi )li + hi li +1 =6 ⎜ i − ⎟
⎝ hi hi −1 ⎠
...
ln +1 = γ 2

Cubic spline coefficients in case of equally distanced nodes


h = xi − xi −1 , i = 1, n
y − yi −1 h
ai = yi −1 , bi = i − (li +1 + 2li ), i = 1, n
h 6
l l −l
ci = i , d i = i +1 i , i = 1, n − 1
2 6h

Auxiliary coefficients li are found from the system:


l1 = γ1
y − 2 y1 + y2
l1 +4l2 +l3 =6 0
h2
.....
y − 2 yi −1 + yi − 2
li −1 +4li +li +1 =6 i
h2
.....
ln +1 = γ 2
Example 1. The following table of values for function y = f (x) is given:
xi 3,0 4,5 7,0 9,0
yi 2,5 1,0 2,5 0,5

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

We enter the coefficients and get the following table:


i ai bi Linear spline S1 ( f , x) from example 1a)
1 2,5 -1,0 f1 = 2,5 − ( x − 3) when x ∈ [3; 4,5]
2 1,0 0,6 f 2 = 1 + 0,6 ( x − 4,5) when x ∈ [4,5; 7]
3 2,5 -1,0 f 3 = 2,5 − ( x − 7) when x ∈ [7; 9]

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 .

Analogically f (5) ≈ f 2 (5) = a2 + b2 ( z 2 − x1 ) = 1 + 0,6 (5 − 4,5) = 1,3 .


The graphic of the spline is shown in fig. 1 – S1 .
It is easy to ascertain that the spline is correctly determined. In the case of a linear
spline to do this we need only to check if it goes through points yi , i = 1,2,3,4 and that it is
continuous. Indeed S1 (3) = f1 (3) = 2,5 , S1 (4,5) = f 2 (4,5) = 1 and S1 (7) = f 2 (7) = 2,5 , also:
f1 (4,5) = 2,5 + (−1).(4,5 − 3) = 2,5 − 1,5 = 1 = f 2 (4,5) , f 2 (7) = 1 + (0,6).(2,5) = 1 + 1,5 = 2,5 = f 3 (7) and

f 3 (9) = 2,5 + (−1).(9 − 7) = 2,5 − 2 = 0,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 - -

The approximation of the function in the point z1 = 4 is found from

f ( 4) ≈ f1 = a1 + b1 ( z1 − x0 ) + c1 ( z1 − x0 ) 2 = 2,5 − 0,6667 ( 4 − 3) 2 = 1,8333 .

Analogically for the other point z 2 = 5 we get

f (5) ≈ f 2 = a 2 + b2 ( z 2 − x1 ) + c2 ( z 2 − x1 ) 2 = 1 − 2 (5 − 4,5) + 1,04 (5 − 4,5) 2 = 0,26 .

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

Solving this system for the auxiliary coefficients we find that:


l1 = 0, l 2 = 1,6791, l3 = −1,5331, l 4 = 0 .

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]

As in the previous cases in order to get approximated values in points z1 = 4 and


z 2 = 5 with the help of the cubic spline we make substitutions in the general formulas

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 =

2,5 − 1,4198.(4 − 3) + 0.(4 − 3) 2 + 0,1866.33 = 1,2668 .

For the second point -


f (5) ≈ f 2 (5) = a2 + b2 ( z 2 − x1 ) + c2 ( z 2 − x1 ) 2 + d 2 ( z 2 − x1 ) 3 =

1 − 0,1605.(5 − 4,5) + 0,8395.(5 − 4,5) 2 − 0,2141.(5 − 4,5) 3 = 1,1029 .

Author: Snezhana Gocheva-Ilieva, [email protected]

You might also like