This action might not be possible to undo. Are you sure you want to continue?

**Sky McKinley and Megan Levine Math 45: Linear Algebra
**

Abstract. An introduction into the theory and application of cubic splines with accompanying Matlab m-file cspline.m

Introduction

Real world numerical data is usually difficult to analyze. Any function which would effectively correlate the data would be difficult to obtain and highly unwieldy. To this end, the idea of the cubic spline was developed. Using this process, a series of unique cubic polynomials are fitted between each of the data points, with the stipulation that the curve obtained be continuous and appear smooth. These cubic splines can then be used to determine rates of change and cumulative change over an interval. In this brief introduction, we will only discuss splines which interpolate equally spaced data points, although a more robust form could encompass unequally spaced points.

Theory

The fundamental idea behind cubic spline interpolation is based on the engineer’s tool used to draw smooth curves through a number of points. This spline consists of weights attached to a flat surface at the points to be connected. A flexible strip is then bent across each of these weights, resulting in a pleasingly smooth curve. The mathematical spline is similar in principle. The points, in this case, are numerical data. The weights are the coefficients on the cubic polynomials used to interpolate the data. These coefficients ’bend’ the line so that it passes through each of the data points without any erratic behavior or breaks in continuity.

Process

The essential idea is to fit a piecewise function of the form s 1 ÝxÞ SÝxÞ = s 2 ÝxÞ if if _ s n?1 ÝxÞ if where s i is a third degree polynomial defined by s i ÝxÞ = a i Ýx ? x i Þ 3 + b i Ýx ? x i Þ 2 + c i Ýx ? x i Þ + d i for i = 1, 2, ..., n ? 1. The first and second derivatives of these n ? 1 equations are fundamental to this process, and they are (2) x n?1 ² x < x n x1 ² x < x2 x2 ² x < x3 (1)

1

. n ? 1. 2. The piecewise function SÝxÞ will interpolate all data points. (3) (4) The Four Properties of Cubic Splines 1.. to make the curve smooth across the interval. 3... the derivatives must be equal at the data points. x n à S v ÝxÞ will be continuous on the interval ßx 1 . we have d i = a i?1 h 3 + b i?1 h 2 + c i?1 h + d i?1 (10) (9) for i = 2. n ? 1. so s i Ýx i Þ = s i?1 Ýx i Þ for i = 2. 3. s vi Ýx i Þ = s vi?1 Ýx i Þ (11) .2 s vi ÝxÞ = 3a i Ýx ? x i Þ 2 + 2b i Ýx ? x i Þ + c i s vv ÝxÞ = 6a i Ýx ? x i Þ + 2b i i for i = 1. s i Ýx i Þ = d i and s i?1 Ýx i Þ = a i?1 Ýx i ? x i?1 Þ + b i?1 Ýx i ? x i?1 Þ + c i?1 Ýx i ? x i?1 Þ + d i?1 3 2 (7) (8) so d i = a i?1 Ýx i ? x i?1 Þ 3 + b i?1 Ýx i ? x i?1 Þ 2 + c i?1 Ýx i ? x i?1 Þ + d i?1 for i = 2. it can be concluded that each sub-function must join at the data points. 4.. x n à Since the piecewiece function SÝxÞ will interpolate all of the data points.... 2.. Our spline will need to conform to the following stipulations.. . . SÝx i Þ = s i Ýx i Þ and we can use equation (2) to produce y i = s i Ýx i Þ y i = a i Ýx i ? x i Þ + b i Ýx i ? x i Þ + c i Ýx i ? x i Þ + d i 3 2 (5) (6) yi = di for each i = 1. 3. Since the curve SÝxÞ must be continuous across its entire interval. .. 2. n ? 1.. SÝxÞ will be continuous on the interval ßx 1 .. Letting h = x i ? x i?1 in equation (8). From equation (2). that is. Since x i 5 ßx i . n. n ? 1. n ? 1... . .. we can conclude that SÝx i Þ = y i for i = 1.. . x i+1 à. 3. 2. Also. x n à S vv ÝxÞ will be continuous on the interval ßx 1 ..

Lastly.. since s vv ÝxÞ has to be continuous across the interval. Each b i can be represented by s vv Ýx i Þ = 2b i i M i = 2b i bi = Mi 2 and d i has already been determined to be di = yi. s vi Ýx i Þ = c i and s vi?1 Ýx i Þ = 3a i?1 Ýx i ? x i?1 Þ 2 + 2b i?1 Ýx i ? x i?1 Þ + c i?1 so c i = 3a i?1 Ýx i ? x i?1 Þ 2 + 2b i?1 Ýx i ? x i?1 Þ + c i?1 . n ? 2. n ? 1. and d i a much easier task. 2. From equation (4). letting h = x i+1 ? x i and using the conclusion from equations (14) and (16). This and equation (14) lead us to the equation s vv Ýx i+1 Þ = 6a i Ýx i+1 ? x i Þ + 2b i i s vv Ýx i+1 Þ i+1 = 6a i Ýx i+1 ? x i Þ + 2b i and. so i s vv ÝxÞ = 6a i Ýx ? x i Þ + 2b i i s vv Ýx i Þ = 6a i Ýx i ? x i Þ + 2b i i s vv Ýx i Þ = 2b i i for i = 2. using equation a i can be re-written as (20) (19) . b i . 3.3 However. This makes the determination of the weights a i. s vv Ýx i Þ = s vv Ýx i Þ for i+1 i i i = 1. we arrive at c i = 3a i?1 h 2 + 2b i?1 h + c i?1 for i = 2. by equation (3). u. s vv ÝxÞ = 6a i Ýx ? x i Þ + 2b i . Again. c i . s vv Ýx i+1 Þ = 6a i Ýx i+1 ? x i Þ + 2b i i+1 2b i+1 = 6a i h + 2b i (17) (18) (15) (16) (14) (13) (12) These equations can be much simplified by substituting M i for s vv Ýx i Þ and expressing the i above equations in terms of M i and y i . 3... `. n ? 1. Similarly. . letting h = x i ? x i?1 . 3.

4 2b i+1 = 6a i h + 2b i 6a i h = 2b i+1 ? 2b i a i = 2b i+1 ? 2b i 6h M i+1 2Ý 2 Þ ? 2Ý M i Þ 2 ai = 6h a i = M i+1 ? M i 6h and c i can be re-written as d i+1 = a i h 3 + b i h 2 + c i h + d i c i h = ?a i h ? b i h ? d i + d i+1 3 2 c i = ?a i h ? b i h ? d i + d i+1 h ?a i h 3 ? b i h 2 + ?d i + d i+1 ci = h h d i ? d i+1 2 c i = Ý?a i h ? b i hÞ ? h M i+1 ? M i h 2 + M i hÞ ? y i ? y i+1 c i = ?Ý 2 6h h y i+1 ? y i M i+1 ? M i h + 3M i hÞ ci = ?Ý 6 6 h y i+1 ? y i M i+1 ? M i + 3M i Þh ?Ý ci = 6 h y i+1 ? y i M i+1 + 2M i Þh. ci = ?Ý 6 h 3 2 (21) (22) We now have our equations for determining the weights for our n ? 1 equations a i = M i+1 ? M i 6h Mi bi = 2 y i+1 ? y i ci = ? Ý M i+1 + 2M i Þh 6 h di = yi These systems can be handled more conveniently by putting them into matrix form as follows (23) .

and is therefore under-determined. The matrix for determining the M 1 ? M n values can be adapted accordingly. n ? 1 which leads to the matrix equation M1 1 0 0 0 0 0 4 1 0 0 0 0 1 4 1 0 0 0 0 1 4 0 0 0 ` 0 ` 0 ` 0 ` 4 ` 1 ` 0 0 0 0 1 4 1 0 0 0 0 1 4 0 0 0 0 0 1 M2 M3 M4 _ M n?3 M n?2 M n?1 Mn = 62 h y 1 ? 2y 2 + y 3 y 2 ? 2y 3 + y 4 y 3 ? 2y 4 + y 5 _ y n?4 ? 2y n?3 + y n?2 y n?3 ? 2y n?2 + y n?1 y n?2 ? 2y n?1 + y n (25) _ _ _ _ b _ _ _ _ Note that this system has n ? 2 rows and n columns. two other conditions must be imposed upon the system. 3.5 c i+1 = 3a i h 2 + 2b i h + c i y ? yi ? Ý M i+1 + 2M i Þh 3Ý M i+1 ? M i Þh 2 + 2Ý M i Þh + i+1 2 6 h 6h 3Ý M i+1 ? M i Þh 2 + 2Ý M i Þh ? Ý M i+1 + 2M i Þh + Ý M i+2 + 2M i+1 Þh 2 6 6 6h 3M i+1 ? 3M i + 6M i ? Ý M i+1 + 2M i Þ + Ý M i+2 + 2M i+1 ÞÞ hÝ 6 6 6 6 h ÝM i + 4M i+1 + M i+2 Þ 6 = = = = (24) y i+2 ? y i+1 M i+2 + 2M i+1 Þh ?Ý 6 h y i+1 ? y i y i+2 ? y i+1 ?Ý Þ+ h h y i ? 2y i+1 + y i+2 h y i ? 2y i+1 + y i+2 h y i ? 2y i+1 + y i+2 6Ý Þ h2 M i + 4M i+1 + M i+2 = for i = 1. In order to generate a unique cubic spline. `. (26) . M1 = Mn = 0 This results in the spline extending as a line outside the endpoints. 2. Three types of Splines Natural splines This first spline type includes the stipulation that the second derivative be equal to zero at the endpoints. This leads us to our next section.

The spline is now unique. which are both 0. = 62 h y 1 ? 2y 2 + y 3 y 2 ? 2y 3 + y 4 y 3 ? 2y 4 + y 5 _ y n?4 ? 2y n?3 + y n?2 y n?3 ? 2y n?2 + y n?1 y n?2 ? 2y n?1 + y n _ _ _ _ b _ _ _ _ _ _ _ b _ _ _ .6 0 1 0 0 0 0 0 0 1 0 0 0 0 0 4 1 0 0 0 0 1 4 0 0 0 ` 0 ` 0 ` 0 ` 4 ` 1 ` 0 0 0 0 1 4 0 0 0 0 0 1 0 0 0 0 0 0 1 M2 M3 M4 _ M n?3 M n?2 M n?1 0 (27) For reasons of convenience. the first and last columns of this matrix can be eliminated. 4 1 0 0 0 0 1 4 1 0 0 0 0 1 4 0 0 0 ` 0 ` 0 ` 0 ` 4 ` 1 ` 0 0 0 0 1 4 1 0 0 0 0 1 4 M2 M3 M4 _ M n?3 M n?2 M n?1 = 62 h y 1 ? 2y 2 + y 3 y 2 ? 2y 3 + y 4 y 3 ? 2y 4 + y 5 _ y n?4 ? 2y n?3 + y n?2 y n?3 ? 2y n?2 + y n?1 y n?2 ? 2y n?1 + y n (28) This results in an n ? 2 by n ? 2 matrix. which will determine the remaining solutions for M 2 through M n?1 . as they correspond to the M 1 and M n values.

The matrix equation for this type of spline is ` 0 ` 0 ` 0 ` 4 ` 1 ` 0 y 1 ? 2y 2 + y 3 y 2 ? 2y 3 + y 4 y 3 ? 2y 4 + y 5 = 62 h _ y n?4 ? 2y n?3 + y n?2 y n?3 ? 2y n?2 + y n?1 y n?2 ? 2y n?1 + y n (30) We can now determine the values for M 2 through M n?1 . with the values for M 1 and M n already determined.5 1 1. M 1 and M n . This type of cubic spline is useful for periodic and exponential data.5 5 5.7 10 5 0 -5 -1 0 -1 5 -2 0 0. M1 = M2 M n = M n?1 The result of this condition is the curve becomes a parabolic curve at the endpoint. Natural interpolating curve Parabolic Runout Spline The parabolic spline imposes the condition that the second derivative at the endpoints.5 4 4.5 3 3. be equal to M 2 and M n?1 respectively.5 Figure 1.5 2 2. (29) 5 1 0 0 0 0 1 4 1 0 0 0 0 1 4 0 0 0 0 0 0 1 4 1 0 0 0 0 1 5 M2 M3 M4 _ M n?3 M n?2 M n?1 _ _ _ b _ _ _ .

8 10 0 -1 0 -2 0 -3 0 -4 0 -5 0 -6 0 0 1 2 3 4 5 6 Figure 2. rather than two separate functions. It assigns M 1 to be 2M 2 ? M 3 and M n to be 2M n?1 ? M n?2 . Cubic Runout Spline This last type of spline has the most extreme endpoint behavior. This causes the curve to degrade to a single cubic curve over the last two intervals. The matrix equation for this type is 6 1 0 0 0 0 0 4 1 0 0 0 0 1 4 0 0 0 ` 0 ` 0 ` 0 ` 4 ` 1 ` 0 0 0 0 1 4 0 0 0 0 0 1 6 M2 M3 M4 _ M n?3 M n?2 M n?1 = 62 h y 1 ? 2y 2 + y 3 y 2 ? 2y 3 + y 4 y 3 ? 2y 4 + y 5 _ y n?4 ? 2y n?3 + y n?2 y n?3 ? 2y n?2 + y n?1 y n?2 ? 2y n?1 + y n (31) _ _ _ b _ _ _ . Parabolic Runout curve Note that the endpoint behavior is a bit more extreme than with the natural spline option.

Curve Fitting with Splines The main application of cubic spline interpolation techniques is. however. Thus. of course. The three discussed in this work are simply the ones which we have chosen to examine. For example. the following figure was generated using the function y = sinÝxÞ.9 20 0 -2 0 -4 0 -6 0 -8 0 -1 0 0 -1 2 0 -1 4 0 -1 6 0 0 1 2 3 4 5 6 Figure 3. Function Imitation Cubic splines would not be necessary were it simple to determine a well-behaved function to fit any data set. the consistency and efficiency of the spline as a data correlation tool will be demonstrated. Cubic Runout curve Note the pronounced curvature at the endpoints. Keep in mind that there are many other types of interpolating spline curves. Moreover. curve fitting. This is testimony to the consistency of splines. such as the Periodic Spline and the Clamped Spline. they are not intrinsically superior to. This is. or more widely used than these other types of splines. . the cubic spline technique is used to generate a function to fit the data. To this end. it can be shown that data generated by a particular function is interpolated by a spline which behaves more or less like the original function. usually not the case.

2 0 -0 . 8 -1 -4 -3 -2 -1 0 1 2 3 4 Figure 4. .2 0 -0 .6 0. 8 -1 -3 -2 -1 0 1 2 3 Figure 5. Spline through six points on a sine curve.4 0.10 1 0. we can see the degree to which the cubic curve imitates the original function y = sinÝxÞ. 2 -0 . 4 -0 .8 0. 6 -0 . 1 0.6 0. This next figure was generated by connecting six data points along the above line with a cubic spline function.4 0. The graph of y = sinÝxÞ. By superimposing Figure 5 on Figure 4. 6 -0 . 4 -0 .8 0. 2 -0 .

2 -0 . Take for instance the function below. It has no extreme behavior between data points.2 0 -0 .6 0. . and it effectively correlates the points. 8 -1 -3 -2 -1 0 1 2 3 Figure 6.8 0. This characteristic also works with more erratic functions. Clearly. the cubic curve closely imitates the sine curve.4 0. Superimposition of a spline curve on a sine function.11 1 0. 6 -0 . 4 -0 .

Take. 6 -0 . . it does closely approximate the function without a great degree of divergence.12 1 0. A cubic spline approximation of ßsinÝxÞ + cosÝxÞà 4 .6 0.8 0. 3 Data interpretation The splines other strength lies in its ability to correlate data which doesn’t follow any specific pattern without a single polynomial’s extreme behavior.4 0. the 100 random data points below. 2 -0 . for instance. 4 -0 .2 0 -0 . While the fit is not perfect. 8 -6 -4 -2 0 2 4 6 Figure 7.

6 0.1 0.3 0. 2 0 0.4 0.9 0.3 0. a much more reasonable range than an approximating polynomial.8 0. can interpolate all 100 points without the drastic behavior that the necessary 99th degree polynomial would exhibit.8 0. its range stays from 0 to 1. however. Also.4 0. .2 0.6 0.2 0 -0 .7 0.9 1 Figure 8.1 0 0 0.5 0.8 0.6 0.5 0. Cubic curve through the random data. Random data points Clearly there is no relation between these data points.2 1 0.7 0. 1. A spline.2 0. while the spline is not exactly pleasing to the eye.13 1 0.9 1 Figure 9.5 0.8 0. Note that.7 0.2.3 0.4 0.6 0. it is not much of a task to generate an approximating spline which generally correlates the data while being much more well behaved.4 0.1 0.2 0.

14 1 0.3 0. no matter how random the data may seem. Cubic Splines and Matlab All of the graphics in this paper were generated using a cubic spline m-file and Matlab software.8 0.6 0. MA: COMAP .redwoods.4 0.9 1 Figure 10.3 0.4 0.6 0. interpolating data with a spline becomes an easy task.2 0. Its curvature is much less severe than that of fig 9. Approximating cubic curve The above figure demonstrates the general trends in the data (of which there are none) without necessarily connecting all data points.5 0.9 0.1 0. Mastering Matlab 5.8 0. Splines correlate data efficiently and effectively.cc.us/instruct/darnold/laproj/fall98/Skymeg Conclusion Cubic spline interpolation is a powerful data analysis tool. Duane and Bruce Littlefield.7 0.5 0.2 0. Splines in Single and Multivariable Calculus. Yves. Once the algorithm for spline generation is produced. 1998 New Jersey: Prentice Hall Nievergelt. 1993.7 0. Lexington. Bibliography Hanselman. UMAP: Module 718.1 0 0 0.ca. The m-file used is available for download at http://online.

1997 New Jersey: Prentice Hall . Applications of Linear Algebra 3ed. Van Loan. 1984 New York: John Wiley and Sons.15 Rorres. Introduction to Scientific Computing. Charles F. Chris and Howard Anton.

- splines
- Cubic Spline Tutorial
- Spline Interpolation En
- Matlab Tutorial5
- books by Dr. Prasanna chandra
- Curve Survey
- Cubic Spline Interpolation Smoothing
- sammath..
- Book
- Hermite
- Biarcs
- Lagrange Text
- 2601ch3c
- curve fitting
- 05 Interpolation
- Num Chapter 3-2014
- Chapter 6
- Chapter 8 - Interpolation
- Interpolation
- spline
- Interpolation
- 97nach4
- Untitled
- Computer Computation - Chapter4-1
- Piecewise Polynomial Interpolation
- Polynomial Interpolation
- Interpolation
- Cubic Spline Interpolation

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd