0% found this document useful (0 votes)
61 views10 pages

Cubic Spline Tutorial v3

Cubic splines are a popular choice for curve fitting because of ease of data interpolation, integration, differentiation, and they are normally very smooth. This tutorial will describe a computationally efficient method of constructing joined cubic spline through known data points.

Uploaded by

Sumitra Shrestha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views10 pages

Cubic Spline Tutorial v3

Cubic splines are a popular choice for curve fitting because of ease of data interpolation, integration, differentiation, and they are normally very smooth. This tutorial will describe a computationally efficient method of constructing joined cubic spline through known data points.

Uploaded by

Sumitra Shrestha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

12/9/12

Cubic Spline Tutorial v3

Upload Log In Sign Up


Search books, presentations, business, academics

Explore Documents Books - FictionBooks - Non-fictionHealth & MedicineBrochures/CatalogsGovernment DocsHow-To Guides/ManualsMagazines/NewspapersRecipes/MenusSchool Work+ all categories RecentFeatured People AuthorsStudentsResearchersPublishersGovernment & NonprofitsBusinessesMusiciansArtists & DesignersTeachers+ all categories Most FollowedPopular

Language: English

Download 0 Go BackComment Link Embed


1

of 6
Like 0

Readcast Cubic
Tw eet Share
0

Spline Tutorial

Cubic splines are a popular choice for curve fitting because of ease of data interpolation, integration, differentiation, and they are normally very smooth. This tutorial will describe a computationally efficient method of constructing joined cubic splines through known data points. As background and motivation, we will begin with a discussion of the basic cubic polynomial:
y = ax3 + bx2 + cx + d

where x is the independent variable and a, b, c, d are real numbers

OK, whats there to know? It was most likely studied in pre-University education, has three roots (real and/or imaginary), the 1st derivative is a quadratic function, the 2nd derivative is a linear function, and it can be fit to four points. Lets dig a little deeper. The general cubic polynomial has four parameters or coefficients that completely define the shape of the curve. Alternatively, we can consider a cubic polynomial as having four constraints or degrees of freedom in physical terms (i.e. points and derivatives) that determine the four x13 x12 x1 1 a y1 parameters. The constraints can be four points, which means the equation can be 3 represented in the matrix form on the left. The solution to the matrix equation is 2

x3 x3 3 x4
2

x2 2 x3 x4
2

x2 x3 x4

1 b = y 2 1 c y3 1 d

y4

the four polynomial coefficients. However,sttherend other possibilities. The are four constraints can be three points plus a 1 or 2 derivative at any arbitrary point. Or, the constraints can be two points plus two derivatives, which is actually the basis for cubic spline interpolation.

3 x12 2 x1 1 0 a y1 Lets say we wish to represent a cubic equation as two points (x 1, y1), (x2, y2) 3 2 x1 x1 1 b y1 plus first derivatives at those points (y1', y2'). How would that be done? Well, x1 = 3 2 lets first take the derivative of the cubic equation, which is y' = 3ax 2 + 2bx + x2 x2 x 2 1 c y 2 2 2 2 c. Thus, y1' = 3ax1 + 2bx1 + c and y2' = 3ax2 + 2bx2 + c. The matrix equation 2 x 2 1 0 d y 2 3 defining the associated cubic polynomial is on the right. OK. How about two x 2 points plus 2nd derivatives at the points? In that case, the equation of the 2nd 6 x1 2 0 0 a y1 derivative is needed, which is y" = 6ax + 2b. Thus, y " = 6ax + 2b and y " = 1 1 2 x 3 x 2 x 1 b y 6ax2 + 2b. The matrix equation defining the 1 1 1 1 = 3 x12 2 x1 1 0 a y1 3 2 x 2 x 2 x 2 1 c y 2 associated cubic polynomial is on the left. 3 2 st nd y1 b x1 x1 1 How about two points plus 1 and 2 x1 =
2 0 0 d y 2 derivatives at the first point? The matrix equation for that isSearch This Document be seen, there are multiple ways to on the right. As can formulate a cubic Search polynomial by specifying points and derivatives.
2

6 x

x2 6 x1
3

2 x2

x2

1 c 0 d

y2 y1

Search History: To illustrate, choose p1 = (0, 0) and p2 = (1, 1). The plots below indicate the result of using various boundary Searching... conditions at the end points to define the cubic polynomial. Result 00 of 00 00 results for result for p.

12/17/2008

Page 1 of 6

hotvette

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

1/10

12/9/12

Cubic Spline Tutorial v3

Develop Web Apps Fast


30 times faster than other tools No HTML, CSS, JavaScript, AJAX, PHP
www.realsoftware.com/web

Note the last plot (on the right). It represents the equation y = x3. We know this because for this equation, y" = 6x. Therefore y(0)" = 6(0) = 0 and y(1)" = 6(1) = 6, which match the constraints used to generate the plot. Alternate Cubic Polynomial formulation - before moving on, it is useful to consider the following (more general) form of the cubic polynomial: y = a'(x-x0)3 + b'(x-x0)2 + c'(x-x0) + d' where x0 is an arbitrary reference point for the independent variable. The superscript (i.e. ') on a, b, c, d is used to distinguish the coefficients from the previous case where xn is used instead of (x-x0)n. This form of a cubic polynomial is just as valid as the previous version and is convenient in cubic spline interpolation because if x 0 is chosen as the value of the independent variable at the beginning of the spline segment, the quantity (x-x 0) begins at zero for each segment and the result is a consistent mathematical treatment for all segments. Also, if the above expression for y is expanded and terms collected, it is easy to show that: a = a' b = b' 3a'x0 c = c' + 3a'x02 2b'x0 d = d' c'x0 + b'x02 a'x03

Clearly, if x0 is chosen as 0, the coefficients (and equations) are identical. As a simple example, consider the equation y = 2x3 + 3x2 + 4x + 5. If x0 is chosen as 1, the following equation produces the exact same result: y = 2(x-1)3 + 9(x-1)2 + 16(x-1) + 14. Checking the result for consistency: a' = 2 b' = 9 c' = 16 d' = 14 a = a' = 2 b = b' 3a'x0 = 9 3(2)(1) = 3 c = c' + 3a'x02 2b'x0 = 16 + 3(2)(1)2 2(9)(1) = 16 + 6 18 = 4 d = d' c'x0 + b'x02 a'x03 = 14 (16)(1) + (9)(1)2 (2)(1)3 = 14 16 + 9 2 = 5

Now that we can think of cubic polynomials in terms of points and derivatives, lets connect two together. Why do that? The main reason is to have a smooth curve that goes through (i.e. interpolates) a given set of points. Of course, it is possible to derive a single polynomial of degree (n-1) to fit n points, but the end result is often not satisfactory. A good example is the function y = x1/3 for x = 0 to 1. Picking four points x = (0, 0.2, 0.6, 1), the resulting cubic polynomial can be seen to wiggle too much to represent the desired function very well. This is often the case. Wait - cant the 1st or 2nd derivative be specified to force a better fit? Unfortunately, the answer is no. The reason is that all four constraints were used up by requiring the curve to interpolate four points. Remember, only four things (points, derivatives) can be specified. Continuity the concept of continuity is important in spline interpolation. If two polynomials are connected together (end point of the 1st is the beginning point of the 2nd) but no other conditions are specified, the two equations (or splines) are said to have C0 continuity, or zero derivative continuity. Though that can make some interesting plots, it doesnt result in a very smooth curve through the points. Additionally, if the 1st derivatives at the connection points are forced to be equal, the curve is said to have C1 (i.e. 1 st derivative) continuity. That makes a smoother curve, but an even smoother one can be obtained if C2 continuity (i.e. nd 2 derivative) is also enforced. The traditional implementation of cubic splines for the purpose of interpolating points uses C0, C1, and C2 continuity.
12/17/2008 Page 2 of 6 hotvette

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

2/10

12/9/12

Cubic Spline Tutorial v3

Development of Spline Equations


Consider the problem of constructing two cubic splines to fit three data points p 1 = (x1, y1), p2 = (x2, y2), p3 = (x3, y3). Refer to the last plot on the right, above. This is the simplest case of cubic spline interpolation that will illustrate the methods used in more normal cases where several points are present. The key characteristics of cubic spline interpolation are: 1. Curve passes through all specified data points (C0 continuity) 2. 1st derivative continuity (C1) at interior points 3. 2nd derivative continuity (C2) at interior points 4. Boundary conditions are specified at the free ends Begin with the equations of the two splines (using the spline starting point for x 0): spline #1 (x1 x x2) y = a1(x-x1)3 + b1(x-x1)2 + c1(x-x1) + d1 y' = 3a1(x-x1)2 + 2b1(x-x1) + c1 y" = 6a1(x-x1) + 2b1 spline #2 (x2 x x3) y = a2(x-x2)3 + b2(x-x2)2 + c2(x-x2) + d2 y' = 3a2(x-x2)2 + 2b2(x-x2) + c2 y" = 6a2(x-x2) + 2b2

For now, the focus will be on spline #1. Starting with the 2nd derivative, impose the compatibility constraints that y" = y1" at x = x1 and y" = y2" at x = x2. Defining x2-x1 as h1: y1" = 6a1(x1-x1) + 2b1 = 0 + 2b1 = 2b1 y2" = 6a1(x2-x1) + 2b1 = 6a1h1 + y1" This results in the following equation for the 2 nd derivative: y" = (x-x1)(y2"-y1")/(x2-x1) + y1" which can be verified to be correct (i.e. y " = y1" at x = x1 and y" = y2" at x = x2). Next, apply the conditions that the spline must pass though the points, in other words y 1 = f(x1) and y2 = f(x2): y1 = a1(x1-x1)3 + b1(x1-x1)2 + c1(x1-x1) + d1 = 0 + 0 + 0 + d 1 y2 = (x2-x1) (y2"-y1")/6h1 + y1"(x2-x1) /2 + c1(x2-x1) + y1 y2 = h13(y2"-y1")/6h1 + y1"h12/2 + c1h1 + y1 y2 = h12(y2"-y1")/6 + y1"h12/2 + c1h1 + y1 y2-y1 = y2"h12/6 - y1"h12/6 + y1"h12/2 + c1h1 (y2-y1)/h1 = y2"h1/6 - y1"h1/6 + y1"h1/2 + c1 (y2-y1)/h1 = y2"h1/6 - y1"h1/6 + 3y1"h1/6 + c1 (y2-y1)/h1 = y2"h1/6 + y1"h1/3 + c1
3 2

b1 = y1"/2 a1 = (y2"-y1")/6h1

d1 = y1

c1 = (y2-y1)/h1 y2"h1/6 - y1"h1/3

Finally, impose the compatibility condition that y 2' in spline #1 must equal y2' in spline #2: 3a1(x2-x1)2 + 2b1(x2-x1) + c1 = 3a2(x2-x2)2 + 2b2(x2-x2) + c2 3a1h12 + 2b1h1 + c1 = c2 h1(y2"-y1")/2 + y1"h1 + (y2-y1)/h1 - y2"h1/6 - y1"h1/3 = (y3-y2)/h2 y3"h2/6 y2"h2/3 h1(y2"-y1")/2 + y1"h1 - y2"h1/6 - y1"h1/3 + y3"h2/6 + y2"h2/3 = (y3-y2)/h2 - (y2-y1)/h1 3h1(y2"-y1") + 6y1"h1 - y2"h1 - 2y1"h1 + y3"h2 + 2y2"h2 = 6(y3-y2)/h2 - 6(y2-y1)/h1 3h1y2" 3h1y1" + 6y1"h1 - y2"h1 - 2y1"h1 + y3"h2 + 2y2"h2 = 6(y3-y2)/h2 - 6(y2-y1)/h1 y1"(6h1 3h1 2h1) + y2"(2h1 + 2h2) + y3"h2 = 6(y3-y2)/h2 - 6(y2-y1)/h1 h1y1" + 2(h1 + h2)y2" + h2y3" = 6[(y3-y2)/h2 - (y2-y1)/h1]
12/17/2008 Page 3 of 6

governing equation for cubic splines.


hotvette

DataFit Curve Fitting


Nonlinear curve fitting, 600+ built in equations, or create your own
www.CurveFitting.com

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

3/10

12/9/12

Cubic Spline Tutorial v3

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

4/10

12/9/12

Cubic Spline Tutorial v3

Interpolation in Excel
GetExcel Interpolation function As Excel Add In - XLA file.
www.excel4engineers.com

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

5/10

12/9/12

Cubic Spline Tutorial v3

Cubic Spline Tutorial v3


Download or Print Add To Collection 136 Reads 0 Readcasts 0 Embed Views

Published by Praveen Srivastava Follow


Search This Document

Search TIP Press Ctrl-FF to search anywhere in the document.

DataFit Curve Fitting


Nonlinear curve fitting, 600+ built in equations, or create your own
www.CurveFitting.com

Info and Rating


Category: Uncategorized. Rating: Upload Date: 11/30/2011 Copyright: Attribution Non-commercial Tags: This document has no tags. Free download as PDF File (.pdf), Text File (.txt) or read online for free. Flag document for inapproriate content

Download and print this document


Choose a format to download in

.PDF

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

6/10

12/9/12

Cubic Spline Tutorial v3

.TXT Download

Recommended

4 p. Cubic Spline Tutorial Michael MOuire 515 Reads

15 p. Cubic Spline Interpolation kjchauhan 1870 Reads

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

7/10

12/9/12

Cubic Spline Tutorial v3

More From This User

2 p. Jacobi Rotation Praveen Srivastava 46 Reads

10 p. Nab Ova Ti 09 Praveen Srivastava 133 Reads

76 p. master_thesis_daniel_viedma Praveen Srivastava 153 Reads

7 p. He-Luo_PRE-1997 Praveen Srivastava 68 Reads

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

8/10

12/9/12

Cubic Spline Tutorial v3

Featured

24 p. Preventing Pearl Harbor Hyperink $2.99

540 p. Avenging Pearl Harbor iUniverseBooks $9.99

71 p. Remember Pearl Harbor Xlibris $9.99

28 p. The Third Bullet Simon and Schuster Next Comments


www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3 9/10

12/9/12

Cubic Spline Tutorial v3

Post comment

About About Scribd Blog Join our team! Contact Us Premium Premium Reader Scribd Store Advertise with us Get started AdChoices Support Help FAQ Press Partners Publishers Developers / API Legal Terms Privacy Copyright Copyright 2012 Scribd Inc. Language: English

www.scribd.com/doc/74298864/Cubic-Spline-Tutorial-v3

10/10

You might also like