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
This can only be achieved if polynomials of degree 5 or higher are used. The classical approach is to use polynomials of degree 3, called cubic splines, which can achieve the continuity of the first derivative, but not that of second derivative.
Algorithm to find the interpolating cubic splineEdit
A third-order polynomial for which
can be written in the symmetrical form
one gets that:
Setting x = x1 and x = x2 respectively in equations (5) and (6) one gets from (2) that indeed first derivatives q′(x1) = k1 and q′(x2) = k2 and also second derivatives
If now (xi, yi), 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 xi−1 ≤ x ≤ xi for i = 1, ..., n such that q′i (xi) = q′i+1(xi) for i = 1, ..., n−1 then the n polynomials together define a differentiable function in the interval x0 ≤ x ≤ xn and
for i = 1, ..., n where
If the sequence k0, k1, ..., kn is such that, in addition, q′′i(xi) = q′′i+1(xi) holds for i = 1, ..., n-1, then the resulting function will even have a continuous second derivative.
From (7), (8), (10) and (11) follows that this is the case if and only if
for i = 1, ..., n-1. The relations (15) are n − 1 linear equations for the n + 1 values k0, k1, ..., kn.
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 (15) should have that
Eventually, (15) together with (16) and (17) constitute n + 1 linear equations that uniquely define the n + 1 parameters k0, k1, ..., kn.
There exist 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 x1 and xN−1 points.
For the "not-a-knot" spline, the additional equations will read:
^Hall, Charles A.; Meyer, Weston W. (1976). "Optimal Error Bounds for Cubic Spline Interpolation". Journal of Approximation Theory. 16 (2): 105–122. doi:10.1016/0021-9045(76)90040-X.
Schoenberg, Isaac J. (1946). "Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions: Part A.—On the Problem of Smoothing or Graduation. A First Class of Analytic Approximation Formulae". Quarterly of Applied Mathematics. 4 (2): 45–99. doi:10.1090/qam/15914.
Schoenberg, Isaac J. (1946). "Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions: Part B.—On the Problem of Osculatory Interpolation. A Second Class of Analytic Approximation Formulae". Quarterly of Applied Mathematics. 4 (2): 112–141. doi:10.1090/qam/16705.