[Math] Find the not-a-knot cubic spline over each subinterval in standard form

interpolationlagrange-interpolationnumerical methodsspline

Looking over some cubic spline interpolation problems and unsure which method to use.

Given the values:
x= [-2,-1,0,1,2,3], y = [18,12,6,4,5,18] respectively.
So x(-2) = 18, x(-1) = 12, x(0) = 6, x(1) = 4, x(2) = 5, x(3) = 18

What I have so far:

Because this is a not-a-knot spline, the first two and the last two spline functions will be the same. This means that a= e, b=f, c=g, and d=h. This also means that m=q, n=r, o=x, and p=t.

$S_0(s) = ax^3+bx^2+cx+d$ and $x\in[-2,-1]$

$S_1(s) = ex^3+fx^2+gx+h$ and $x\in[-1,0]$

$S_2(s) = ix^3+jx^2+kx+l$ and $x\in[0,1]$

$S_3(s) = mx^3+nx^2+ox+p$ and $x\in[1,2]$

$S_4(s) = qx^3+rx^2+sx+t$ and $x\in[2,3]$

then i plugged in all the x values for each and got:

$S_0(-2) = -8a+4b-2c+d = 18$

$S_0(-1) = -a+b-c+d = 12$

$S_1(-1) = -e+f-g+h = 12$

$S_1(0) = h = 6$

$S_2(0) = l = 6$

$S_2(1) = i+j+k+l=4$

$S_3(1) = m+n+o+p = 4$

$S_3(2) = 8m+4n+2o+p=5$

$S_4(2) = 8q+4r+2s+t =5$

$S_4(3) = 27q + 9r + 3s + t = 18$

Because $h=l=6$, $d=6$ as well because of the not-a-knot condition.

I continue doing this for the next two derivatives and get

c=g=k=o=s and b=f=j=n=r.

Then is it okay to assume that $S_0''(-2) = 0$ and $S_4''(3) = 0$ because of natural cubic spline rule. So that leads to $6a = b$ and $-9q = r$ because $S_0''(-2) = -12a + 2b =0$ and $S_4''(3) = 18q+2r = 0$(i found out this part is wrong). I ended up figuring out the correct answer, but I'm not sure how a=b=0.

By doing multiple systems of equations, I got to the solution that:

$S_0(s) = -6x+6$ for $x\in[-2,-1]$

$S_1(s) = -6x+6$ for $x\in[-1,0]$

$S_2(s) = 4x^3-6x+6$ for $x\in[0,1]$

$S_3(s) = x^3-6x+9$ for $x\in[1,2]$

$S_4(s) = x^3-6x+9$ for $x\in[2,3]$

I think I finally got it working. I don't know if this is considered "standard" form though? Plugged in the numbers and they're all correct.

Best Answer

You have 20 unknowns: $a$ through $t$, so we're going to need 20 equations. Here is how you get them:

  1. Interpolation of points: $S_0(-2) = 18$, $S_0(-1) =12$, $S_1(-1) = 12$, and so on. This is 10 equations.

  2. Equality of first derivatives: $S'_0(-1) = S'_1(-1)$, and so on. That's 4 equations.

  3. Equality of second derivatives: $S''_0(-1) = S''_1(-1)$, and so on. That's 4 equations.

  4. Equality of third derivatives (which makes the adjacent segments identical). This is the not-a-knot condition: $S'''_0(-1) = S'''_1(-1)$ and $S'''_3(2) = S'''_4(2)$. That's two equations.

Write out the 20 equations, and solve.

Incidentally, these sorts of problems are much easier to solve if you express each cubic segment in Hermite form (i.e. as a function of its end-points and end-slopes). That way, many of the required constraints are built into the representation, so you don't need equations to enforce them. In fact, the only unknowns will be the second derivatives at the interior knots. That's 4 equations/unknowns, instead of 20.