- #1
Applejacks01
- 26
- 0
Cubic Spline...what is the logic in constructing it?
Hey guys,
I am not trying to directly code a cubic spline computation, but I am writing a sub routine in VBA that takes input data, and outputs it to a text file in Maple syntax.
Anywho, my cubic spline actually produces LINEAR splines! I can't figure out what is wrong with my logic?!
Here is my logic:
Suppose I have n data points
Then I will have n-1 splines, defined for interval (x_i, x_(i+1)) where i = 1 to (n-1)
I am modeling the spline according to the equation ax^3 + bx^2 + cx + d,
and therefore IN TOTAL I will have 4*(n-1) different coefficients. The reasoning behind that is simple. The first spline has 4 coefficients, the second has 4, etc, and there are (n-1) splines in total.
I am also setting the first and second derivatives equal to zero (and hence equal to each other) at (x_i) and (x_(i+1))
So, here is what I am constraining each spline to:
a(x_i)^3 + b(x_i)^2 + c(x_i) + d = y(x_i)
a(x_(i+1))^3 + b(x_(i+1))^2 + c(x_(i+1)) + d = y(x_(i+1))
3a(x_i)^2 + 2b(x_i) + c = 3a(x_(i+1))^2 + 2b(x_(i+1)) + c
6a(x_i) + 2b = 6a(x_(i+1)) + 2b
So for example, suppose My points are: (-1,.5), (0,0) , (3,3)
I get the following function:
S(x) = (-.5x, -1<x<0
= ( x, 0<x<3
Where is my logic flawed? I would really appreciate any help.
Hey guys,
I am not trying to directly code a cubic spline computation, but I am writing a sub routine in VBA that takes input data, and outputs it to a text file in Maple syntax.
Anywho, my cubic spline actually produces LINEAR splines! I can't figure out what is wrong with my logic?!
Here is my logic:
Suppose I have n data points
Then I will have n-1 splines, defined for interval (x_i, x_(i+1)) where i = 1 to (n-1)
I am modeling the spline according to the equation ax^3 + bx^2 + cx + d,
and therefore IN TOTAL I will have 4*(n-1) different coefficients. The reasoning behind that is simple. The first spline has 4 coefficients, the second has 4, etc, and there are (n-1) splines in total.
I am also setting the first and second derivatives equal to zero (and hence equal to each other) at (x_i) and (x_(i+1))
So, here is what I am constraining each spline to:
a(x_i)^3 + b(x_i)^2 + c(x_i) + d = y(x_i)
a(x_(i+1))^3 + b(x_(i+1))^2 + c(x_(i+1)) + d = y(x_(i+1))
3a(x_i)^2 + 2b(x_i) + c = 3a(x_(i+1))^2 + 2b(x_(i+1)) + c
6a(x_i) + 2b = 6a(x_(i+1)) + 2b
So for example, suppose My points are: (-1,.5), (0,0) , (3,3)
I get the following function:
S(x) = (-.5x, -1<x<0
= ( x, 0<x<3
Where is my logic flawed? I would really appreciate any help.
Last edited: