Splines
Splines
Antony Jameson
1 References on splines
1
2 Definition of spline
Figure 1:
Typically cubics are used. Then the coefficients are chosen to match the function and
its first and second derivatives at each joint. There remain one free condition at each
end, or two conditions at one end. However, using only starting conditions the spline
is unstable. In general with nth degree polynomials one can obtain continuity up to
the n − 1 derivative. The most common spline is a cubic spline. Then the spline
function y(x) satisfies y (4) (x) = 0, y(3)(x) = const, y 00 (x) = a(x) + h. But for a beam
between simple supports
M (x)
y 00 (x) =
EI
where M (x) varies linearly. Thus a spline is the curve obtained from a draughtsman’s
spline.
2
Figure 2: Draughtsman’s spline
Let data be given at x0 , x1 , · · · xn with values y0 , y1 , · · · yn . Let S(x) bet the spline.
Let
Mj = S 00 (xj ), hj = xj − xj−1
xj − x x − xj−1
S 00 (x) = Mj−1 + Mj
hj hj
But
S(xj−1 ) = yj−1 , S(xj ) = yj .
We obtain
3
(xj − x)2 (x − xj−1 )2 yj − yj−1 Mj − Mj−1
S 0 (x) = −Mj−1 + Mj + − hj
2hj 2hj hj 6
We now have continuity of S 00 (x) and S(x) at xj . We also require continuity of S 0 (x).
Now
hj hj yj − yj−1
S 0 (x−
j ) = Mj−1 + Mj +
6 3 hj
−hj+1 hj+1 yj+1 − yj
S 0 (x+
j ) = Mj − Mj+1 +
3 6 hj+1
If neither S 0 (x) nor S 00 (x) are known at the ends, one may set S 000 (x) = 0, or
M1 − M0 = 0
Mn−1 − Mn = 0
Alternatively one may use some linear combination of these end conditions. In any
4
case one obtains a tridiagonal set of equations which may be written
2 λ0 M0 d0
µ1 2 λ1 M1 d1
=
µn−1 2 λn−1 Mn−1 dn−1
µn 2 Mn dn
hj+1
λj = , µj = 1 − λj
hj + hj+1
Let
mj = S 0 (xj )
Then
5
(xj − x)(2xj−1 + xj − 3x) (x − xj−1 )(2xj − xj−1 − 3x)
S 0 (x) = mj−1 2
− mj
hj h2j
yj − yj−1
+6 (xj − x)(x − xj−1 )
h3j
1 1 1 1 yj − yj−1 yj+1 − yj
mj−1 + 2 + mj + mj+1 = 3 2
+3
hj hj hj+1 hj+1 hj h2j+1
Then
2 µ0 m0 c0
λ1 2 µ1 m1 c1
=
λN −1 2 µN −1 mN −1 cN −1
λN 2 mN cN
yj − yj−1 yj+1 − yj
cj = 3λj + 3µj
hj hj+1
6
The end condition S 00 = 0 gives
yj − y0
µ0 = 1, c0 = 3
hj
yN − yN −1
λN = 1, cN = 3
hN −1
Consider all functions f (x) such that f (xi ) = yi Then the spline S(x) with S 00 (x0 ) =
S 00 (xn ) = 0 is that function f (x) which minimize:
Z xn
f 00 (x)2 dx
x0
(Ahlberg, p. 76)
Proof
Z xn
2
(f 00 (x) − S 00 (x)) dx
x0
Z xn Z Z
00 00 00 00
= 2
f (x) dx − 2 (f (x) − S (x)) S (x)dx − S 00 (x)2 dx
x0
n
X n Z
X xi
0 0 00 i
[(f (x) − S (x)) S (x)]i−1 − (f 0 (x) − S 0 (x)) S 000 (x)dx
i=1 i=1 xi−1
7
S 000 (x) is constant in each segment, and can be taken out of each integral in the second
term.
But
Z xi
(f 0 (x) − S 0 (x)) dx = [f (x) − S(x)]ii−1
xi−1
f (xi ) = S(xi ) = yi , i = 0, 1, . . . n
Also the contributions to the sum in the first term vanish at every interior node,
leaving
(f 0 (xn ) − S 0 (xn )) S 00 (xn ) − (f 0 (x0 ) − S 0 (x0 )) S 00 (x0 )
Thus
Z xn
(f 00 (x) − S 00 (x)) S 00 (x)dx = 0
x0
Z xn Z xn Z xn
00 00 2
2
f (x) dx − 2
S (x) dx = (f 00 (x) − S 00 (x)) dx > 0
x0 x0 x0
8
5 Errors in spline approximation
f (x) − S(x) ∼ h4
f 0 (x) − S 0 (x) ∼ h3
f 00 (x) − S 00 (x) ∼ h2
This is proved by Ahlberg, Nilson and Walsh, p. 29, provided that f (4) is continuous.
kxk = max|xi |
n
kBxk X
kBk = sup = max |bij |
x6=0 kxk i
j=1
9
With a diagonally dominant matrix we have
X n
kyk = kBxk = max bij xj
i
j=1
Xn
≥ bij xj
j=1
( )
X
kyk ≥ |bkk | − |bkj | kxk
j6=k
( )
X
≥ min |bii | − |bij | kxk
i
j6=i
Now let
δ = maxhj
and let
δ
max ≤ β < ∞.
hj
Then the spline has the following convergence propety as the maximum mesh spacing
10
δ is reduced:
Theorem A: (Ahlberg, p. 22)
Let f (x) be continuous on [a, b] and let max [|λ0 |, |µn |] < 2. Then if S(x) is a spline
fit to f (x) with x0 = a, xn = b, then
|f (x) − S(x)| → 0 as δ → 0.
Also if
α
|f (x) − f (x0 )| ≤ κ |x − x0 | , 0≤α≤1
then
|f (x) − S(x)| = O (δ α ) .
Mj−1 (xj − x) (xj − x)2 − h2j Mj (x − xj−1 ) (x − xj−1 )2 − h2j
S(x) − f (x) = +
6hj 6hj
fj + fj−1 xj + xj−1 − 2x
+ − f (x) + (fj − fj−1 )
2 2hj
By maximizing the coefficients of Mj and Mj−1 we find that they do not exceed
h2j /35/2 . Let Ai j be the elements of B −1 where B is the coefficient matrix. Then
n−1
X (fi+1 − fi )/hi+1 − (fi − fi−1 )/hi
Mj = 6 Aji + Aj0 d0 + Ajn dn .
i=1
hi + hi+1
11
Also let µ(f, δ) be the modulus of continuity of f (x) on [a, b] defined as
(fi+1 − fi )/hi+1 − (fi − fi−1 )/hi
h2j ≤ β 2 µ(f, δ)
hi + hi+1
Thus
h2j (|Mj−1 + |Mj |) ≤ 2kB −1 k 6β 2 µ(f, δ) + δ 2 (|d0 | + |dn |)
and finally
2 −1
2 2
1
|S(x) − f (x)| ≤ 5 kB k 6β µ(f, δ) + δ (|d0 | + |dn |) + µ(f, δ) 1 +
32 2
then
µ(f, δ) ≤ κδ α
If f is in C 2 we can prove
Theorem B: (Ahlberg, p. 27)
12
|f (p) x − S (p) (x)| = O(δ 2−p )
6 f1 − f0
2M0 + M1 = − f00
h1 h1
or
M0 = f000 .
BM = d
whence
d B
B M− = I− d
3 3
13
Also by the Taylor theorem
I− B
≤ 3µ(f 00 , δ)
d
3
d
−1
M −
≤ kB k
I − B
00
3
3
≤ 3µ(f , δ)
d
dj
Now since = f 00 (ξj ) it also follows that
3
00
f − d
≤ µ(f 00 , δ)
3
whence
kM − f 00 k ≤ 4µ(f 00 , δ)
kS 00 − f 00 k ≤ 5µ(f 00 , δ)
14
Now if
|f 00 (x) − f 00 (x0 )| ≤ κ|x − x0 |α , 0<α≤1
we have
kS 00 − f 00 k ≤ 5κδ α
Since S(xj ) = f (xj ), by Rolle’s theorem, there is a point ξj in the interval [xj−1 , xj ]
at which S 0 (ξj ) = f 0 (ξj ). Then on this interval
Z
x
0 0
|f (x) − S (x)| = (f (x) − S (x)) ≤ 5δµ(f 00 , δ)
00 00
ξj
5
|f (x) − S(x)| ≤ δ 2 µ(f 00 , δ)
2
Even stronger convergence theorems can be proved. Ahlberg (p. 29) gives:
Theorem C: Let f (4) (x) be continuous then
B spline
15
Figure 3: B spline
6 Smoothing splines
Instead of requiring a spline to coincide with the function at specidied points one may
simply require it to pass closer and permit some smoothing. To do this let S(x) be
chosen to minimize
xn n
(f (xi ) − yi )2
Z X
R1 f 00 (x)2 dx + R2
x0 i=0
Qi
Then by the calculus of variations the solution can be shown to be a spline with joints
at x1 , x2 , · · · xn−1 which does not necessarily pass through thte points.
Reinsch (Numer. Math 10, 1967, pp. 177-183) shows that the equations now reduce
to a five diagonal system, which can still be solved with a number of operations
proportional to n.
16
7 Change of independent variable
With any type of polynomial fitting or spline fitting difficulties occur if the function
y(x) has too large a slope. In extreme cases the given points may represent a closed
curve or other curve that bends back on itself.
Figure 4:
dy
In such a case the xi do not form a monotone sequence, and also is inifinite at
dx
dx
the nose, while is infinite at the top and bottom. To overcome this difficulty we
dy
need to parameterize the curve and set
x = x(t)
y = y(t)
where t is a new independent variable that increases monotonely. Then form separate
splines for x(t) and y(t).
17
8 Integration
Splines are useful for integration when function is defined by a table of coordinates
at unequal intervals.
Conclusions
Acknowledgements
References
18