# Spline interpolation

{{#invoke:see also|seealso}}
In the mathematical field of numerical analysis, **spline interpolation** is a form of interpolation where the interpolant is a special type of piecewise polynomial called a spline. Spline interpolation is often preferred over polynomial interpolation because the interpolation error can be made small even when using low degree polynomials for the spline. Spline interpolation avoids the problem of Runge's phenomenon, in which oscillation can occur between points when interpolating using high degree polynomials.

## Introduction

Originally, *spline* was a term for elastic rulers that were bent to pass through a number of predefined points ("knots"). These were used to make technical drawings for shipbuilding and construction by hand, as illustrated by Figure 1.

The approach to mathematically model the shape of such elastic rulers fixed by *n*+1 knots is to interpolate between all the pairs of knots and with polynomials .

The curvature of a curve

is

As the spline will take a shape that minimizes the bending (under the constraint of passing through all knots) both and will be continuous everywhere and at the knots. To achieve this one must have that

and that

for all *i*, . This can only be achieved if polynomials of degree 3 or higher are used. The classical approach is to use polynomials of degree 3 — the case of cubic splines.

## Algorithm to find the interpolating cubic spline

A third order polynomial for which

can be written in the symmetrical form

where Template:NumBlk and

Setting `x` = `x`_{1} and `x` = `x`_{2} respectively in equations (Template:EquationNote) and (Template:EquationNote) one gets from (Template:EquationNote) that indeed first derivatives `q'`(`x`_{1}) = `k`_{1} and `q'`(`x`_{2}) = `k`_{2} and also second derivatives

If now (`x _{i}`,

`y`) where

_{i}`i`= 0, 1, ... ,

*n*are

*n*+1 points and

where *i* = 1, 2, ..., *n* and are *n* third degree polynomials interpolating `y` in the interval
`x` _{i-1} ≤ `x` ≤ `x`_{i} for *i* = 1,... , *n* such that `q`'_{i} (`x`_{i}) = `q`' _{i+1} (`x`_{i}) for *i* = 1, ... , *n*-1
then the *n* polynomials together define a differentiable function in the interval `x`_{0} ≤ `x` ≤ `x`_{n} and

for *i* = 1, ..., *n* where

If the sequence `k`_{0}, `k`_{1}, ..., `k`_{n} is such that in addition `q"`_{i}(`x`_{i}) = `q"`_{i+1}(`x`_{i}) for *i* = 1, ..., *n*-1 the resulting function will even have a continuous second derivative.

From (Template:EquationNote), (Template:EquationNote), (Template:EquationNote) and (Template:EquationNote) follows that this is the case if and only if

for *i* = 1, ..., *n*-1. The relations (Template:EquationNote) are *n*-1 linear equations for the *n*+1 values `k`_{0}, `k`_{1}, ..., `k`_{n}.

For the elastic rulers being the model for the spline interpolation one has that to the left of the left-most "knot" and to the right of the right-most "knot" the ruler can move freely and will therefore take the form of a straight line with `q"` = 0 . As `q"` should be a continuous function of `x` one gets that for "Natural Splines" one in addition to the *n*-1 linear equations (Template:EquationNote) should have that

i.e. that

Eventually, (Template:EquationNote) together with (Template:EquationNote) and (Template:EquationNote) constitute *n*+1 linear equations that uniquely define the *n*+1 parameters `k`_{0}, `k`_{1}, ..., `k`_{n}.

There exists other end conditions: "Clamped spline", that specifies the slope at the ends of the spline, and the popular "not-a-knot spline", that requires that the third derivative is also continuous at the `x _{1}` and

`x`points. For the "not-a-knot" spline, the additional equations will read:

_{N-1}## Example

In case of three points the values for are found by solving the tridiagonal linear equation system

with

For the three points

one gets that

and from (Template:EquationNote) and (Template:EquationNote) that

In Figure 2 the spline function consisting of the two cubic polynomials and given by (Template:EquationNote) is displayed

## See also

- Cubic Hermite spline
- Centripetal Catmull–Rom spline
- Monotone cubic interpolation
- NURBS
- Multivariate interpolation
- Polynomial interpolation
- Smoothing spline

## External links

- {{#invoke:citation/CS1|citation

|CitationClass=citation }}

- Dynamic cubic splines with JSXGraph
- Lectures on the theory and practice of spline interpolation
- Paper which explains step by step how cubic spline interpolation is done, but only for equidistant knots.
- Online Cubic Spline Interpolation Utility
- Numerical Recipes in C, Go to Chapter 3 Section 3-3.
- A note on cubic splines