Documente Academic
Documente Profesional
Documente Cultură
MACM 316
1/15
Cubic Splines
Given the following list of points: x : y : a = x0 < x1 < < xn = b y0 y1 yn
Basic idea: piecewise polynomial interpolation Use lower order polynomials that interpolate on each subinterval [xi, xi+1]. Force the polynomials to join up as smoothly as possible. Simplest example: a linear spline just connects the dots Denition: A cubic spline S (x) is a piecewise-dened function that satises the following conditions: 1. S (x) = Si (x) is a cubic polynomial on each subinterval [xi, xi+1] for i = 0, 1, . . . , n 1. 2. S (xi) = yi for i = 0, 1, . . . , n (S interpolates all the points). 3. S (x), S (x), and S (x) are continuous on [a, b] (S is smooth). So we write the n cubic polynomial pieces as Si (x) = ai + bi (x xi ) + ci(x xi)2 + di (x xi)3, for i = 0, 1, . . . , n 1, where ai, bi , ci, and di represent 4n unknown coefcients.
November 1, 2012 c Steven Rauch and John Stockie
Cubic Splines
MACM 316
2/15
Derivation
Using the denition, lets determine equations relating the coefcients and keep a count of the number of equations: # eqns. Interpolation and continuity: Si (xi) = yi for i = 0, 1, . . . , n 1 Si (xi+1) = yi+1 for i = 0, 1, . . . , n 1
(based on both of these, S (x) is continuous)
n n
n1 n1 4n 2
November 1, 2012
Cubic Splines
MACM 316
3/15
Derivation (contd)
We need expressions for the derivatives of Si : Si(x) = ai + bi(x xi) + ci(x xi)2 + di (x xi)3
(x) = bi + 2ci(x xi) + 3di(x xi)2 Si (x) = 2ci + 6di(x xi) Si
It is very helpful to introduce the hi = xi+1 xi. Then the spline conditions can be written as follows: Si(xi) = yi for i = 0, 1, . . . , n 1: ai = y i Si(xi+1) = yi+1 for i = 0, 1, . . . , n 1:
3 ai + hi b i + h2 i ci + hi di = yi+1 (xi+1) = Si Si +1 (xi+1 ) for i = 0, 1, . . . , n 2:
b i + 2 hi c i + 3 h2 i di bi+1 = 0
(xi+1) = Si Si +1 (xi+1 ) for i = 0, 1, . . . , n 2:
2ci + 6hidi 2ci+1 = 0 The boxed equations above can be written as a large linear system for the 4n unknowns [a0, b0, c0, d0, a1, b1, c1, d1 , . . . , an1, bn1, cn1, dn1 ]T
November 1, 2012 c Steven Rauch and John Stockie
Cubic Splines
MACM 316
4/15
Alternate formulation
This linear system can be simplied considerably by dening
(x i ) = 2c i mi = Si
or
ci =
mi 2
= = =
hi mi 2
hi (mi+1 6
mi)
b i + 2 hi c i + 3 h2 i di = bi+1
Substitute bi, ci and di from above and simplify: himi + 2(hi + hi+1 )mi+1 + hi+1 mi+2 = 6
November 1, 2012
yi+1 yi hi
Cubic Splines
MACM 316
5/15
Notice: These are n 1 linear equations for n + 1 unknowns [m0, m1, m2, . . . , mn]T where
mi = gi (x i ).
November 1, 2012
Cubic Splines
MACM 316
6/15
. . . or you could just drop the equations for m0 and mn and write it as an (n 1) (n 1) system.
November 1, 2012 c Steven Rauch and John Stockie
Cubic Splines
MACM 316
7/15
The word spline comes from the draftsmans spline, which is shown here constrained by 3 pegs. There is no force on either end to bend the spline beyond the last pegs, which results in a at shape (zero curvature). This is why the S = 0 end conditions are called natural.
November 1, 2012
Cubic Splines
MACM 316
8/15
= = =
b0 = A A= y1 y0 h0 h0 2 m0 h0 6 (m1 m0) A
2h0m0 + h0m1 = 6
y1 y0 h0
and
Sn 1 (xn ) = B
hn1mn1 + 2hn1mn = 6 B
November 1, 2012
Cubic Splines
MACM 316
9/15
and
these conditions
h1(m1 m0 ) = h0(m2 m1) and hn1(mn1 mn2) = hn2(mn mn1) The matrix in this case is
h1 h0 + h1 h0 0 . . h0 2(h0 + h1 ) h1 0 . . . 0 h1 2(h1 + h2 ) h2 0 . . . . . . .. .. .. 0 . 0 0 0 hn2 2(hn2 + hn1 ) hn1 0 hn1 hn2 + hn1 hn2
and the rst/last RHS entries are zero. Note: Matlabs spline function implements the not-a-knot condition (by default) as well as the clamped spline, but not the natural spline. Why not? (see Homework #4).
November 1, 2012
Cubic Splines
MACM 316
10/15
5. On each subinterval xi x xi+1, construct the function gi (x) = ai + bi(x xi) + ci(x xi)2 + di (x xi)3
November 1, 2012
Cubic Splines
MACM 316
11/15
1.5881 33.0139 [4.35, 4.57] 34.8675 [4.57, 4.76] 2.4541 [4.76, 5.26] 1.8035 [5.26, 5.88]
Then the spline functions are easy to read off, for example:
S2 (x) = 6.57 + 0.7900(x 4.57) 20.2010(x 4.57)2 + 34.8675(x 4.57)3 S3 (x) = 6.23 3.1102(x 4.76) 0.3266(x 4.76)2 + 2.4541(x 4.76)3
Exercise: Verify that S2 and S3 satisfy the conditions dening a cubic spline.
November 1, 2012 c Steven Rauch and John Stockie
Cubic Splines
MACM 316
12/15
a1 4.5143
a2
a3
a4
a5
-1.5402 -15.3862 -13.2337 13.1562 -1.2616 2.6331 2.1878 -6.8778 22.6527 -15.7077
November 1, 2012
Cubic Splines
MACM 316
13/15
xi y i = a i bi S0(x) 4.00 4.19 1.0000 S1(x) 4.35 S2(x) 4.57 S3(x) 4.76 S4(x) 5.26 5.77 6.57 6.23 4.90 5.9937
ci di Interval 27.2832 32.9375 [4.00, 4.35] 7.3011 15.5191 [4.35, 4.57] 28.1431 [4.57, 4.76] 4.7277 [4.76, 5.26] 6.8363 [5.26, 5.88]
Exercise: Verify that the spline satises the clamped end conditions:
S0 (4.00) = 1.0 and S4 (5.88) = 2.0.
November 1, 2012 c Steven Rauch and John Stockie
Cubic Splines
MACM 316
14/15
Comparison
Below is a comparison of the splines with various endpoint conditions:
7 6.5 6 5.5 5 4.5 4 4 y Natural Clamped NotAKnot
4.5 x
5.5
November 1, 2012
Cubic Splines
MACM 316
15/15
Second Example
Consider the following data representing the thrust of a model rocket versus time.
t 0.00 0.05 0.10 0.15 0.20 0.30 0.40 0.50 T 0.00 1.00 5.00 15.00 33.50 33.00 16.50 16.00 t 0.60 0.70 0.80 0.85 0.90 0.95 1.00 T 16.00 16.00 16.00 16.00 6.00 2.00 0.00
Notice how wiggles are introduced near the ends of the at region non-smooth data cause some problems for cubic splines.
November 1, 2012 c Steven Rauch and John Stockie