Ch19.4: Cubic Splines

Higher Degree Polynomial Interpolation

  • Suppose we had a data set of 102 data points.
  • A polynomial interpolation would have degree 101 (Ch19.3).
  • Can have 100 oscillations, typically of large magnitude.

title

Draftsman's Spline

title

  • Woodworking, ship hull design, etc.
  • Smooth fit determined by a natural balance of internal and external forces (tension, weights).
  • Applications in other areas help create naturally smooth curves.

Clamped Spline

title

  • Fit flexible strip of wood through pegs
  • Spline is clamped at endpoints
  • Specific derivative (shape) condition at endpoints

title

Natural Spline

title

  • Spline is not clamped at endpoints (free)
  • Linear shape at endpoints
  • Second derivative equal to zero at endpoints.

Two Jokes



What's brown and sticky?

A stick.


Wanna hear a joke about paper?

Never mind-it's tearable.

Splines: Piecewise Interpolation

Piecewise Interpolation

  • A piecewise interpolation uses low order polynomials (splines) between groupings of data.
  • Common choices are linear and cubic.
  • Note difference between single cubic interpolating polynomial versus three separate cubic splines (one for each pair of data).

title

Quadratic Spline Figure

  • Note the piecewise listing of quadratic formulas

title

Linear Spline

  • Graph linear spline for (-2,-1), (-1,-2), (0,-1), (1,2).
  • To find spline, solve six equations in six unknowns…

plot of chunk unnamed-chunk-2

Cubic Splines

  • Instead of trying to fit a piecewise linear model through a set of data points, we can try to fit a piecewise cubic polynomial model through the points.
  • For a smooth curve (no jaggedness), we require that the resulting graph is differentiable everywhere.

Cubic Spline Derivation

  • Suppose that we want to fit cubic splines through the data points (1,2), (2,1), (3,2).
  • Find two cubic polynomials (splines) that fit their respective two data points along with additional smoothness conditions.

\[ \begin{aligned} p_1(x) &= a_1 x^3 + b_1 x^2 + c_1 x + d_1 , \,\, 1 \leq x \leq 2 \\ p_2(x) &= a_2 x^3 + b_2 x^2 + c_2 x + d_2 , \,\, 2 \leq x \leq 3 \end{aligned} \]

  • Here, \( p_1(x) \) passes through (1,2) and (2,1).
  • Also, \( p_2(x) \) passes through (2,1) and (3,2).
  • To join smoothly at the shared point (2,1), they need to have the same slope and concavity there.

Cubic Spline Derivation: 8 Equations

Cubic Spline Derivation: Matrix Equation

Book Example

Find a spline approximation and a polynomial approximation for the curve of the cross section of the circular shaped Shrine of the Book in Jerusalem.

Book Example: Python Output

plot of chunk unnamed-chunk-3

Book Example: Python Code Chunk 1

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

#Enter data
x = [-5.8, -5.0, -4.0, -2.5, -1.5, -0.8, 0, 0.8, 1.5, 2.5, 4.0, 5.0, 5.8]
y = [0, 1.5, 1.8, 2.2, 2.7, 3.5, 3.9, 3.5, 2.7, 2.2, 1.8, 1.5, 0]

#Command for cubic spline spline polynomial p(x)
p = interp1d(x, y, kind = 'cubic')

Book Example: Python Code Chunk 2

#Create vector of 500 points between 0 and x[n-1] on x-axis
n = len(x)
xnew = np.linspace(x[0], x[n-1], num=500, endpoint=True)

#Plot the original data together with p(x) sampled at the 500 points
plt.plot(x, y, 'o', xnew, p(xnew), '-,r')
plt.legend(['Original Data','Cubic Spline p(x)'], loc = 'best')
plt.show()