# Spline (mathematics) Single knots at 1/3 and 2/3 establish a spline of three cubic polynomials meeting with C2 continuity. Triple knots at both ends of the interval ensure that the curve interpolates the end points

In mathematics, a spline is a special function defined piecewise by polynomials. In interpolating problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results, even when using low degree polynomials, while avoiding Runge's phenomenon for higher degrees.

In the computer science subfields of computer-aided design and computer graphics, the term spline more frequently refers to a piecewise polynomial (parametric) curve. Splines are popular curves in these subfields because of the simplicity of their construction, their ease and accuracy of evaluation, and their capacity to approximate complex shapes through curve fitting and interactive curve design.

The term spline comes from the flexible spline devices used by shipbuilders and draftsmen to draw smooth shapes.

## Introduction

The term "spline" is used to refer to a wide class of functions that are used in applications requiring data interpolation and/or smoothing. The data may be either one-dimensional or multi-dimensional. Spline functions for interpolation are normally determined as the minimizers of suitable measures of roughness (for example integral squared curvature) subject to the interpolation constraints. Smoothing splines may be viewed as generalizations of interpolation splines where the functions are determined to minimize a weighted combination of the average squared approximation error over observed data and the roughness measure. For a number of meaningful definitions of the roughness measure, the spline functions are found to be finite dimensional in nature, which is the primary reason for their utility in computations and representation. For the rest of this section, we focus entirely on one-dimensional, polynomial splines and use the term "spline" in this restricted sense.

## Definition

We begin by limiting our discussion to the univariate polynomial case. In this case, a spline is a piecewise polynomial function. This function, call it S, takes values from an interval [a,b] and maps them to $\mathbb {R}$ , the set of real numbers,

$S:[a,b]\to \mathbb {R} .$ We want S to be piecewise defined. To accomplish this, let the interval [a,b] be covered by k ordered, disjoint[disambiguation needed] subintervals,

$[t_{i},t_{i+1}]{\mbox{ , }}i=0,\ldots ,k-1$ $[a,b]=[t_{0},t_{1}]\cup [t_{1},t_{2}]\cup \cdots \cup [t_{k-2},t_{k-1}]\cup [t_{k-1},t_{k}]$ $a=t_{0}\leq t_{1}\leq \cdots \leq t_{k-1}\leq t_{k}=b$ On each of these k "pieces" of [a,b], we want to define a polynomial, call it Pi.

$P_{i}:[t_{i},t_{i+1}]\to \mathbb {R}$ .

On the ith subinterval of [a,b], S is defined by Pi,

$S(t)=P_{0}(t){\mbox{ , }}t_{0}\leq t $S(t)=P_{1}(t){\mbox{ , }}t_{1}\leq t $\vdots$ $S(t)=P_{k-1}(t){\mbox{ , }}t_{k-1}\leq t\leq t_{k}.$ The given k+1 points ti are called knots. The vector ${\mathbf {t}}=(t_{0},\dots ,t_{k})$ is called a knot vector for the spline. If the knots are equidistantly distributed in the interval [a,b] we say the spline is uniform, otherwise we say it is non-uniform.

If the polynomial pieces Pi each have degree at most n, then the spline is said to be of degree $\leq n$ (or of order n+1).

If $S\in C^{r_{i}}$ in a neighborhood of ti, then the spline is said to be of smoothness (at least) $C^{r_{i}}$ at ti. That is, at ti the two pieces Pi-1 and Pi share common derivative values from the derivative of order 0 (the function value) up through the derivative of order ri (in other words, the two adjacent polynomial pieces connect with loss of smoothness of at most n - ri).

A vector ${\mathbf {r}}=(r_{1},\dots ,r_{k-1})$ such that the spline has smoothness $C^{r_{i}}$ at ti for $i=0,\ldots ,k-1$ is called a smoothness vector for the spline.

Given a knot vector ${\mathbf {t}}$ , a degree n, and a smoothness vector ${\mathbf {r}}$ for ${\mathbf {t}}$ , one can consider the set of all splines of degree $\leq n$ having knot vector ${\mathbf {t}}$ and smoothness vector ${\mathbf {r}}$ . Equipped with the operation of adding two functions (pointwise addition) and taking real multiples of functions, this set becomes a real vector space. This spline space is commonly denoted by $S_{n}^{\mathbf {r}}({\mathbf {t}})$ .

In the mathematical study of polynomial splines the question of what happens when two knots, say ti and ti+1, are moved together has an easy answer. The polynomial piece Pi(t) disappears, and the pieces Pi−1(t) and Pi+1(t) join with the sum of the continuity losses for ti and ti+1. That is,

$S(t)\in C^{n-j_{i}-j_{i+1}}[t_{i}=t_{i+1}],$ where $j_{i}=n-r_{i}$ This leads to a more general understanding of a knot vector. The continuity loss at any point can be considered to be the result of multiple knots located at that point, and a spline type can be completely characterized by its degree n and its extended knot vector

$(t_{0},t_{1},\cdots ,t_{1},t_{2},\cdots ,t_{2},t_{3},\cdots ,t_{k-2},t_{k-1},\cdots ,t_{k-1},t_{k})$ where ti is repeated ji times for $i=1,\dots ,k-1$ .

A parametric curve on the interval [a,b]

$G(t)=(X(t),Y(t)){\mbox{ , }}t\in [a,b]$ is a spline curve if both X and Y are spline functions of the same degree with the same extended knot vectors on that interval.

## Examples

Suppose the interval [a,b] is [0,3] and the subintervals are [0,1], [1,2], and [2,3]. Suppose the polynomial pieces are to be of degree 2, and the pieces on [0,1] and [1,2] must join in value and first derivative (at t=1) while the pieces on [1,2] and [2,3] join simply in value (at t = 2). This would define a type of spline S(t) for which

$S(t)=P_{0}(t)=-1+4t-t^{2}{\mbox{ , }}0\leq t<1$ $S(t)=P_{1}(t)=2t{\mbox{ , }}1\leq t<2$ $S(t)=P_{2}(t)=2-t+t^{2}{\mbox{ , }}2\leq t\leq 3$ would be a member of that type, and also

$S(t)=P_{0}(t)=-2-2t^{2}{\mbox{ , }}0\leq t<1$ $S(t)=P_{1}(t)=1-6t+t^{2}{\mbox{ , }}1\leq t<2$ $S(t)=P_{2}(t)=-1+t-2t^{2}{\mbox{ , }}2\leq t\leq 3$ would be a member of that type. (Note: while the polynomial piece 2t is not quadratic, the result is still called a quadratic spline. This demonstrates that the degree of a spline is the maximum degree of its polynomial parts.) The extended knot vector for this type of spline would be (0, 1, 2, 2, 3).

The simplest spline has degree 0. It is also called a step function. The next most simple spline has degree 1. It is also called a linear spline. A closed linear spline (i.e, the first knot and the last are the same) in the plane is just a polygon.

A common spline is the natural cubic spline of degree 3 with continuity C2. The word "natural" means that the second derivatives of the spline polynomials are set equal to zero at the endpoints of the interval of interpolation

$S''(a)\,=S''(b)=0.$ This forces the spline to be a straight line outside of the interval, while not disrupting its smoothness.

### Algorithm for computing natural cubic splines

Cubic splines are of the form ${S}_{j}\left(x\right)=a_{j}+b_{j}\left(x-x_{j}\right)+c_{j}{\left(x-x_{j}\right)}^{2}+d_{j}{\left(x-x_{j}\right)}^{3}$ .
Given set of coordinates $C=\left[\left({x}_{0},{y}_{0}\right),\left({x}_{1},{y}_{1}\right),....,\left({x}_{n},{y}_{n}\right)\right]$ we wish to find set of $n\,$ splines ${S}_{i}\left(x\right)$ for $i=0,\ldots ,n-1.$ These must satisfy:

• $S_{i}\left(x_{i}\right)=y_{i}=S_{i-1}\left(x_{i}\right),i=1,\ldots ,n-1.$ • ${S^{'}}_{i}\left(x_{i}\right)={S^{'}}_{i-1}\left(x_{i}\right),i=1,\ldots ,n-1.$ • ${S^{''}}_{i}\left(x_{i}\right)={S^{''}}_{i-1}\left(x_{i}\right),i=1,\ldots ,n-1.$ • ${S^{''}}_{0}\left(x_{0}\right)={S^{''}}_{n-1}\left(x_{n}\right)=0$ .

Let us define one cubic spline $S\,$ as a 5-tuple $(a,b,c,d,x_{t})\,$ where $a,b,c\,$ and $d\,$ correspond to coefficients in the form shown earlier and $x_{t}\,$ is equal to $x_{j}.\,$ Algorithm for computing Natural Cubic Splines:
Input: set of coordinates $C\,$ , with $\left|C\right|=n+1$ Output: set splines which is composed of n 5-tuples.

1. Create new array a of size n + 1 and for $i=0,\ldots ,n$ set $a_{i}=y_{i}\,$ 2. Create new arrays b and d each of size n.
3. Create new array h of size n and for $i=0,\ldots ,n-1$ set $h_{i}=x_{i+1}-x_{i}\,$ 4. Create new array α of size n and for $i=1,\ldots ,n-1$ set ${\alpha }_{i}={\frac {3}{{h}_{i}}}\left({a}_{i+1}-{a}_{i}\right)-{\frac {3}{{h}_{i-1}}}\left({a}_{i}-{a}_{i-1}\right)$ .
5. Create new arrays c, l, μ, and z each of size $n+1\,$ .
6. Set $l_{0}=1,{\mu }_{0}=z_{0}=0\,$ 7. For $i=1,\ldots ,n-1\,$ 1. Set ${l}_{i}=2\left({x}_{i+1}-{x}_{i-1}\right)-{h}_{i-1}{\mu }_{i-1}$ .
2. Set ${\mu }_{i}={\frac {{h}_{i}}{{l}_{i}}}$ .
3. Set ${z}_{i}={\frac {{\alpha }_{i}-{h}_{i-1}{z}_{i-1}}{{l}_{i}}}$ .
8. Set $l_{n}=1;z_{n}=c_{n}=0.\,$ 9. For $j=n-1,n-2,\ldots ,0$ 1. Set $c_{j}=z_{j}-{\mu }_{j}c_{j+1}\,$ 2. Set $b_{j}={\frac {{a}_{j+1}-{a}_{j}}{{h}_{j}}}-{\frac {{h}_{j}\left({c}_{j+1}+2{c}_{j}\right)}{3}}$ 3. Set $d_{j}={\frac {{c}_{j+1}-{c}_{j}}{3{h}_{j}}}$ 10. Create new set Splines and call it output_set. Populate it with n splines S.
11. For $i=0,\ldots ,n-1$ 1. Set Si,a = ai
2. Set Si,b = bi
3. Set Si,c = ci
4. Set Si,d = di
5. Set Si,x = xi
12. Output output_set