2
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ So from my understanding of what you said, I should set up a 16x16 matrix but vary the H's 3 times. To find the first set of coefficients and carry on from there, correct? $\endgroup$ – Meow Jan 31 '15 at 23:26
  • $\begingroup$ I don't quite get what you mean by "vary the H's 3 times". $\endgroup$ – fang Feb 1 '15 at 6:10
  • $\begingroup$ Oh sorry, I'm using H as the coefficient relating to the spacing between the X values. $\endgroup$ – Meow Feb 1 '15 at 12:41
  • $\begingroup$ Then, yes but you should vary the H 4 times since you have 4 cubic splines to solve for. $\endgroup$ – fang Feb 1 '15 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.