You are on page 1of 9

LECTURE NOTES - SPLINE INTERPOLATION

DR MAZHAR IQBAL

1. Introduction A cubic spline yields a third-degree polynomial connecting each pair of data points. The slopes and curvatures of the cubic splines can be forced to be continuous at each data point. In fact, these requirements are necessary to obtain the additional conditions required to t a cubic polynomial to two data points. Higher-degree splines can be dened in a similar manner. However, cubic splines have proven to be a good compromise between accuracy and complexity. Consequently, the concept of cubic splines is developed in this section. The name spline comes from the thin exible rod, called a spline, used by draftsmen to draw smooth curves through a series of discrete points. The spline is placed over the points and either weighted or pinned at each point. Due to the exure properties of a exible rod (typically of rectangular cross section), the slope and curvature of the rod are continuous at each point. A smooth curve is then traced along the rod, yielding a spline curve.

2. Construction

Denition
For a given set of data points (xk , yk ), k = 0 : N , the cubic spline s(x) consists of N cubic polynomial sk (x), s assigned to each subinterval satisfying certain constraints. We dene cubic spline as a function S(x) = Sj (x) on interval [xj , xj+1 ] for n = 0, 1, . . . , n 1 dened as (2.1) Sj (x) = aj + bj (x xj ) + cj (x xj )2 + dj (x xj )3

and the requirements


1

DR MAZHAR IQBAL

(2.2) (2.3) (2.4) (2.5) (2.6)

Sj (xj ) Sn1 (xn ) Sj (xj+1 ) Sj (xj+1 ) Sj (xj+1 )

= yj , = yn

j = 0, 1, . . . , n 1,

= Sj+1 (xj+1 ) = = Sj+1 (xj+1 ) Sj+1 (xj+1 )

Construction
From condition 2.2 we get Sj (xj ) = aj yj = aj for i = 0, 1, . . . n 1 The

equation 2.1 for the node j + 1 can be written as (2.7) Sj+1 (x) = aj+1 + bj+1 (x xj+1 ) + cj+1 (x xj+1 )2 + dj+1 (x xj+1 )3

If we evaluate this on node xj+1 we get (2.8) and (2.9) Sj (xj+1 ) = aj + bj (xj+1 xj ) + cj (xj+1 xj )2 + dj (xj+1 xj )3 Sj+1 (xj+1 ) = aj+1

if we write hj = xj+1 xj the above equation can be written as (2.10) Sj (xj+1 ) = aj + bj hj + cj h2 + dj h3 j j

By invoking the condition 2.4 we get (2.11) or (2.12) yj+1 = yj + bj hj + cj h2 + dj h3 j j aj+1 = aj + bj hj + cj h2 + dj h3 j j

LECTURE NOTES - SPLINE INTERPOLATION

Taking derivatives of the equation 2.1 we get (2.13) (2.14) similarly (2.15) Sj+1 (x) = 2cj+1 + 6dj+1 (x xj+1 ) and xj+1 we get Sj+1 (xj+1 ) = 2cj+1 Sj (x) = bj + 2cj (x xj ) + 3dj (x xj )2 Sj (x) = 2cj + 6dj (x xj )

Evaluating the above equations at xj Sj (xj ) = 2cj Now invoking 2.6 we get &

2cj + 6dj hj = 2cj+1 dj = Let Sj (xj ) = mj and Sn1 (xn ) = mn Therefore, (2.16) and (2.17) Replacing the values of c and cj = mj 2 dj = mj+1 mj 6hj f or j = 0, 1, . . . , n 1 Sj+1 (xj+1 ) Sj (xj ) 6hj

d in equation 2.11 we get mj 2 mj+1 mj 3 h + hj 2 j 6hj

yj+1 = yj + bj hj +

DR MAZHAR IQBAL

bj hj = (yj+1 yj ) (2.18) or bj = f [xj , xj+1 ] cj hj dj h2 j Now we are left with mj s as unknowns. We now invoke condition 2.5 on sj1 and sj splines. bj = (yj+1 yj ) mj hj mj+1 hj hj 3 6 mj h2 mj+1 h2 mj h2 j j j + 2 6 6

Sj (x) = bj + 2cj (x xj ) + 3dj (x xj )2

Sj1 (x) = bj1 + 2cj1 (x xj1 ) + 3dj1 (x xj1 )2 By condition 2.5 at the common node xj we get

bj = bj1 + 2cj1 hj1 + 3dj1 h2 j1 Replacing the values of bj s, cj & dj , from equations 2.18,2.17 and 2.16, we get

the relationship between dierent mj s as

yj+1 yj 2mj + mj+1 yj yj1 2mj1 + mj mj mj 1 hj = hj1 +mj1 hj1 +3 hj1 hj 6 hj1 6 6

f [xj , xj+1 ]f [xj1 , xj ] =

2mj1 + mj mj mj 1 2mj + mj+1 hj hj1 +mj1 hj1 +3 hj1 6 6 6

LECTURE NOTES - SPLINE INTERPOLATION

2mj hj +mj+1 hj 2mj1 hj1 mj hj1 +6mj1 hj1 +3mj hj1 3mj1 hj1 = 6[f [xj , xj+1 ]f [xj1 , xj ]] (2.19) mj1 hj1 + 2(hj1 + hj )mj + mj+1 hj = 6[f [xj , xj+1 ] f [xj1 , xj ]] j = 1, 2, . . . , n 1 Now we will employ the two missing conditions. Depending upon the conditions we will have dierent splines. These are discussed in the succeeding paragraphs.

2.1. Natural Spline. If the second derivatives at the end points are set equal to zero then the resulting splines are called Natural Splines. It is the curve obtained by forcing a exible elastic rod through the data points but letting the slope at the ends be free to equilibrate to the position that minimizes the oscillatory behavior of the curve. It is useful for tting a curve to experimental data that are signicant to several signicant digits. The two boundary conditions that we apply are m0 = 0 & mn = 0.

From equation 2.19 we have For j = 1 m0 h0 + 2(h0 + h1 )m1 + h1 m2 = 6[f [x1 , x2 ] f [x0 , x1 ]] For j = 2 n 2 mj1 hj1 + 2(hj1 + hj )mj + mj+1 hj = 6[f [xj , xj+1 ] f [xj1 , xj ]] For j = n 1 mn2 hn2 + 2(hn2 + hn1 )mn1 + hn1 mn = 6[f [xn1 , xn ] f [xn2 , xn1 ]]

DR MAZHAR IQBAL

On applying m0 = 0 equations will be

& mn = 0 in the above equations resulting system of

... ... ... . . . hn2 0 0 ... . . . 2(hn2 + hn1 ) m1 m2 ... . . . mn1

h1 ... 2(h0 + h1 ) h1 2(h1 + h2 ) h2 ... ... ... . . . . . . . . . ... ... ...

6 (f [x1 x2 ] f [x0 x1 ]) ... ... ... 6 (f [xn1 xn ] f [xn2 xn1 ])

2.2. Clamped Spline. The clamped spline involves the slope at the ends. This spline can be visualized as the curve obtained when a exible elastic rod is forced to pass through the data points, and the rod is clamped at each end with a xed slope. This spline is useful to a draftsman for drawing a smooth curve through several points. In this type of cubic spline the slopes at the end points are specied. As per the formulation of the linear system to calculate mj s. We are required to nd the values of m0 & mn . These are zero in the natural spline case but here wee will have to calculate these using the given information of the rst derivative. We know that (2.20) also Sj (x) = bj + 2cj (x xj ) + 3dj (x xj )2 bj = f [xj xj+1 ] cj hj dj h2 j

LECTURE NOTES - SPLINE INTERPOLATION

(2.21) Particularly (2.22) from 2.20 we get b0

Sj (xj ) = bj

S0 (x0 ) = b0

= = =

f [x0 x1 ] c0 h0 d0 h2 0 m0 m1 m0 h0 h0 2 6 m1 m0 h0 h0 f [x0 x1 ] 3 6 f [x0 x1 ]

m0 = = 3 m1 [f [x0 x1 ] b0 ] h0 2 m1 3 [f [x0 x1 ] S0 (x0 )] h0 2

Here S (x0 ) i.e 1st derivative at the node x0 is same as the S0 (x0 ). Because, S0 (x0 ) is the spline with center at x0 . In order to calculate mn we must use S (xn ) = given

As we have n 1 splines. Therefore, Sn1 (x) will be the last spline dened in the last interval [xn1 , xn ] dened as Sn1 (x) = an1 + bn1 (x xn1 ) + cn1 (x xn1 )2 + dn1 (x xn1 )3 Sn1 (x) = bn1 + 2cn1 (x xn1 ) + 3dn1 (x xn1 )2

DR MAZHAR IQBAL

(2.23) Sn1 (xn ) = bn1 + 2cn1 hn1 + 3dn1 h2 n1

Replacing the value of bn1 in equation 2.23 we get Sn1 (xn ) = = f [xn1 xn ] cn1 hn1 dn1 h2 + 2cn1 hn1 + 3dn1 h2 n1 n1 f [xn1 xn ] + cn1 hn1 + 2dn1 h2 n1

Now replacing the values of Cn1 & dn1 we get Sn1 (xn ) = = mn = mn1 mn mn1 2 hn1 + 2 hn1 2 6hn1 mn mn1 hn1 + hn1 f [xn1 xn ] + 6 3 f [xn1 xn ] + 3 mn1 S (xn ) f [xn1xn ] hn1 n1 2

From equation 2.19 we have For j = 1 m0 h0 + 2(h0 + h1 )m1 + h1 m2 = 6[f [x1 , x2 ] f [x0 , x1 ]] replacing the value of m0 we get 2(h0 + h1 )m1 + h1 m2 = 6[f [x1 , x2 ] f [x0 , x1 ]] 3[f [x0 x1 ] S0 (x0 )] + 3 ( h0 + 2h1 )m1 + h1 m2 = 6[f [x1 , x2 ] f [x0 , x1 ]] 3[f [x0 x1 ] S0 (x0 )] 2 For j = n 1 mn2 hn2 + 2(hn2 + hn1 )mn1 + hn1 mn = 6[f [xn1 , xn ] f [xn2 , xn1 ]] m1 h0 2

LECTURE NOTES - SPLINE INTERPOLATION

Replacing the values of mn we get mn2 hn2 +2(hn2 +hn1 )mn1 = 6[f [xn1 , xn ]f [xn2 , xn1 ]]3[S (xn )f [xn1 , xn ]+ 3 mn2 hn2 +(2hn2 + hn1 )mn1 = 6[f [xn1 , xn ]f [xn2 , xn1 ]]3[S (xn )f [xn1 , xn ] 2 The resulting system of equations will be
3 ( 2 h0

mn1 hn1 2

+ 2h1 ) h1 h1 2(h1 + h2 ) ... . . . ... ... h2 ... . . . ... ... ... ... . . . hn2 0 0 ... . . .
3 (2hn2 + 2 hn1 )

m1 m2 ... . . . mn1 =

... . . . ...

6[f [x1 , x2 ] f [x0 , x1 ]] 3[f [x0 x1 ] S0 (x0 )] 6[f [x2 , x3 ] f [x1 , x2 ]] ... ... 6[f [xn1 , xn ] f [xn2 , xn1 ]] 3[S (xn ) f [xn1 , xn ]

2.3. Endpoint Curvature Adjusted Spline. Imposing the values of the second derivatives at the endpoints permits the practitioner to adjust the curvature at the endpoints. The construction of linear system for this spline is left as an exercise. References
[1] Joe D. Homan, Numerical Methods for Engineers and Scientists,2nd ed,2001, [2] Wan Y Yang, Applied Numerical Methods Using Matlab,Wiely 2005. [3] Jhon H. Mathews and Kurtis D. Fink , Numerical Methods Using Matlab, Pearson,2004. [4] Curtis F. Gerald and Patrick O. Wheatley, Applied Numerical Analysis, Pearson,2004. [5] Steven C. Cahpra and Raymond P. Canale , Numerical Methods for Engineers, 5th Ed, Macraw-Hill,2006. [6] Burden and Faires , Numerical Analysis, 8th Ed

You might also like