You are on page 1of 10

SPLINE INTERPOLATION Spline Background • Problem: high degree interpolating polynomials often have extra oscillations. 1 , x ∈ [−1, 1].

Example: “Runge” function f (x) = 1+4 x2
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

0.2

0.4

0.6

0.8

1

• Piecewise Polynomials provide alternative to high degree polynomials: approximation interval [a, b] is subdivided into pieces [x1, x2], [x2, x3], . . . , [xn−1, 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 )+(x−xj ) , if x ∈ [xj , xj +1] xj +1 − xj • Splines are piecewise polynomial approximations, connected at xj ’s with various continuity conditions.

. . . a) S (x) is composed of cubic polynomial pieces Sj (x) S (x) = Sj (x) if x ∈ [xj . . 2 . . . . . b]). (x2. n − 1 (S ∈ C 2[a. • Properties of Cubic Interpolating Spline S (x). condition a) provides 4(n − 1) free parameters. . n − 1. f) two end conditions: examples i) S (x1) = S (xn) = 0 (natural or free spline). b)-f) give n + 3(n − 2) + 2 = 4(n − 1) constraints. . . y2). . Sn−2(xn−1) = Sn−1(xn−1) (not-a-knot). b) S (xj ) = yj . j = 2. b]). n − 1 (S ∈ C 1[a. ii) S (x1) = f (x1). iv) S1 (x2) = S2 (x2). . j = 2. . . xj +1]. 2. . b]). d) Sj −1(xj ) = Sj (xj ). j = 1. e) Sj −1(xj ) = Sj (xj ). n − 1 (S ∈ C [a. j = 1. S (xn) = f (xn) (complete or clamped spline). . iii) S1 = Sn−1 = 0 (parabolically terminated). Note: if Sj (x) = aj + bj (x − xj ) + cj (x − xj )2 + dj (x − xj )3. y1). . j = 2.CUBIC SPLINE INTERPOLATION Cubic Interpolating Splines for a = x1 < · · · < xn = b with given data (x1. . . . (xn. . . . n. yn). (interpolation) c) Sj −1(xj ) = Sj (xj ).

(3.CUBIC SPLINE INTERPOLATION • Example: n = 3. (2.5). 1 3 ( x − 1) + ( x − 1) .2). natural. 2 4 4 3 . data (1. S1 ( x ) = 2 + 3 4 4 3 1 2 3 S2 ( x ) = 3 + 3 ( x − 2) + ( x − 2) − ( x − 2) .3).

hj +1 hj Also Sj (x) = bj + 2cj (x − xj ) + 3dj (x − xj )2. 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. implies 2cj +1 = 2cj + 6dj hj . dj hj = (cj +1 − cj )/3. hj 3 3 3∆yj +1 3∆yj − = 3∆bj +(cj +2+2cj +1)hj +1−(cj +1+2cj )hj .CUBIC SPLINE INTERPOLATION Cubic Interpolating Spline Construction • Spline Linear System: let hj = xj +1 − xj . so e) Sj +1(xj +1) = Sj (xj +1). with extra unknown cn = Sn−1(xn)/2 added. hj where ∆yj = yj +1 − yj . ∆yj = bj + cj hj + dj h2 j. implies 3 yj +1 = yj + bj hj + cj h2 + d h j j j. so d) Sj +1(xj +1) = Sj (xj +1). ∆bj = 2cj hj + (cj +1 − cj )hj = (cj +1 + cj )hj 3∆yj +1 3∆yj − = cj hj + 2cj +1(hj + hj +1) + cj +2hj +1 hj +1 hj 4 . c) Sj +1(xj +1) = Sj (xj +1). Notice Sj (x) = 2cj + 6dj (x − xj ). Then (cj +1 − cj )hj ∆yj (cj +1 + 2cj )hj = bj + cj hj + = bj + . bj +1 = bj + 2cj hj + 3dj h2 j.

bj = ∆yj /hj − cj hj − dj h2 j can be used to find remaining coefficients for Sj (x)’s. 3∆yn−2 3∆y3−2 cn−3hn−3 + 2cn−2(hn−3+hn−2) + cn−1hn−2 = − hn−2 hn−3 3∆yn−1 3∆yn−2 − cn−2hn−2 + 2cn−1(hn−2+hn−1) + cnhn−1 = hn−1 hn−2 cn = 0 . 5 . so c1 = cn = 0 Linear system equations are a “tridiagonal” system c1 = 0 3∆y2 3∆y1 c1h1 + 2c2(h1+h2) + c3h2 = − h2 h1 3∆y3 3∆y2 − c2h2 + 2c3(h2+h3) + c4h3 = h3 h2 . a simpler tridiagonal system. dj = (cj +1 − cj )/(3hj ).CUBIC SPLINE INTERPOLATION • Natural Splines: S (x1) = S (xn) = 0. . . . which can be solved uniquely for cj ’s with O(n) work. Note: if all hj = h.

natural.3).1 −1 −0.6 −0. 1 3 S1(x) = 2 + (x − 1) + (x − 1)3. x ∈ [−1.2).4 0.7 0.8 0. with data (1.2 0 0. ∆y2 = 2.8 1 6 . so c2 = 3/4.4 −0.CUBIC SPLINE INTERPOLATION • Example: n = 3.4 0. d2 = −1/4.2 0. x2 1/(1+4x2).5 0.2 0. (3. 2 4 4 1 • Example: “Runge” function f (x) = 1+4 .6 0. so h1 = h2 = 1.3 0. S(x) and P4(x) 1 0. Only one equation 2c2(1 + 1) = 3(2 − 1). 4 4 3 3 1 2 S2(x) = 3 + (x − 2) + (x − 2) − (x − 2)3. b2 = 2 − 3/4 + 1/4 = 3/2. b1 = 1 − 0 − 1/4 = 3/4. ∆y1 = 1.5). d1 = 1/4.8 −0.9 0. 1].6 0. (2.

and yn−1 cn−1hn−1 + 2cnhn−1 = 3yn − 3∆ hn−1 . . 3yn − hn−1 which can be solved (uniquely) for cj ’s with O(n) work. S (xn) = yn. yn = bn−1 + 2cn−1hn−1 + 3dn−1h2 n−1 ∆yj (cj +1 +2cj )hj Using hj = bj + . so y1 = b1. dj = (cj +1 − cj )/(3hj ).CUBIC SPLINE INTERPOLATION • Clamped Splines: let S (x1) = y1. 3hj dj = (cj +1 − cj ). 3∆yn−1 3∆yn−2 − hn−1 hn−2 3∆yn−1 . . cn−2hn−2 + 2cn−1(hn−2+hn−1) + cnhn−1 = cn−1hn−1 + 2cnhn−1 = 3∆y1 − 3y1 h1 3∆y2 3∆y1 − h2 h1 . 3 “1st” and “nth” equations become y1 2c1h1 + c2h1 = 3∆ h1 − 3y1 . bj = ∆yj /hj − cj hj − dj h2 j can be used to find remaining coefficients for Sj (x)’s. Linear system equations are a “tridiagonal” system 2c1h1 + c2h1 = c1h1 + 2c2(h1+h2) + c3h2 = . 7 .

2). 8 . c1 = c2.5). b1 = 1. bj = ∆yj /hj − cj hj − dj h2 j can be used to find remaining coefficients for Sj (x)’s. b2 = 2−1+1/2 = 3/2. cn−1 = cn. c2 + 2c3 = 6 − 3(2) = 0. (2. Three equations: 2c1 + c2 = 3(2 − 1) − 3 = 0. Linear system equations are a “tridiagonal” system c1 − c2 = 0 3∆y2 3∆y1 c1h1 + 2c2(h1+h2) + c3h2 = − h2 h1 . c1 + 4c2 + c3 = 3. 1 2 3 ( x − 1) + ( x − 1) . dj = (cj +1 − cj )/(3hj ). . d2 = −1/2. S1(x) = 2 + (x − 1) − 1 2 2 1 2 3 S2 ( x ) = 3 + 3 ( x − 2) + ( x − 2) − 2 2 (x − 2) . so d1 = dn−1 = 0. d1 = 1/2. and y1 = 1. y3 = 2.CUBIC SPLINE INTERPOLATION • Example: n = 3. with data (1. c2 = 1. (3. clamped. . . so c1 = c3 = −1/2. which can be solved (uniquely) for cj ’s with O(n) work.3). • Parabolically Terminated Splines: S1 = Sn−1 = 0. 3∆yn−1 3∆yn−2 cn−2hn−2 + 2cn−1(hn−2+hn−1) + cnhn−1 = − hn−1 hn−2 cn−1 − cn = 0.

(cn−1 − cn−2)/hn−2 = (cn − cn−1)/hn−1. Then (c2 − c1)/h1 = (c3 − c2)/h2.CUBIC SPLINE INTERPOLATION • Not-a-Knot Splines: S1 (x2) = S2 (x2). . so “1st” and “nth” equations become c1h2 − c2(h1 + h2) + c3h1 = 0 cn−2hn−1 − cn−1(hn−2 + hn−1) + cnhn−2 = 0. . and S1 = S2. Sn−2 = Sn−1. 3∆yn−1 3∆yn−2 cn−2hn−2 + 2cn−1(hn−2+hn−1) + cnhn−1 = − hn−1 hn−2 cn−2hn−1 − cn−1(hn−2 + hn−1) + cnhn−2 = 0. which can be solved (uniquely) for cj ’s with O(n) work. so d1 = d2. Linear system equations are a “tridiagonal” system c1h2 − c2(h1 + h2) + c3h1 = 0 3∆y2 3∆y1 − c1h1 + 2c2(h1+h2) + c3h2 = h2 h1 . dn−2 = dn−1. dj = (cj +1 − cj )/(3hj ). 9 . Sn−2(xn−1) = Sn−1(xn−1). . bj = ∆yj /hj − cj hj − dj h2 j can be used to find remaining coefficients for Sj (x)’s.

and S (x) is the unique clamped spline for f (x) with nodes a = x1 < x2 · · · < xn = b. find interval x ∈ [xj . then |f (x) − S (x)| ≤ 5M max h4 j. xj +1] in O(log(n)) time and evaluate Sj (x) in O(1) time. b].CUBIC SPLINE INTERPOLATION Efficient Spline Evaluation • Setup: solve linear system for cj ’s in O(n) time • For each evaluation point x. Error Theorem : if f ∈ C 4[a.b] |f (4)(x)| = M . 1 ≤ j<n 384 10 . 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 ). with maxx∈[a. hj 3 hj +1 3 • Compare with polynomial interpolation. where setup time is O(n2) and evauation time is O(n).