Cubic Splines
Cubic Splines
October 21 2008
Motivation
many points.
We want to find an approximation in-between these points.
Until now we have seen one way to do this, namely high order
a = t0
t1
t2
t3
tn1
b = tn
Motivation
f (x) =
1
.
1 + x2
Motivation
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
5
Motivation
8
exact
7
interpolated
6
5
4
3
2
1
0
1
5
Motivation
y1
s1 (x)
sn1 (x)
y0
x0
x1
x2
xn1 xn
Motivation
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
5
interpolation.
However piecewise linear is not a good choice as the regularity
s1(x)
s0(x)
sn1(x)
a = t0
t1
t2
t3
tn1
b = tn
Splines - definition
t0 x t1
S0 (x),
S1 (x),
t1 x t2
S(x) =
.
..
Cubic spline
a0 x 3 + b0 x 2 + c0 x + d0 ,
t0 x t1
S0 (x) =
..
S(x) =
.
S (x) = a x 3 + b x 2 + c x + d , t
n1
n1
n1
n1
n1
n1 x tn .
which satisfies
0
(xi ) = Si0 (xi )
S(x) C 2 [t0 , tn ] : Si1
00
Si1
(xi )
Si00 (xi )
, i = 1, 2, , n 1.
3(n 1) equations.
In addition we require that
S(xi ) = yi ,
i = 0, , n
)
S0000 (t1 ) = S1000 (t1 )
00
000
(tn1 ) = Sn1
(tn1 )
Sn2
Si00 (x) = zi
x ti
x ti+1
+ zi+1
.
ti ti+1
ti+1 ti
S 00 (x) = zi+1
x ti
ti+1 x
+ zi
.
hi
hi
zi+1
zi
(x ti )3 +
(ti+1 x)3
6hi
6hi
+ Ci (x ti ) + Di (ti+1 x) .
Si (x) =
Interpolation gives:
Si (ti ) = yi
zi 2
h + Di hi = yi , i = 0, , n.
6 i
Continuity yields:
Si (ti+1 ) = yi+1
zi+1 2
h + Ci hi = yi+1 .
6 i
system
zi+1
zi
(x ti )3 +
(ti+1 x)3
6hi
6hi
yi+1 zi+1
+
hi (x ti )
hi
6
yi
hi
zi (ti+1 x) .
+
hi
6
Si (x) =
zi+1
zi
(x ti )2
(ti+1 x)2
2hi
2hi
hi
1
+ (yi+1 yi ) (zi+1 zi ) .
h
6
{z
}
|i
Si0 (x) =
bi
1
hi
1
Si0 (ti ) = zi hi + bi zi+1 + hi zi
2
6
6
zi+1
hi
1
0
Si (ti+1 ) =
hi + bi zi+1 + hi zi
2
6
6
1
1
Si1 (ti ) = zi hi+1 + hi1 zi1 + bi1
3
6
Si0 (ti ) = Si1 (ti )
6 (bi bi1 ) = hi1 z1 + 2 (hi1 + hi ) zi + hi zi+1 .
This means that we can find our solution using the following
procedure:
First do some precalculations
hi = ti+1 ti ,
i = 0, , n 1
1
bi = (yi+1 yi ) , i = 0, , n 1
hi
vi = 2 (hi1 + hi ) ,
i = 1, . . . , n 1
ui = 6 (bi bi1 ) ,
z0 = zn = 0
i = 1, , n 1
v1 h1
h1 v2
h2
h2
v3
..
.
h3
..
.
..
.
..
..
.
hn2
z1
z2
z3
..
.
u1
u2
u3
..
.
=
.
i
xi
yi
hi = xi+1 xi
bi = h1i (yi+1 yi )
vi = 2 (hi1 + hi )
ui = 6 (bi bi1 )
0
0.9
1.3
0.4
0.5
1
1.3
1.5
0.6
0.5833
2.0
0.5
2.0 0.4 z1
0.5
=
0.4 1.6 z2
0.4
2
1.9
1.85
0.2
1.25
1.6
4
3
2.1
2.1
functions
S0 (x) = 0.208 (x 0.9)3 + 3.78 (x 0.9) + 3.25 (1.3 x)
S1 (x) = 0.035 (x 1.3)3 + 0.139 (1.9 x)3 + 0.664 0.62x
S2 (x) = 0.104 (x 1.9)3 + 10.5 (x 1.9) + 9.25 (2.1 x)
d1
a1
c1
d2
..
.
c2
..
.
..
an1
b1
b2
..
.
.
,
cn1 bn1
bn
dn
d1
0
c1
d2
..
.
c2
..
.
..
an1
b1
b2
..
.
,
,
cn1 bn1
bn
dn
a1
d2 = d2 c1
d1
a1
b2 = b2 b1
d1
for i =2, , n
m = ai1 /di1
di = di mci1
bi = bi mbi1
end
And the backward substitution reads
xn = bn /dn
for i =n 1, , 1
xi = bi ci xi+1 /di
end
where b1 = b1 .
i =
This will work out fine as long as d
6 0.
Assume that |di | > |ai1 | + |ci | - i.e. diagonal dominance.
For the eliminated system diagonal domiance means that
|di1 |
di1
> |ai1 |ci | |ai1 | = |ci |.
|di | = |di
function:
Z
(f ) =
(f 00 (x))2 dx.
(1)
Theorem
Given interpolation data (ti , yi )ni=0 . Among all functions
f C 2 [a, b] which interpolates (ti , yi ), the natural cubic spline is
the smoothest, where smoothness is measured through (1).
g (x) C 2 [a, b]
g (ti ) = 0, i = 0, , n.
2
S 00 (x) g 00 (x) dx
a
Z b
= (S) + (g ) 2
S 00 (x)g 00 (x) dx
(f ) =
S 00 (x)g 00 (x) dx = 0.
Z
a
b
S (x)g (x) dx = g (x)S (x)a
00
00
00
000
g (x)S (x) dx =
a
n1 Z
X
i=0
n1
X
i=0
n1
X
i=0
t i+1
ti
Z
6ai
ti+1
g 0 (x) dx
ti
t
6ai g (x)|ti+1
= 0.
i