[Math] Natural Cubic Spline Unequal Spacing

approximationapproximation-theoryinterpolation

I'm currently trying to create a natural cubic spline by setting up linear equations to solve for the coefficients of the spline.

Where the spline follows as :

$S_i(x)=a_i+b_i(x-x_i)+c_i(x-x_i)^2+d_i(x-x_i)^3$ where $i=0,…n-1.$

I need to construct the spline to fit the following data points :

$ x = 3, 5,9, 13, 21$ and $y= 625, 410, 299, 130, 82$

As you can see, the X values is unequally spaced.

Where the equal spacing is used within the tridiagonal system.

What alteration can I use to create a cubic spline?

Best Answer

You still can do what you want to do with unequal spacing of X values. For your particular case where you have 5 points, this means you have 4 cubic splines you would like to solve for. Therefore, you have 16 unknowns (each cubic spline has 4 coefficients). You have 5 points and 3 continuity constraints ($C^0$, $C^1$ and $C^2$) at each of the 3 interior data points, which amount to 14 equations. The two additional constraints come from setting the second derivatives to zero at the start and end point. So, at the end you have 16 unknowns with 16 equations and you can get your linear equations set up and solved.

In a nutshell, in the process of setting up these linear equations, whether the X values are spaced evenly or unevenly only affects the 16x16 matrix value, but it will not interfere with how the matrix is set up.