Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

5.05: Spline Method of Interpolation

( \newcommand{\kernel}{\mathrm{null}\,}\)

Lesson 1: Why Do We Need Spline Interpolation?

Learning Objectives

After successful completion of this lesson, you should be able to:

1) justify why higher-order interpolation is a bad idea,

2) how spline interpolation can avoid the pitfalls of higher-order interpolation.

Introduction

Polynomial interpolation involves finding a polynomial of order n or less that passes through the n+1 points. Several methods to obtain such a polynomial include the direct method (also called the Vandermonde polynomial method), Newton’s divided difference polynomial method, and the Lagrangian interpolation method.

So is the spline method yet another method of obtaining this nth order polynomial? …… NO!

Actually, when n becomes large, in many cases, one may get oscillatory behavior in the interpolating polynomial. This phenomenon was illustrated by Runge when he interpolated data based on a simple function of

y=11+25x2(5.5.1.1)

on an interval of [1,1].

For example, take six equidistantly spaced points in [1,1] and find y at these points from Equation (5.5.1.1). These values are given in Table 5.5.1.1.

Table 5.5.1.1. Six equidistantly spaced points in [1,1].
x y=11+25x2
1.0 0.038461
0.6 0.1
0.2 0.5
0.2 0.5
0.6 0.1
1.0 0.038461

Now through these six data points, one can pass a fifth-order interpolating polynomial.

f5(x)=1.2019x41.7308x2+0.56731, 1x1(5.5.1.2)

On plotting the fifth-order polynomial (Equation (5.5.1.2)) and the original function (Equation (5.5.1.1)), as seen in Figure 5.5.1.1, you can see that they do not match well. The polynomial does go through the six data pairs of Table 5.5.1.1, but it does not even come close to the original function at many other points. Just look at x=0.85, the value of the original function is 0.052459, but the fifth-order polynomial gives you a value of 0.055762. That is a whopping relative true error of 206.30%.

Graphs of 6 equidistant points on both the original function and the interpolated 5th order polynomial.
Figure 5.5.1.1. Fifth order polynomial interpolation with six equidistant points.

One may think that choosing more points in the interval [1,1] will give us a better match between the original function and the interpolant, but it diverges even more (Figure 5.5.1.2). Here 20 equidistant points were chosen in the interval [1,1] to draw a 19th order interpolating polynomial. It, however, did do a better job of approximating the data but except near the ends where the approximation is worse than before. At our chosen point, x=0.85, the value of the original function is 0.052459, while we get 0.62944 from the 19th order polynomial. That gives a big whopper relative true error of 1299.9%.

In fact, Runge found that as the order of the polynomial approaches infinity, the polynomial diverges even more in the interval of 1<x<0.726 and 0.726<x<1.

Graphs of 20 equidistant points on both the original function and the interpolated 19th order polynomial.
Figure 5.5.1.2. Nineteenth order polynomial interpolation with twenty equidistant points.

So, what is the solution to using information from more data points, but at the same time keeping the function reasonably true to the data behavior? The answer is in spline interpolation and will be discussed in the following lessons. The most common types of spline interpolation used are linear, quadratic, and cubic.

Audiovisual Lecture

Title: Higher Order Interpolation is a Bad Idea

Summary: Learn via Runge's phenomena why higher-order interpolation is a bad idea. We take Runge's function y=11+25x2 in xϵ[−1,1] domain. We choose equidistant points and show that the polynomial interpolant becomes even farther from the exact value as more points are chosen.

Lesson 2: Linear Spline Interpolation

Learning Objectives

After successful completion of this lesson, you should be able to:

1) develop linear spline interpolant to given data points,

2) estimate unknown data points from the linear spline interpolant.

Linear Spline Interpolation

Given (x0,y0),(x1,y1),,(xn1,yn1),(xn,yn), find the interpolating linear spline (Figure 5.5.2.1) to the data. This procedure simply involves drawing straight lines between consecutive points.

Linear splines for 4 points.
Figure 5.5.2.1. Linear splines.

Assuming that the above data is given in ascending order, the interpolating linear spline, also called the spline of degree 1, f(x), is given by f(x)=f(x0)+f(x1)f(x0)x1x0(xx0), x0xx1,=f(x1)+f(x2)f(x1)x2x1(xx1), x1xx2,     =f(xn1)+f(xn)f(xn1)xnxn1(xxn1), xn1xxn.(5.5.2.1)

Note that yi=f(xi) in the above expression and that the terms of

f(xi)f(xi1)xixi1(5.5.2.2)

are simply slopes between xi1 and xi.

Example 5.5.2.1

The upward velocity of a rocket is given as a function of time in Table 5.5.2.1 (Figure 5.5.2.2).

Table 5.5.2.1. Velocity as a function of time.
t (s) v(t) (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67

Determine the value of the velocity at t=16 seconds using an interpolating linear spline.

Graph of velocity vs. time data for the rocket example.
Figure 5.5.2.2. Graph of velocity vs. time data for the rocket example.
Solution

Since we want to evaluate the velocity at t=16 and use linear spline interpolation, we need to choose the two data points closest to t=16 that also bracket t=16 to evaluate it. The two points are t0=15 and t1=20.

Then

t0=15, v(t0)=362.78

t1=20, v(t1)=517.35'

gives

v(t)=v(t0)+v(t1)v(t0)t1t0(tt0)=362.78+517.35362.782015(t15)=362.78+30.913(t15), 15t20

At t=16,

v(16)=362.78+30.913(1615)=393.7 m/s

Linear spline interpolation is no different from linear polynomial interpolation. Linear spline interpolation still uses data only from the two consecutive data points, and data from other points is not used at all. Also, at the interior points of the data, the slope of the spline changes abruptly, which implies that the first derivative is “artificially” not continuous at these points. So how do we overcome these two drawbacks? We can do so by using quadratic or cubic spline interpolation. We discuss these types of spline interpolation in upcoming lessons.

Audiovisual Lecture

Title: Spline Interpolation: Linear Spline Interpolation

Summary: Learn the theory behind linear spline interpolation using an example.

Lesson 3: Quadratic Spline Interpolation

Learning Objectives

After successful completion of this lesson, you should be able to:

1) derive interpolating quadratic spline for discrete data.

Interpolating Quadratic Spline

Quadratic spline interpolation is a method to curve fit data. For quadratic spline interpolation, piecewise quadratics approximates the data between two consecutive data points (Figure 5.5.3.1). Given (x0,y0),(x1,y1),......,(xn1,yn1),(xn,yn), fit an interpolating quadratic spline through the data. The quadratics of the spline are given by

f(x)=a1x2+b1x+c1, x0xx1=a2x2+b2x+c2, x1xx2     =anx2+bnx+cn, xn1xxn

So how does one find the coefficients of these quadratics? There are 3n such coefficients:

ai, i=1,2,.....,n

bi, i=1,2,.....,n

ci, i=1,2,.....,n

To find 3n unknowns, one needs to set up 3n equations and then simultaneously solve them. These 3n equations are found as follows.

Quadratic spline interpolation.
Figure 5.5.3.1. Quadratic spline interpolation
  1. Each quadratic goes through two consecutive data points: a1x02+b1x0+c1=f(x0)a1x12+b1x1+c1=f(x1)aixi12+bixi1+ci=f(xi1)aixi2+bixi+ci=f(xi)anxn12+bnxn1+cn=f(xn1)anxn2+bnxn+cn=f(xn) This condition gives 2n equations as there are n quadratics going through two consecutive data points.
  2. The first derivatives of two consecutive quadratics are continuous at the common interior points. For example, the derivative of the first quadratic a1x2+b1x+c1 is 2a1x+b1 The derivative of the second quadratic a2x2+b2x+c2 is 2a2x+b2 and the two are equal at the common interior point x=x1, giving 2a1x1+b1=2a2x1+b2 2a1x1+b12a2x1b2=0 Similarly, at the other interior points x2,,xn1, 2a2x2+b22a3x2b3=02aixi+bi2ai+1xibi+1=02an1xn1+bn12anxn1bn=0 Since there are (n1) interior points, we have (n1) such equations.
  3. So far, the total number of equations obtained is (2n)+(n1)=(3n1) equations. We still then need one more equation. We could assume the first quadratic is linear, that is, a1=0 Some assume the last quadratic is linear, that is, an=0 Others rightly base it on which interval is smaller, [x0,x1] or [xn1,xn]. If |x1x0||xnxn1|, then one would choose a1=0; else, choose an=0.

This gives us 3n simultaneous linear equations and 3n unknowns. These can be solved by several techniques used to solve a general set of simultaneous linear equations.

Audiovisual Lecture

Title: Quadratic Spline Interpolation: Theory

Summary: Learn the theory behind quadratic spline interpolation.

Lesson 4: Application of Quadratic Spline Interpolation

Learning Objectives

After successful completion of this lesson, you should be able to:

1) conduct quadratic spline interpolation on discrete data,

2) differentiate an interpolating quadratic spline as needed,

3) integrate an interpolating quadratic spline as needed.

Applications

In the previous lesson, you learned the theory of the quadratic spline interpolation method. In this lesson, we apply the theory to given interpolate discrete data to an interpolating quadratic spline.

Example 5.5.4.1

The upward velocity of a rocket is given as a function of time as

Table 5.5.4.1. Velocity as a function of time.

t (s) v(t) (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67

a) Determine the value of the velocity at t=16 seconds using quadratic spline interpolation.

b) Using the interpolating quadratic spline, find the distance covered by the rocket from t=11 s to t=16 s.

c) Using the interpolating quadratic spline, find the acceleration of the rocket at t=16 s.

Solution

a) Since there are six data points, five quadratics pass through them.

v(t)=a1t2+b1t+c1, 0t10=a2t2+b2t+c2, 10t15=a3t2+b3t+c3, 15t20=a4t2+b4t+c4, 20t22.5=a5t2+b5t+c5, 22.5t30

The equations are found as follows.

1. Each quadratic passes through two consecutive data points.

Quadratic a1t2+b1t+c1 passes through t=0 and t=10.

a1(0)2+b1(0)+c1=0(5.5.4.E1.1)

a1(10)2+b1(10)+c1=227.04(5.5.4.E1.2)

Quadratic a2t2+b2t+c2 passes through t=10 and t=15.

a2(10)2+b2(10)+c2=227.04(5.5.4.E1.3)

a2(15)2+b2(15)+c2=362.78(5.5.4.E1.4)

Quadratic a3t2+b3t+c3 passes through t=15 and t=20.

a3(15)2+b3(15)+c3=362.78(5.5.4.E1.5)

a3(20)2+b3(20)+c3=517.35(5.5.4.E1.6)

Quadratic a4t2+b4t+c4 passes through t=20 and t=22.5.

a4(20)2+b4(20)+c4=517.35(5.5.4.E1.7)

a4(22.5)2+b4(22.5)+c4=602.97(5.5.4.E1.8)

Quadratic a5t2+b5t+c5 passes through t=22.5 and t=30.

a5(22.5)2+b5(22.5)+c5=602.97(5.5.4.E1.9)

a5(30)2+b5(30)+c5=901.67(5.5.4.E1.10)

2. The quadratics have continuous derivatives at the common interior data points.

At t=10

2a1(10)+b12a2(10)b2=0(5.5.4.E1.11)

At t=15

2a2(15)+b22a3(15)b3=0(5.5.4.E1.12)

At t=20

2a3(20)+b32a4(20)b4=0(5.5.4.E1.13)

At t=22.5

2a4(22.5)+b42a5(22.5)b5=0(5.5.4.E1.14)

3. Assuming the last quadratic a5t2+b5t+c5 is linear (why did we choose the last spline to be linear over the first one?),

a5=0(5.5.4.E1.15)

Combining Equations (5.5.4.E1.1) through (5.5.4.E1.15) in matrix form gives

[001000000000000100101000000000000000100101000000000000225151000000000000000225151000000000000400201000000000000000400201000000000000506.2522.51000000000000000506.2522.5100000000000090030120102010000000000000301030100000000000004010401000000000000045104510000000000000100]=[a1b1c1a2b2c2a3b3c3a4b4c4a5b5c5][0227.04227.04362.78362.78517.35517.35602.97602.97901.6700000]

Solving the above 15 simultaneous linear equations for the 15 unknowns gives

i ai bi ci
1 0.15667 24.271 0
2 1.2021 2.9053 135.88
3 0.44893 46.627 235.61
4 2.2315 60.589 836.55
5 0 39.827 293.13

Therefore, the interpolating quadratic spline is given by

v(t)=0.15667t2+24.271t, 0t10=1.2021t22.9053t+135.88, 10t15=0.44893t2+46.627t235.61, 15t20=2.2315t260.589t+836.55, 20t22.5=39.827t293.13, 22.5t30(5.5.4.E1.16)

At t=16 s

v(16)=0.44893(16)2+46.627(16)235.61=395.50 m/s

b) The distance covered by the rocket between 11 s and 16 s seconds can be calculated as

s(16)s(11)=1611v(t) dt

But since several quadratics are valid over the limits of integration, we need to break the integral accordingly. Using Equation (5.5.4.E1.16),

v(t)=1.2021t22.9053t+135.88, 10t15=0.44893t2+46.627t235.61, 15t20

Then

s(16)s(11)=1611v(t) dt=1511v(t) dt+1615v(t) dt

Substituting proper quadratics gives

s(16)s(11)=15111.2021t22.9053t+135.88 dt     +16150.44893t2+46.627t235.61 dt=[1.2021t332.9053t22+135.88t]1511     +[0.44893t33+46.627t22235.61t]1615=1211.49+379.22=1590.7 m

c) What is the acceleration at t=16 s?

a(16)=dvdt|t=16

Here we use the third quadratic from Equation (5.5.4.E1.15),

0.44893t2+46.627t235.61, 15t20

as t=16 is in the domain of 15t20.

So

a(t)=ddtv(t)=ddt(0.44893t2+46.627t235.61)=0.89786t+46.627, 15t20

Hence

a(16)=0.89786(16)+46.627=32.261 m/s2

Audiovisual Lecture

Title: Quadratic Spline Interpolation: Example

Summary: Learn the quadratic spline interpolation method via an example.

Lesson 5: Outline of Cubic Spline Interpolation

Learning Objectives

After successful completion of this lesson, you should be able to:

1) outline the derivation of cubic spline interpolation.

Introduction

Just like quadratic spline interpolation, cubic spline interpolation is a method to curve fit data. The cubic spline interpolation is the most common degree of spline used.

Interpolating Cubic Spline

Given n+1 data points, (x0,y0), (x1,y1),, (xn,yn), fit an interpolating cubic spline through the data. For cubic spline interpolation, piecewise cubic polynomials approximate the data between two consecutive points. The interpolating cubic spline is given by the cubics as

f(x)=a1x3+b1x2+c1x+d1, x0xx1=a2x3+b2x2+c2x+d2, x1xx2     =anx3+bnx2+cnx+dn, xn1xxn

So, how does one find the coefficients of these cubics? There are 4n such coefficients as given below.

ai, i=1, 2,, nbi, i=1, 2,, nci, i=1, 2,, ndi, i=1, 2,, n

To find the 4n unknowns, we need to set up 4n simultaneous linear equations. The outline of setting up these equations is as follows. We have n+1 data points. Out of these n+1 points, two are the exterior (end) data points, while there are ((n+1)2=n1) interior data points.

  1. Each cubic must go through two consecutive points. Since we have n splines, we will get 2n equations.
  2. The first derivative of two consecutive cubics is continuous at the common interior data point. Since we have (n1) interior points, we will get 2(n1) equations
  3. The second derivative of two consecutive cubics is continuous at the common interior data point. Since we have (n1) interior points, we will get 2(n1) equations

So far, we have outlined that

(2n)+(n1)+(n1)=4n2

equations can be set up. We need two more equations, and several types of conditions can be used to get them. A few common conditions used are as follows.

  1. Assume that the first and last cubic splines are quadratics (a1=0 and an=0) to get the two more equations. This assumption is called the quadratic end condition.
  2. Assume the second derivative of the first and last cubic spline is zero (6a1x0+2b1=0 and 6anxn+2bn=0) at the respective exterior points to get the two more equations. This assumption is called the natural end condition.

Multiple Choice Test

(1). The following n data points, (x1,y1), (x2,y2), …….. (xn,yn), are given. For conducting quadratic spline interpolation, the x-data needs to be

(A) equally spaced

(B) placed in ascending or descending order of x-values

(C) integers

(D) positive

(2). In cubic spline interpolation,

(A) the first derivatives of the cubics are continuous at the interior data points

(B) the second derivatives of the cubics are continuous at the interior data points

(C) the first and the second derivatives of the cubics are continuous at the interior data points

(D) the third derivatives of the cubics are continuous at the interior data points

(3). The following incomplete y vs. x data is given.

x 1 2 4 6 7
y 5 11 ???? ???? 32

The data is fit by interpolating quadratic splines given by

f(x)=ax1, 1x2=2x2+14x9, 2x4=bx2+cx+d, 4x6

=25x2303x+928,    6x7 where a,b,c,and d are constants. The value of c is most nearly

(A) 303.00

(B) 144.50

(C) 0.0000

(D) 14.000

(4). The following incomplete y vs. x data is given.

x 1 2 4 6 7
y 5 11 ???? ???? 32

The data is fit by interpolating quadratic spline given by

f(x)=ax1, 1x2,=2x2+14x9, 2x4=bx2+cx+d, 4x6=ex2+fx+g, 6x7

where a,b,c,d,e,f,and g are constants. The value of dfdx at x=2.6 most nearly is

(A) 144.50

(B) 4.0000

(C) 3.6000

(D) 12.200

(5). The following incomplete y vs. x data is given.

x 1 2 4 6 7
y 5 11 ???? ???? 32

The data is fit by interpolating quadratic spline given by

f(x)=ax1, 1x2,=2x2+14x9, 2x4=bx2+cx+d, 4x6=25x2303x+928, 6x7

where a,b,c, and d are constants. What is the estimated value of 3.51.5f(x) dx?

(A) 23.500

(B) 25.667

(C) 25.750

(D) 28.000

(6). A robot needs to follow a path that passes consecutively through six points, as shown in the figure. To find the shortest path that is also smooth, you would recommend which of the following?

Graph of six data points for the path of a robot.

(A) Pass a fifth-order polynomial through the data

(B) Pass interpolating linear spline through the data

(C) Pass interpolating quadratic spline through the data

(D) Regress the data to a second-order polynomial

For complete solution, go to

http://nm.mathforcollege.com/mcquizzes/05inp/quiz_05inp_spline_solution.pdf

Problem Set

(1). The following y vs x data is given.

x 2 3 6
y 4.75 5.25 45

a) Set up the equations to solve for the interpolating quadratic spline that goes through the data.

b) Use a program such as MATLAB to solve the equations and then write down the interpolating quadratic spline.

c) Estimate the value of y(3.6).

Answer

a) [4210009310000009310003661610610100000][a1b1c1a2b2c2]=[4.755.255.254500]

b)

i ai bi ci
1 0 0.5 3.75
2 4.25 25 42

c) 7.08

(2). The following y vs x data is given.

x 1 2 3 5 6
y 4.75 4 5.25 15 45

The data is fit by interpolating quadratic spline given by

f(x)=0.75x+5.5,1x2=2x28.75x+13.5,2x3=cx2+gx+h,3x5=jx2+kx+l,5x6

where c, g, h, j, k, and l are constants.

a) Find the value of c, g, h, j, k, and l.

b) Compare the value of the function at x=2.3 using interpolating linear spline and interpolating quadratic spline.

Answer

a) c=0.8125
g=1.625
h=2.8125
j=23.5
k=228.5
l=570

b) linear=4.375; quadratic=3.955

(3). The following incomplete y vs. x data is given.

x 1 2.2 3.7 5.1 6
y 4.25 6 5.25 15.1 ?????

The data is fit by interpolating quadratic spline given by

f(x)=1.4583x+2.7917,1x2.2=1.3056x2+7.2028x3.5278,2.2x3.7=cx2+gx+h,3.7x5.1=jx2+kx+1,5.1x6

where c, g, h, j, k, and l are constants. What is the value of g? Show all your steps clearly.

Answer

g=52.6391

(4). The following incomplete y vs. x data is given.

x 1 2.2 3.7 5.1 6
y 4.25 6 5.25 ???? ?????

The data is fit by interpolating quadratic spline given by

f(x)=1.4583x+2.7917,1x2.2=1.3056x2+7.2028x3.5272,2.2x3.7=cx2+gx+h,3.7x5.1=jx2+kx+l,5.1x6

where c, g, h, j, k, and l are constants. What is the value of dfdx at x=2.67?

Answer

0.23133

(5). The following incomplete y vs. x data is given.

x 1 2.2 3.7 5.1 6
y 4.25 6 5.25 ???? ?????

The data is fit by interpolating quadratic spline given by

f(x)=1.4583x+2.7917,1x2.2=1.3056x2+7.2028x3.5272,2.2x3.7=cx2+gx+h,3.7x5.1=jx2+kx+l,5.1x6

where c, g, h, j, k, and l are constants. What is the value of2.51.5f(x)dx?

Answer

5.6965

(6). Given three data points (1,6), (3,28), and (10,231), it is found that the function y=2x2+3x+1 passes through the three data points. To find the length of the polynomial curve from x=5 to x=8, a student uses the formula, S=ba1+(dy/dx)2 dx. However, this formula gives the student an integral that cannot be solved exactly. Instead, the student approximates the polynomial curve by drawing interpolating linear spline that consists of piecewise functions from x=5 to x=6, from x=6 to x=7 and from x=7 to x=8. The student then finds the length of the interpolating linear spline from x=5 to x=8. What is the student’s estimate of the length of the function from x=5 to x=8?

Answer

87.052 (getting 87 as the answer is wrong)


This page titled 5.05: Spline Method of Interpolation is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Autar Kaw via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?