Docsity

Cubic Spline Interpolation: Constructing a Cubic Polynomial for Function Approximation, Lecture notes of Computer science

Toggle sidebar
bg1
Interpolation using Cubic Spline
Given N+ 1 data points in the interval [a,b],
x t0t1· · · tN
y y0y1· · · yN
t0t1t2tN−2 tN−1 tN
S0(x)
S1(x)
SN−2(x)
SN−1(x)
S
(x)
x
Cubic Spline
we want to construct a cubic spline S(x) to interpolate the table presumable of a function f(x).
We assume that the points are ordered so that
a=t0< t1<· · · < tN=b.
S(x) is given by a different cubic polynomial in each interval [t0, t1], [t1, t2], · · · , [tN−1, tN]. Let
S(x) be given by Si(x) if x∈[ti, ti+1]. Each cubic polynomial is defined by 4 coefficients and so
we have a total of 4Nparameters. These are determined by the following conditions:
1. S(x) must interpolate the data points and so in each subinterval i= 0,· · · , N −1, we must
have Si(ti) = yiand Si(ti+1) = yi+1.
2. S0(x) must be continuous at each of the internal knots. Therefore for i= 1,2,· · · , N −1
we must have S0
i−1(ti) = S0
i(ti).
3. S00(x) must be continuous at each of the internal knots. Therefore for i= 1,2,· · · , N −1
we must have S00
i−1(ti) = S00
i(ti).
4. A choice of one of the following 2 conditions at the 2 end points aand b:
(a) The natural spline: S0(a) = 0 = S0
N−1(b),
(b) The clamped cubic spline: S0
0(a) = f0(a) and S0
N−1(b) = f0(b).
The clamped cubic spline gives more accurate approximation to the function f(x), but requires
knowledge of the derivative at the endpoints. Condition 1 gives 2Nrelations. Conditions 2, 3
and 4 each gives N−1 relations. Together with the 2 relations from condition 4, we have a
1
pf3
pf4

Partial preview of the text

Download Cubic Spline Interpolation: Constructing a Cubic Polynomial for Function Approximation and more Lecture notes Computer science in PDF only on Docsity!

Interpolation using Cubic Spline

Given N + 1 data points in the interval [a, b],

x t 0 t 1 · · · tN

y y 0 y 1 · · · yN

t 0 t 1 t 2 t N− t N− t N

S 0

(x)

S 1 (x)

S N− (x)

S N− (x) S(x)

x

Cubic Spline

we want to construct a cubic spline S(x) to interpolate the table presumable of a function f (x).

We assume that the points are ordered so that

a = t 0 < t 1 < · · · < tN = b.

S(x) is given by a different cubic polynomial in each interval [t 0 , t 1 ], [t 1 , t 2 ], · · · , [tN − 1 , tN ]. Let

S(x) be given by Si(x) if x ∈ [ti, ti+1]. Each cubic polynomial is defined by 4 coefficients and so

we have a total of 4N parameters. These are determined by the following conditions:

  1. S(x) must interpolate the data points and so in each subinterval i = 0, · · · , N − 1, we must

have Si(ti) = yi and Si(ti+1) = yi+1.

2. S

′ (x) must be continuous at each of the internal knots. Therefore for i = 1, 2 , · · · , N − 1

we must have S ′ i− 1 (ti) = S ′ i (ti).

3. S

′′ (x) must be continuous at each of the internal knots. Therefore for i = 1, 2 , · · · , N − 1

we must have S

′′ i− 1 (ti) =^ S

′′ i (ti).

  1. A choice of one of the following 2 conditions at the 2 end points a and b:

(a) The natural spline: S ′ (a) = 0 = S ′ N − 1 (b),

(b) The clamped cubic spline: S ′ 0 (a) = f ′ (a) and S ′ N − 1 (b) = f ′ (b).

The clamped cubic spline gives more accurate approximation to the function f (x), but requires

knowledge of the derivative at the endpoints. Condition 1 gives 2N relations. Conditions 2, 3

and 4 each gives N − 1 relations. Together with the 2 relations from condition 4, we have a

total of 2N + 2(N − 1) + 2 = 4N conditions. Thus we have just the right number of relations to

determined all the parameters uniquely.

The best way to express the cubic polynomial within each subinterval is to note that since

Si(x) is a cubic polynomial, then S

′′ i (x) must be a linear function of the form

S

′′ i (x) =^ αx^ +^ β.

Next we denote S ′′ i (ti) = zi and S ′′ i (ti+1) = zi+1, so that replacing i by i − 1 in the second

expression gives S ′′ i− 1 (ti) = zi, and therefore condition 3 is automatically satisfied. We then

evaluate S ′′ i (x) at the endpoint of the subinterval to get

S

′′ i (ti) = zi = αti + β

S

′′ i (ti+1) = zi+1 = αti+1 + β.

We can then solve for α and β to obtain

α =

zi+1 − zi

hi

β =

ziti+1 − zi+1ti

hi

where we define hi = ti+1 − ti for i = 0, · · · , N − 1. Inserting these back to the expression for

S

′′ i (x) gives

S

′′ i (x) =^

zi

hi

(ti+1 − x) +

zi+

hi

(x − ti).

Integrating this expression, we have

S

′ i(x) =^ −^

zi

2 hi

(ti+1 − x)

2

zi+

2 hi

(x − ti)

2

  • p,

where p is a constant. Integrating one more time, we have

Si(x) = −

zi

6 hi

(ti+1 − x)

3

zi+

6 hi

(x − ti)

3

  • px + q,

where q is another constant. Instead of using constants p and q, it is better to use constants C

and D so that

Si(x) = −

zi

6 hi

(ti+1 − x)

3

zi+

6 hi

(x − ti)

3

  • C(x − ti) + D(ti+1 − x).

Evaluating this at ti gives

Si(ti) = yi =

zi

h

2 i

  • Dhi,

from which we get D =

yi hi

zihi 6

. Similarly, evaluating Si(x) at ti+1 gives

Si(ti+1) = yi+1 =

zi+

h

2 i

  • Chi,

from which we get C =

yi+ hi

zi+1hi 6

. Using these results for C and D, we finally have the

expression for Si(x):

Si(x) = −

zi

6 hi

(ti+1 −x)

3

zi+

6 hi

(x−ti)

3

yi+

hi

zi+1hi

(x−ti)+

yi

hi

zihi

(ti+1 −x). (1)

One can easily see that

Ai =

zi+1 − zi

6 hi

Bi =

zi

Ci = −

hizi+

hizi

yi+1 − yi

hi