[Math] Natural Cubic Spline 3 points

matricesnumerical linear algebranumerical methodsspline

I am trying to do a natural cubic spline but I'm having trouble.

f(-.0247500)=-.5, f(.3349375)=-.25, f(1.101000)=0

I tried doing the matrix, Ax=b where, h0=h1=.25 an a0=-.0247500, a1=.3349375, a2=1.1010000 but my answers were wrong I believe. So I decided to try another way which was,

S0(-.5)=-.0247500=a0

S0(-.25)=.3349375=a0+1/4b0+1/16co+1/64do

S1(-.25)=.3349375=a1

S1(0)=a1+1/4b1+1/16c1+1/64di=1.1010000

S'0(-.25)=b0+1/2c0+3/16do=S'1(-.25)=b1

S"0(-.25)=2c0+3/2d0=S"1(-.25)=b1

S"0(-.5)=2c0=0

S"1(0)=2c1+6d1=0

I am not sure how to solve these systems of equations or what to do. I need to learn how to construct on of these by hand so can you help me? I thought I was getting close when I tried to do it with Ax=b , h0=h1=.25 but I not sure how I keep getting the wrong answer.

Best Answer

Update You wrote the data points backwards, so I will swap those and rework the problem.

For your problem, we are given:

  • $f(-.5) = -.0247500, f(-.25) = .3349375, f(0) = 1.101000$, so, we have the three points:

$$(x,y) = (-.5,-.0247500), (-.25, .3349375), (0, 1.101000)$$

This gives use the values:

  • $a_0 = -0.02475$
  • $a_1 = 0.334938$
  • $c_0 = 0$
  • $b_0 = 1.03238$
  • $d_0 = 6.502$
  • $b_1 = 2.2515$
  • $c_1 = 4.8765$
  • $d_1 = -6.502$

From this data, we write out the two cubic polynomials:

$$1.30419 + 5.90888 x + 9.753 x^2 + 6.502 x^3 \\ 1.101 + 3.47063 x - 6.502 x^3$$

Aside: the Wiki Spline interpolation example more or less works, but is very confusing when interpreting the results, so buyer beware!