Anda di halaman 1dari 10

SPLINE INTERPOLATION

Spline Background
Problem: high degree interpolating polynomials often
have extra oscillations.
1
Example: Runge function f (x) = 1+4x
2 , x [1, 1].
1/(1+4x2) and P8(x) and P16(x)
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

Piecewise Polynomials provide alternative to high


degree polynomials: approximation interval [a, b] is subdivided into pieces [x1, x2], [x2, x3], . . . , [xn1, xn], with
a = x1 < x2 < < xn = b, and a low degree polynomial is used to approximate f (x) on each subinterval.
Example: piecewise linear approximation S(x)
f (xj+1) f (xj )
S(x) = f (xj )+(xxj )
, if x [xj , xj+1]
xj+1 xj
Splines are piecewise polynomial approximations, connected at xj s with various continuity conditions.

CUBIC SPLINE INTERPOLATION


Cubic Interpolating Splines for a = x1 < < xn = b
with given data (x1, y1), (x2, y2), . . . , (xn, yn).
Properties of Cubic Interpolating Spline S(x),
a) S(x) is composed of cubic polynomial pieces Sj (x)
S(x) = Sj (x) if x [xj , xj+1], j = 1, 2, . . . , n 1.
b) S(xj ) = yj , j = 1, . . . , n. (interpolation)
c) Sj1(xj ) = Sj (xj ), j = 2, . . . , n 1 (S C[a, b]).
0
d) Sj1
(xj ) = Sj0 (xj ), j = 2, . . . , n 1 (S C 1[a, b]).
00
e) Sj1
(xj ) = Sj00(xj ), j = 2, . . . , n 1 (S C 2[a, b]).
f) two end conditions: examples
i) S 00(x1) = S 00(xn) = 0 (natural or free spline);
ii) S 0(x1) = f 0(x1), S 0(xn) = f 0(xn)
(complete or clamped spline);
000
iii) S1000 = Sn1
= 0 (parabolically terminated);
000
000
iv) S1000(x2) = S2000(x2), Sn2
(xn1) = Sn1
(xn1)
(not-a-knot).
Note: if
Sj (x) = aj + bj (x xj ) + cj (x xj )2 + dj (x xj )3,
condition a) provides 4(n 1) free parameters;
b)-f) give n + 3(n 2) + 2 = 4(n 1) constraints.

CUBIC SPLINE INTERPOLATION


Example: n = 3, natural, data (1,2), (2,3), (3,5).

S1(x) = 2 + 34 (x 1) + 41 (x 1)3,
S2(x) = 3 + 32 (x 2) + 43 (x 2)2 14 (x 2)3,

CUBIC SPLINE INTERPOLATION


Cubic Interpolating Spline Construction
Spline Linear System: let hj = xj+1 xj ; start with
Sj (x) = aj + bj (x xj ) + cj (x xj )2 + dj (x xj )3
= yj + bj (x xj ) + cj (x xj )2 + dj (x xj )3.
c) Sj+1(xj+1) = Sj (xj+1), implies
yj+1 = yj + bj hj + cj h2j + dj h3j ;

yj
= bj + cj hj + dj h2j ,
hj

where yj = yj+1 yj .
Notice Sj00(x) = 2cj + 6dj (x xj ), so
00
e) Sj+1
(xj+1) = Sj00(xj+1), implies
2cj+1 = 2cj + 6dj hj ; dj hj = (cj+1 cj )/3,
00
with extra unknown cn = Sn1
(xn)/2 added. Then

(cj+1 cj )hj
yj
(cj+1 + 2cj )hj
= bj + cj hj +
= bj +
;
hj
3
3
3yj+1 3yj

= 3bj +(cj+2+2cj+1)hj+1(cj+1+2cj )hj .


hj+1
hj
Also Sj0 (x) = bj + 2cj (x xj ) + 3dj (x xj )2, so
0
d) Sj+1
(xj+1) = Sj0 (xj+1); bj+1 = bj + 2cj hj + 3dj h2j ;
bj = 2cj hj + (cj+1 cj )hj = (cj+1 + cj )hj
3yj+1 3yj

= cj hj + 2cj+1(hj + hj+1) + cj+2hj+1


hj+1
hj

CUBIC SPLINE INTERPOLATION


Natural Splines: S 00(x1) = S 00(xn) = 0, so c1 = cn = 0
Linear system equations are a tridiagonal system
c1 = 0
3y2 3y1
c1h1 + 2c2(h1+h2) + c3h2 =

h2
h1
3y3 3y2

c2h2 + 2c3(h2+h3) + c4h3 =


h3
h2
..
..
3yn2 3y32
cn3hn3 + 2cn2(hn3+hn2) + cn1hn2 =

hn2
hn3
3yn1 3yn2

cn2hn2 + 2cn1(hn2+hn1) + cnhn1 =


hn1
hn2
cn = 0.
which can be solved uniquely for cj s with O(n) work;
dj = (cj+1 cj )/(3hj ), bj = yj /hj cj hj dj h2j
can be used to find remaining coefficients for Sj (x)s.
Note: if all hj = h, a simpler tridiagonal system.

CUBIC SPLINE INTERPOLATION


Example: n = 3, natural, with data (1,2), (2,3), (3,5),
so h1 = h2 = 1, y1 = 1, y2 = 2.
Only one equation 2c2(1 + 1) = 3(2 1), so c2 = 3/4,
d1 = 1/4, d2 = 1/4;
b1 = 1 0 1/4 = 3/4, b2 = 2 3/4 + 1/4 = 3/2.
1
3
S1(x) = 2 + (x 1) + (x 1)3,
4
4
3
3
1
2
S2(x) = 3 + (x 2) + (x 2) (x 2)3.
2
4
4
1
Example: Runge function f (x) = 1+4x
2 , x [1, 1].
1/(1+4x2), S(x) and P4(x)
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

CUBIC SPLINE INTERPOLATION


Clamped Splines: let S 0(x1) = y10 , S 00(xn) = yn0 ,
so y10 = b1, yn0 = bn1 + 2cn1hn1 + 3dn1h2n1
y
(c +2c )h
Using hjj = bj + j+1 3 j j , 3hj dj = (cj+1 cj ),
1st and nth equations become
0
1

3y
2c1h1 + c2h1 = 3y
1 , and
h1
n1
cn1hn1 + 2cnhn1 = 3yn0 3y
hn1 .
Linear system equations are a tridiagonal system
2c1h1 + c2h1 =
c1h1 + 2c2(h1+h2) + c3h2 =
..
cn2hn2 + 2cn1(hn2+hn1) + cnhn1 =
cn1hn1 + 2cnhn1 =

3y1
3y10
h1
3y2 3y1

h2
h1
..
3yn1 3yn2

hn1
hn2
3yn1
.
3yn0
hn1

which can be solved (uniquely) for cj s with O(n) work;


dj = (cj+1 cj )/(3hj ), bj = yj /hj cj hj dj h2j
can be used to find remaining coefficients for Sj (x)s.

CUBIC SPLINE INTERPOLATION


Example: n = 3, clamped, with data (1,2), (2,3), (3,5),
and y10 = 1, y30 = 2. Three equations:
2c1 + c2 = 3(2 1) 3 = 0,
c1 + 4c2 + c3 = 3,
c2 + 2c3 = 6 3(2) = 0,
so c1 = c3 = 1/2, c2 = 1;
d1 = 1/2, d2 = 1/2; b1 = 1, b2 = 21+1/2 = 3/2.
S1(x) = 2 + (x 1) 12 (x 1)2 + 12 (x 1)3,
S2(x) = 3 + 32 (x 2) + (x 2)2 12 (x 2)3,
000
Parabolically Terminated Splines: S1000 = Sn1
= 0,
so d1 = dn1 = 0, c1 = c2, cn1 = cn.
Linear system equations are a tridiagonal system
c1 c2 = 0
3y2 3y1
c1h1 + 2c2(h1+h2) + c3h2 =

h2
h1
..
..
3yn1 3yn2
cn2hn2 + 2cn1(hn2+hn1) + cnhn1 =

hn1
hn2
cn1 cn = 0.
which can be solved (uniquely) for cj s with O(n) work;
dj = (cj+1 cj )/(3hj ), bj = yj /hj cj hj dj h2j
can be used to find remaining coefficients for Sj (x)s.

CUBIC SPLINE INTERPOLATION


Not-a-Knot Splines:
000
000
S1000(x2) = S2000(x2), Sn2
(xn1) = Sn1
(xn1), so
d1 = d2, dn2 = dn1, and S1 = S2, Sn2 = Sn1.
Then (c2 c1)/h1 = (c3 c2)/h2,
(cn1 cn2)/hn2 = (cn cn1)/hn1, so
1st and nth equations become
c1h2 c2(h1 + h2) + c3h1 = 0
cn2hn1 cn1(hn2 + hn1) + cnhn2 = 0.
Linear system equations are a tridiagonal system
c1h2 c2(h1 + h2) + c3h1 = 0
3y2 3y1

c1h1 + 2c2(h1+h2) + c3h2 =


h2
h1
..
..
3yn1 3yn2
cn2hn2 + 2cn1(hn2+hn1) + cnhn1 =

hn1
hn2
cn2hn1 cn1(hn2 + hn1) + cnhn2 = 0.
which can be solved (uniquely) for cj s with O(n) work;
dj = (cj+1 cj )/(3hj ), bj = yj /hj cj hj dj h2j
can be used to find remaining coefficients for Sj (x)s.

CUBIC SPLINE INTERPOLATION


Efficient Spline Evaluation
Setup: solve linear system for cj s in O(n) time
For each evaluation point x, find interval x [xj , xj+1]
in O(log(n)) time and evaluate Sj (x) in O(1) time.
Alternate formula for Sj (x) (without bj s and dj s):
cj+1
cj
3
(xj+1 x) +
(x xj )3
Sj (x) =
3hj
3hj+1
yj cj hj
yj+1 cj+1hj+1
+(
)(xj+1 x) + (

)(x xj ).
hj
3
hj+1
3
Compare with polynomial interpolation, where setup
time is O(n2) and evauation time is O(n).
Error Theorem :
if f C 4[a, b], with maxx[a,b] |f (4)(x)| = M , and
S(x) is the unique clamped spline for f (x) with
nodes a = x1 < x2 < xn = b, then
|f (x) S(x)|

10

5M
max h4j .
384 1j<n

Anda mungkin juga menyukai