Cubic Spline what is the logic in constructing it?

  • Thread starter Thread starter Applejacks01
  • Start date Start date
  • Tags Tags
    Cubic Logic
Applejacks01
Messages
26
Reaction score
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.
 
Last edited:
Mathematics news on Phys.org


EDIT: In my code I was forcing the derivatives to be equal to zero at the end points of S(x), i.e x_0 and x_n. I loosened that constraint up by just making them equal each other, and now I produce pretty nice solutions.

EDIT 2: Consider this solved. I set the 2nd derivatives of the end points to 0, and removed the constraint that the first derivatives be 0 or equal to each other at the end points. Not sure why I thought that was right.

====================
I fixed my logic up...and now I'm getting empty solutions.
Here are my new constraints, which I figured would be correct

At the end points of S(x), my piecewise cubic spline function, S'(x) and S''(x) = 0.
I.e Once again, for n data points:
First Derivative at x_0: 3a(x_0)^2+2b(x_0)+c(x_0)+d = 0
First Derivative at x_n: 3a(x_n)^2+2b(x_n)+c(x_n)+d = 0
Second Derivative at x_0: 6a(x_0) + 2b = 0
Second Derivative at x_n: 6e(x_n) + 2f = 0

At each node of S(x), i.e, at the endpoint of each intersecting spline, the derivative and second derivative of each spline is equal.
The following shows what I mean:
If we have any node, (x_i,y_i),where 0<i<n(strictly) and two splines, az^3+bz^2+cz+d, ez^3+fz^2+gz+h, then we have:
First Derivative at x-value x_i: 3a(x_i)^2+2b(x_i)+c(x_i)+d = 3e(x_i)^2+2f(x_i)+g(x_i)+h
Second Derivative at x_i: 6a(x_i) + 2b = 6e(x_i) + 2f

The final constraint is that the Spline be continuous, and therefore for all x_i, 0<=i<=n,
S(x_i) = a(x_i)^3 + b(x_i)^2 + c(x_i) + d and S(x_(i+1)) = a(x_(i+1))^3 + b(x_(i+1))^2 + c(x_(i+1)) + d must hold to ensure both points in each sub interval are contained in the spline,
additionally S(x_(i+1)) = e(x_(i+1))^3 + f(x_(i+1))^2 + g(x_(i+1)) + h must hold to ensure continuity from spline to spline.
 
Last edited:
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
I'm interested to know whether the equation $$1 = 2 - \frac{1}{2 - \frac{1}{2 - \cdots}}$$ is true or not. It can be shown easily that if the continued fraction converges, it cannot converge to anything else than 1. It seems that if the continued fraction converges, the convergence is very slow. The apparent slowness of the convergence makes it difficult to estimate the presence of true convergence numerically. At the moment I don't know whether this converges or not.
Back
Top