1 1/ (1+4x) and P (X) and P (X)
1 1/ (1+4x) and P (X) and P (X)
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) Sj 1(xj ) = Sj (xj ), j = 2, . . . , n 1 (S C [a, b]). d) Sj 1(xj ) = Sj (xj ), j = 2, . . . , n 1 (S C 1[a, b]). e) Sj 1(xj ) = Sj (xj ), j = 2, . . . , n 1 (S C 2[a, b]). f) two end conditions: examples i) S (x1) = S (xn) = 0 (natural or free spline); ii) S (x1) = f (x1), S (xn) = f (xn) (complete or clamped spline); iii) S1 = Sn1 = 0 (parabolically terminated); iv) S1 (x2) = S2 (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.
1 3 ( x 1) + ( x 1) , S1 ( x ) = 2 + 3 4 4 3 1 2 3 S2 ( x ) = 3 + 3 ( x 2) + ( x 2) ( x 2) , 2 4 4
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
3 yj +1 = yj + bj hj + cj h2 + d h j j j;
yj = bj + cj hj + dj h2 j, hj
where yj = yj +1 yj . Notice Sj (x) = 2cj + 6dj (x xj ), so e) Sj +1(xj +1) = Sj (xj +1), implies 2cj +1 = 2cj + 6dj hj ; dj hj = (cj +1 cj )/3, 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 Sj (x) = bj + 2cj (x xj ) + 3dj (x xj )2, so d) Sj +1(xj +1) = Sj (xj +1); bj +1 = bj + 2cj hj + 3dj h2 j; 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 (x1) = S (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 h2 j can be used to nd remaining coecients 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+4 , x [1, 1]. x2
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 (x1) = y1, S (xn) = yn, so y1 = b1, yn = bn1 + 2cn1hn1 + 3dn1h2 n1 yj (cj +1 +2cj )hj Using hj = bj + , 3hj dj = (cj +1 cj ), 3 1st and nth equations become y1 2c1h1 + c2h1 = 3 h1 3y1 , and yn1 cn1hn1 + 2cnhn1 = 3yn 3 hn1 . Linear system equations are a tridiagonal system 2c1h1 + c2h1 = c1h1 + 2c2(h1+h2) + c3h2 = . . cn2hn2 + 2cn1(hn2+hn1) + cnhn1 = cn1hn1 + 2cnhn1 = 3y1 3y1 h1 3y2 3y1 h2 h1 . . 3yn1 3yn2 hn1 hn2 3yn1 . 3yn hn1
which can be solved (uniquely) for cj s with O(n) work; dj = (cj +1 cj )/(3hj ), bj = yj /hj cj hj dj h2 j can be used to nd remaining coecients for Sj (x)s.
CUBIC SPLINE INTERPOLATION Example: n = 3, clamped, with data (1,2), (2,3), (3,5), and y1 = 1, y3 = 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. 1 2 3 ( x 1) + ( x 1) , S1(x) = 2 + (x 1) 1 2 2 1 2 3 S2 ( x ) = 3 + 3 ( x 2) + ( x 2) 2 2 (x 2) , Parabolically Terminated Splines: S1 = 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 h2 j can be used to nd remaining coecients for Sj (x)s.
CUBIC SPLINE INTERPOLATION Not-a-Knot Splines: S1 (x2) = S2 (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 h2 j can be used to nd remaining coecients for Sj (x)s.
CUBIC SPLINE INTERPOLATION Ecient Spline Evaluation Setup: solve linear system for cj s in O(n) time For each evaluation point x, nd 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)| 5M max h4 j. 1 j<n 384
10