0% found this document useful (0 votes)
76 views

MATH2601 Chapter 3 Approximating Functions 118

This document discusses spline interpolation, which uses piecewise polynomial functions joined together continuously to approximate a function. Specifically, it covers: 1) Spline interpolation consists of polynomial pieces on subintervals that have continuous derivatives up to a specified degree (k-1). 2) Cubic splines (k=3) are commonly used and require the spline and its first two derivatives to be continuous. 3) Constructing a cubic spline to interpolate a set of data points involves determining the cubic polynomial for each subinterval that satisfies the continuity and interpolation conditions.

Uploaded by

Surender Reddy
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)
76 views

MATH2601 Chapter 3 Approximating Functions 118

This document discusses spline interpolation, which uses piecewise polynomial functions joined together continuously to approximate a function. Specifically, it covers: 1) Spline interpolation consists of polynomial pieces on subintervals that have continuous derivatives up to a specified degree (k-1). 2) Cubic splines (k=3) are commonly used and require the spline and its first two derivatives to be continuous. 3) Constructing a cubic spline to interpolate a set of data points involves determining the cubic polynomial for each subinterval that satisfies the continuity and interpolation conditions.

Uploaded by

Surender Reddy
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/ 23

MATH2601 Chapter 3 Approximating Functions 118

3.3 Spline Interpolation


A spline function consists of polynomial pieces on subintervals
joined together with certain continuity conditions.
Formally, suppose that n + 1 points t
0
, t
1
, , t
n
have been
specied and satisfy
t
0
< t
1
< < t
n
These points are called knots.
Suppose also that an integer k 0 has been prescribed. A spline
function of degree k having knots t
0
, t
1
, , t
n
is a function
S such that:
1. On each interval [t
i1
, t
i
], S is a polynomial of degree k.
2. S has a continuous (k 1)st derivative on [t
0
, t
n
].
Hence, S is a piecewise polynomial of degree at most k having
continuous derivatives of all orders up to k 1.
MATH2601 Chapter 3 Approximating Functions 119
Figure 7: A spline of degree 0
Splines of degree 0 are piecewise constants. A typical spline of
degree 0 with six knots is shown in Figure 7.
A spline of degree 0 can be given explicitly in the form
S(x) =
_

_
S
0
(x) = c
0
x [t
0
, t
1
)
S
1
(x) = c
1
x [t
1
, t
2
)
.
.
.
.
.
.
S
n1
(x) = c
n1
x [t
n1
, t
n
]
The intervals [t
i1
, t
i
) do not intersect each other, and so no
ambiguity arises in dening such a function at the knots.
MATH2601 Chapter 3 Approximating Functions 120
Figure 8: A spline of degree 1
Figure 8 shows the graph of a typical spline function of degree 1
with nine knots. A function such as this can be dened explicitly
by
S(x) =
_

_
S
0
(x) = a
0
x + b
0
x [t
0
, t
1
]
S
1
(x) = a
1
x + b
1
x [t
1
, t
2
]
.
.
.
.
.
.
S
n1
(x) = a
n1
x + b
n1
x [t
n1
, t
n
]
The function S is continuous, and so the piecewise polynomials
match up at the knots; that is, S
i
(t
i+1
) = S
i+1
(t
i+1
).
If the knots t
i
and the coecients a
i
, b
i
are all prescribed,
then the value of S at x is obtained by rst identifying the
subinterval [t
i
, t
i+1
) that contains x.
MATH2601 Chapter 3 Approximating Functions 121
The spline function can be dened on the entire real line.
For convenience, we can use the expression a
0
x + b
0
on the
interval (, t
1
) and the expression a
n1
x + b
n1
on the
interval [t
n1
, ).
Example 3.13 Determine whether the following function is a
quadratic spline.
f(x) =
_

_
x x (, 1]

1
2
(2 x)
2
+
3
2
x [1, 2]
3
2
x [2, )
Solution It is easy to see that
f

(x) =
_

_
1 x (, 1]
2 x x [1, 2]
0 x [2, )
Since
lim
x1

f(x) = 1 = lim
x1
+
f(x)
lim
x2

f(x) =
3
2
= lim
x2
+
f(x)
lim
x1

(x) = 1 = lim
x1
+
f

(x)
lim
x2

(x) = 0 = lim
x2
+
f

(x)
we see that both f and f

are continuous on R. So f is a
quadratic spline.
MATH2601 Chapter 3 Approximating Functions 122
Example 3.14 Is the function in Example 3.13 a cubic spline?
Solution Note that
f

(x) =
_

_
0 x (, 1]
1 x [1, 2]
0 x [2, )
Since
lim
x1

(x) = 0 = 1 = lim
x1
+
f

(x)
By denition, f is not a cubic spline function since f

is not
continuous.
Example 3.15 If S is a rst degree spline function that inter-
polates f at a sequence of knots 0 = t
0
< t
1
< < t
n
= 1,
what is
_
1
0
S(x) dx?
Solution Suppose the given table of values is
x t
0
t
1
t
2
t
n
y y
0
y
1
y
2
y
n
and
S(x) =
_

_
S
0
(x) = a
0
x + b
0
x [t
0
, t
1
)
S
1
(x) = a
1
x + b
1
x [t
1
, t
2
)
.
.
.
.
.
.
S
n1
(x) = a
n1
x + b
n1
x [t
n1
, t
n
]
MATH2601 Chapter 3 Approximating Functions 123
Then
_
1
0
S(x) dx =
n1

i=0
_
t
i+1
t
i
(a
i
x + b
i
) dx
=
n1

i=0
_
a
i
2
(t
2
i+1
t
2
i
) + b
i
(t
i+1
t
i
)
_
=
n1

i=0
_
a
i
2
(t
i+1
+ t
i
) + b
i
_
(t
i+1
t
i
)
=
n1

i=0
_
1
2
(a
i
t
i+1
+ b
i
+ a
i
t
i
+ b
i
)
_
(t
i+1
t
i
)
=
n1

i=0
1
2
(y
i+1
+ y
i
)(t
i+1
t
i
)
Remark If f is nonnegative, then so is S. In this case,
_
1
0
S(x) dx
is the sum of area of trapezoids over [t
i
, t
i+1
].
MATH2601 Chapter 3 Approximating Functions 124
Example 3.16 Determine all the values of a, b, c, d, e for which
the following function is a cubic spline:
f(x) =
_

_
a(x 2)
2
+ b(x 1)
3
x (, 1]
c(x 2)
2
x [1, 3]
d(x 2)
2
+ e(x 3)
3
x [3, )
Next, determine the value of parameters so that the cubic spline
interpolates this table
x 0 1 4
y 26 7 25
Solution From the denition of f, we deduce that
f

(x) =
_

_
2a(x 2) + 3b(x 1)
2
x (, 1]
2c(x 2) x [1, 3]
2d(x 2) + 3e(x 3)
2
x [3, )
and
f

(x) =
_

_
2a + 6b(x 1) x (, 1]
2c x [1, 3]
2d + 6e(x 3) x [3, )
MATH2601 Chapter 3 Approximating Functions 125
The continuity of f, f

and f

at x = 1 and x = 3 implies the


following, respectively:
f : a = c and c = d
f

: 2a = 2c and 2c = 2d
f

: 2a = 2c and 2c = 2d
So a = c = d. Therefore f is a cubic spline i a = c = d, and
b and e can take any values. (There are only three degrees of
freedom.)
According to the table, f(0) = 26, f(1) = 7, and f(4) = 25, so
4a b = 26
c = 7
4d + e = 25
In addition, a = c = d. Therefore the values of these parameters
can be uniquely determined:
a = c = d = 7, b = 2 and e = 3
MATH2601 Chapter 3 Approximating Functions 126
Cubic Splines
We shall develop more thoroughly the theory and construction of
the cubic splines (k = 3) since these are often used in practice.
We assume that a table of values has been given:
x t
0
t
1
t
2
t
n
y y
0
y
1
y
2
y
n
(3.22)
and that a cubic spline S it to be constructed to interpolate the
table.
On each interval [t
0
, t
1
], [t
1
, t
2
], , [t
n1
, t
n
], S is given by a
dierent cubic polynomial.
Let S
i
be the cubic polynomial that represents S on [t
i
, t
i+1
].
Thus,
S(x) =
_

_
S
0
(x) x [t
0
, t
1
]
S
1
(x) x [t
1
, t
2
]
.
.
.
.
.
.
S
n1
(x) x [t
n1
, t
n
]
(3.23)
MATH2601 Chapter 3 Approximating Functions 127
The polynomials
S
i1
on [t
i1
, t
i
]
and
S
i
on [t
i
, t
i+1
]
interpolate the same value at the point t
i
and therefore
S
i1
(t
i
) = y
i
= S
i
(t
i
) (1 i n 1)
Hence, S is automatically continuous.
Moreover, S

and S

are assumed to be continuous, and these


conditions will be used in the derivation of the cubic spline func-
tion.
MATH2601 Chapter 3 Approximating Functions 128
Does the continuity of S, S

and S

provide enough conditions


to dene a cubic spline?
There are 4n coecients in the piecewise cubic polyno-
mial since there are four coecients in each of the n cubic
polynomials.
On each subinterval [t
i
, t
i+1
], there are two interpolation con-
ditions, S(t
i
) = y
i
and S(t
i+1
) = y
i+1
, giving 2n conditions.
The continuity of S gives no additional conditions since it has
already been counted in the interpolation conditions.
The continuity of S

gives one condition at each interior knot,


S

i1
(t
i
) = S

i
(t
i
)
accounting for n 1 additional conditions.
Similarly, the continuity of S

gives another n1 conditions.


Thus there are altogether 4n 2 conditions for determining 4n
coecients. Two degrees of freedom remain, and there are
various ways of using them to advantage.
MATH2601 Chapter 3 Approximating Functions 129
Now we derive the equation for S
i
(x) on the interval [t
i
, t
i+1
].
1. First we dene the numbers z
i
= S

(t
i
). Clearly, z
i
exists for
0 i n an satisfy
lim
xt
+
i
S

(x) = z
i
= lim
xt

i
S

(x) (1 i n 1)
because S

is continuous at each interior knot.


2. Since S
i
is a polynomial of degree 3 on [t
i
, t
i+1
], S

i
is a poly-
nomial of degree 1. We may write
S

i
(x) = A
i
x + B
i
, x [t
i
, t
i+1
]
Note that S

i
satises
S

i
(t
i
) = z
i
and S

i
(t
i+1
) = z
i+1
Then
A
i
t
i
+ B
i
= z
i
A
i
t
i+1
+ B
i
= z
i+1
Let h
i
= t
i+1
t
i
, we have
A
i
=
z
i+1
z
i
t
i+1
t
i
=
z
i+1
z
i
h
i
B
i
= z
i
A
i
t
i
= z
i

z
i+1
z
i
h
i
t
i
MATH2601 Chapter 3 Approximating Functions 130
Hence
S

i
(x) = A
i
x + B
i
=
z
i+1
z
i
h
i
x + z
i

z
i+1
z
i
h
i
t
i
=
z
i+1
h
i
x
z
i+1
h
i
t
i
+ z
i

z
i
h
i
x +
z
i
h
i
t
i
=
z
i+1
h
i
(x t
i
) + z
i

z
i
h
i
x +
z
i
h
i
(t
i+1
h
i
)
=
z
i+1
h
i
(x t
i
) + z
i

z
i
h
i
x +
z
i
h
i
t
i+1
z
i
=
z
i+1
h
i
(x t
i
) +
z
i
h
i
(t
i+1
x)
So S

i
(x) is the straight line between z
i
and z
i+1
:
S

i
(x) =
z
i
h
i
(t
i+1
x) +
z
i+1
h
i
(x t
i
) (3.24)
If this is integrated once,
S

i
(x) =
z
i
h
i
_
(t
i+1
x) dx +
z
i+1
h
i
_
(x t
i
) dx
=
1
2
z
i
h
i
(t
i+1
x)
2
+
1
2
z
i+1
h
i
(x t
i
)
2
+ C
i
Integrating one more time, the result is S
i
itself:
S
i
(x) =
z
i
6h
i
(t
i+1
x)
3
+
z
i+1
6h
i
(x t
i
)
3
+ C
i
(x t
i
) + D
i
(3.25)
MATH2601 Chapter 3 Approximating Functions 131
3. The interpolation conditions S
i
(t
i
) = y
i
and S
i
(t
i+1
) = y
i+1
can now be imposed on S
i
to determine C
i
and D
i
.
First,
y
i
=
z
i
6h
i
(t
i+1
t
i
)
3
+ D
i
=D
i
= y
i

z
i
h
2
i
6
Then
y
i+1
=
z
i+1
6h
i
(t
i+1
t
i
)
3
+ C
i
(t
i+1
t
i
) + D
i
leads to
C
i
=
y
i+1
y
i
h
i
+
h
i
6
(z
i
z
i+1
)
Hence
S
i
(x) =
z
i
6h
i
(t
i+1
x)
3
+
z
i+1
6h
i
(x t
i
)
3
+
_
y
i+1
y
i
h
i
+
h
i
6
(z
i
z
i+1
)
_
(x t
i
)
+
_
y
i

z
i
h
2
i
6
_
which can be rewritten as
S
i
(x) =
z
i
6h
i
(t
i+1
x)
3
+
z
i+1
6h
i
(x t
i
)
3
+
_
y
i+1
h
i

z
i+1
h
i
6
_
(x t
i
)
+
_
y
i
h
i

z
i
h
i
6
_
(t
i+1
x) (3.26)
MATH2601 Chapter 3 Approximating Functions 132
4. Once the values of z
0
, z
1
, , z
n
have been determined,
(3.23) and (3.26) can be used to evaluate S(x) for any x in
the interval [t
0
, t
n
].
5. To determine z
1
, z
2
, , z
n1
, we use the continuity condi-
tions for S

at the interior knots t


i
:
S

i1
(t
i
) = S

i
(t
i
)
Since
S

i
(x) =
1
2
z
i
h
i
(t
i+1
x)
2
+
1
2
z
i+1
h
i
(x t
i
)
2
+
y
i+1
y
i
h
i
+
h
i
6
(z
i
z
i+1
)
Then substitution of x = t
i
and simplication lead to
S

i
(t
i
) =
h
i
3
z
i

h
i
6
z
i+1
+
y
i+1
y
i
h
i
(3.27)
and
S

i1
(t
i
) =
h
i1
6
z
i1
+
h
i1
3
z
i
+
y
i
y
i1
h
i1
(3.28)
When the right-hand sides of (3.27) and (3.28) are set equal
to each other, the result can be written as
h
i1
z
i1
+ 2(h
i
+ h
i1
)z
i
+ h
i
z
i+1
=
6
h
i
(y
i+1
y
i
)
6
h
i1
(y
i
y
i1
) (3.29)
MATH2601 Chapter 3 Approximating Functions 133
If we dene
c
i
=
6
h
i
(y
i+1
y
i
)
then
6
h
i
(y
i+1
y
i
)
6
h
i1
(y
i
y
i1
) = c
i
c
i1
Let
b
i
= c
i
c
i1
Then (3.29) can be written as
h
i1
z
i1
+ 2(h
i
+ h
i1
)z
i
+ h
i
z
i+1
= b
i
(3.30)
which is valid only for i = 1, 2, , n 1. (Why?)
(3.29) gives a system of n1 linear equations for the n+1
unknowns z
0
, z
1
, , z
n
.
Recall that we have 2 degrees of freedom.
We can select z
0
and z
n
arbitrarily and solve the resulting system
of equations to obtain z
1
, z
2
, , z
n1
.
One widely used choice is z
0
= z
n
= 0. The resulting spline
function is called natural cubic spline. (This choice of spline
is supported by a theorem to be proved later.)
MATH2601 Chapter 3 Approximating Functions 134
Equations (3.30) for 1 i n1 with z
0
= 0 and z
n
= 0 leads
to a linear system of the following form.
_

_
u
1
h
1
h
1
u
2
h
2
h
2
u
3
h
3
.
.
.
.
.
.
.
.
.
h
n3
u
n2
h
n2
h
n2
u
n1
_

_
_

_
z
1
z
2
z
3
.
.
.
z
n2
z
n1
_

_
=
_

_
b
1
b
2
b
3
.
.
.
b
n2
b
n1
_

_
where
u
i
= 2(h
i
+ h
i1
) h
i
= t
i+1
t
i
b
i
= c
i
c
i1
c
i
=
6
h
i
(y
i+1
y
i
)
The coecient matrix is symmetric, tridiagonal and diagonally
dominant.
Hence Gaussian elimination without pivoting can be used to
solve the system for z
1
, z
2
, , z
n1
.
Once z
i
are computed, S
i
(x) can be determined.
MATH2601 Chapter 3 Approximating Functions 135
Example 3.17 Find the natural cubic spline function whose
knots are 1, 0 and 1 and that takes the value S(1) = 13,
S(0) = 7 and S(1) = 9.
Solution We need z
0
= z
2
= 0.
Now
t
0
= 1, t
1
= 0, t
2
= 1,
y
0
= 13, y
1
= 7, y
2
= 9
and
h
0
= h
1
= 1
So (3.29) yields
h
0
z
0
+ 2(h
1
+ h
0
)z
1
+ h
1
z
2
=
6
h
1
(y
2
y
1
)
6
h
0
(y
1
y
0
)
2(2)z
1
= 6(2) 6(6)
which implies z
1
= 12.
By (3.26), we have
S
0
(x) =
z
0
6h
0
(t
1
x)
3
+
z
1
6h
0
(x t
0
)
3
+
_
y
1
h
0

z
1
h
0
6
_
(x t
0
)
+
_
y
0
h
0

z
0
h
0
6
_
(t
1
x)
=
z
1
6h
0
(x t
0
)
3
+
_
y
1
h
0

z
1
h
0
6
_
(x t
0
) +
y
0
h
0
(t
1
x)
= 2(x + 1)
3
+ 5(x + 1) 13x
MATH2601 Chapter 3 Approximating Functions 136
and
S
1
(x) =
z
1
6h
1
(t
2
x)
3
+
z
2
6h
1
(x t
1
)
3
+
_
y
2
h
1

z
2
h
1
6
_
(x t
1
)
+
_
y
1
h
1

z
1
h
1
6
_
(t
2
x)
=
z
1
6h
1
(t
2
x)
3
+
y
2
h
1
(x t
1
) +
_
y
1
h
1

z
1
h
1
6
_
(t
2
x)
= 2(1 x)
3
+ 9x + 5(1 x)
So the natural cubic spline function is
S(x) =
_
2(x + 1)
3
+ 5(x + 1) 13x x [1, 0]
2(1 x)
3
+ 9x + 5(1 x) x [0, 1]
We now present a theorem to the eect that the natural spline
produces the smoothest possible interpolating function. The
word smooth is given a technical meaning in the theorem.
Theorem 3.6. (Theorem on Optimality of Natural Cubic
Splines) Let f

be continuous on [a, b] and let a = t


0
< t
1
<
< t
n
= b. If S is the natural cubic spline interpolating f at
the knots t
i
for 0 i n, then
_
b
a
[S

(x)]
2
dx
_
b
a
[f

(x)]
2
dx
MATH2601 Chapter 3 Approximating Functions 137
Proof We need to show
_
b
a
[S

(x)]
2
dx
_
b
a
[f

(x)]
2
dx
Let g f S. Then
g(t
i
) = 0 for 0 i n
and (f

)
2
= (S

+ g

)
2
= (S

)
2
+ (g

)
2
+ 2S

leads to
_
b
a
(f

)
2
dx =
_
b
a
(S

)
2
dx +
_
b
a
(g

)
2
dx + 2
_
b
a
S

dx
The proof will be complete if we can show that
_
b
a
S

dx 0.
We establish this in the following analysis, using integration by
parts, the condition S

(t
0
) = S

(t
n
) = 0, and the fact that S

is a constant (say c
i
) on [t
i1
, t
i
].
_
b
a
S

dx =
n

i=1
_
t
i
t
i1
S

dx
=
n

i=1
_
(S

)(t
i
) (S

)(t
i1
)
_
t
i
t
i1
S

dx
_
=
n

i=1
_
t
i
t
i1
S

dx =
n

i=1
c
i
_
t
i
t
i1
g

dx
=
n

i=1
c
i
[g(t
i
) g(t
i
1)] = 0
MATH2601 Chapter 3 Approximating Functions 138
Theorem 3.7. Let a = t
0
< t
1
< < t
n
= b. If g

is
continuous on [a, b] and g interpolates a given function f at the
knots t
i
for 0 i n, then
_
b
a
[S

(x)]
2
dx
_
b
a
[g

(x)]
2
dx
where S is the natural cubic spline interpolating f at the knots
t
i
for 0 i n.
Proof Since S also interpolates g at t
i
for 0 i n, the
statement can be decuded directly from Theorem (3.6) with g in
place of f over there.
Remark For a curve dened by the equation y = g(x), the
curvature at a point x is
k(x) =
|g

(x)|
(1 + |g

(x)|
2
)
3/2
which is commonly linearized to
k(x) |g

(x)|
The quantity
_
b
a
[g

(x)]
2
dx can therefore be viewed as a crude
measure of the total curvature over an interval.
In this measure, Theorem (3.7) asserts that any smooth interpo-
lating function must have a total curvature at least as large as
that of the natural cubic spline. That is why the natural spline
produces the smoothest possible interpolating function.
MATH2601 Chapter 3 Approximating Functions 139
Example 3.18 Determine the values of a, b, c so that the fol-
lowing function is a cubic spline having knots 0, 1 and 2:
f(x) =
_
3 + x 9x
2
x [0, 1]
a + b(x 1) + c(x 1)
2
+ d(x 1)
3
x [1, 2]
Next, determine d so that
_
2
0
[f

(x)]
2
dx is minimized. Finally,
nd the value of d that makes f

(2) = 0 and explain why this


value is dierent from the one previously determined.
Solution Observe that
f

(x) =
_
1 18x x [0, 1]
b + 2c(x 1) + 3d(x 1)
2
x [1, 2]
and
f

(x) =
_
18 x [0, 1]
2c + 6d(x 1) x [1, 2]
The continuity of f, f

and f

at x = 1 implies the following,


respectively:
f : 5 = a
f

: 17 = b
f

: 18 = 2c
So a = 5, b = 17 and c = 9.
MATH2601 Chapter 3 Approximating Functions 140
Since
_
2
0
[f

(x)]
2
dx
=
_
1
0
[f

(x)]
2
dx +
_
2
1
[f

(x)]
2
dx
=
_
1
0
[18]
2
dx +
_
2
1
[2c + 6d(x 1)]
2
dx
= 2(18)
2
108d + 12d
2
(as c = 9)
it can be seen that
_
2
0
[f

(x)]
2
dx is minimized when the rst
derivative 108 + 24d = 0. Thus d = 9/2.
Setting f

(2) = 0 yields 2c + 6d = 0, so d = 3.
Since f

(0) = 18, f(x) is not a natural cubic spline for any d.


So when
_
2
0
[f

(x)]
2
dx is minimized, we need not have f

(2) = 0.
That is why the above values of d can be dierent.

You might also like