Spline fitting or spline interpolation is a way to draw a smooth curve through n+1 points (x0, y0), …, (xn,yn). Thus, we seek a smooth function f(x) so that f(xi) = yi for all i. In particular, we seek n cubic polynomials p0, …, pn-1 so that f(x) = pi(x) for all x in the interval [xi, xi+1].
Key Property
Property 1: The cubic polynomials that we are seeking can be defined by
pi(x) = ai(x–xi)3 + bi(x–xi)2 + ci(x–xi) + di
where for i = 0, …, n-1
based on hi = xi+1 – xi and ki = yi+1 – yi. The bi coefficients are defined via matrix operations as follows. First define for i = 1, …, n
Now define U = [uij] to be an n+1 × n+1 matrix (where i, j = 0, …, n) where
and define B = [bi] and V = [vi] to be n+1 × 1 matrices where the vi are as defined above and B is defined by
B = U-1V
Proof
The proof uses calculus.
We define n cubic polynomials p0, …, pn-1 with the following properties:
- pi(x) = ai(x–xi)3 + bi(x–xi)2 + ci(x–xi) + di for all i = 0, …, n–1
- if xi-1 ≤ x ≤ xi then f(x) = pi(x) for all i = 0, …, n–1 (f defined piecewise by the pi)
- f(xi) = yi for all i = 0, …, n (points (xi, yi) lie on the y = f(x) curve)
- pi-1 (xi) = pi (xi) for all i = 0, …, n–1 (f is continuous)
- p′i-1 (xi) = p′i (xi) for all i = 0, …, n–1 (f′ exists and is continuous)
- p′′i-1 (xi) = p′′i (xi) for all i = 0, …, n–1 (f′′ exists and is continuous)
- p′′0 (x0) = 0 and p′′n-1 (xn) = 0 (initial conditions)
We also define hi = xi+1 – xi and ki = yi+1 – yi for i = 0, …, n–1.
By 1, 2, and 3, for i = 0, …, n–1
and so by 1, 3, and 4, for i = 0, …, n–1
By 1
and so
It now follows by 6 that
Solving for ci it follows that
As we have seen previously
and so
It now follows by 5 that
or equivalently for i = 0, …, n–1
This can be re-expressed as
We now have n+1 linear equations in n+1 unknowns as follows for i = 1, …, n–1
Dividing both sides of this last equation by hi-1 + hi, we obtain the equivalent form
where ri, si, and vi are defined as in the statement of the property. With B, U, and V defined as in the statement of the property, the n+1 linear equations can be re-expressed as
UB = V
from which it follows that B = U-1V, which completes the proof.
References
Chen, M-Q (2013) Cubic spline interpolation
This paper has been removed from the Internet
Jameson, A. (2019) Cubic splines
http://aero-comlab.stanford.edu/Papers/splines.pdf
Wang, K. (2013) A study of cubic spline interpolation
https://www2.rivier.edu/journal/ROAJ-Fall-2013/J784-Wang_cubic-splines.pdf
A bit pedantic, but … in properties 4, 5, 6 your equations show indices “i-1” for i=0,…,n-1 but the polynomials are only defined for index values 0 to n-1 (property 1). So when i=0, your indices in properties 4, 5, 6 take a value of -1, for which the polynomials are not defined.
Similarly in property 2, the “i-1” index for x can take a value of -1
It would seem to be more sensible to use indices i and i+1 in place of i-1 and i, or else use i=1, …n (n+1 in property 3)
Thanks for your suggestion. I am now finishing the testing of the new capabilities for the next release of the Real Statistics software. I will make the necessary changes once I have issued the new release.
Charles