Cubic Spline what is the logic in constructing it?

  • Thread starter Applejacks01
  • Start date
  • Tags
    Cubic Logic
In summary, the conversation is about the logic behind constructing a cubic spline. The person is writing a subroutine in VBA and is having trouble with their cubic spline producing linear splines. They explain their logic, which involves using 4 coefficients per spline and setting the first and second derivatives equal to zero at the endpoints. They also mention constraints for each spline, including the first and second derivatives being equal at each node and the spline being continuous. After some edits, they were able to fix their logic and produce accurate solutions.
  • #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.
 
Last edited:
Mathematics news on Phys.org
  • #2


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:

Related to Cubic Spline what is the logic in constructing it?

1. What is a Cubic Spline and how is it used in scientific research?

A Cubic Spline is a mathematical function that is used to interpolate between data points in order to create a smooth curve. It is commonly used in scientific research to analyze and visualize complex data, such as in the fields of engineering, physics, and computer science.

2. What is the logic behind constructing a Cubic Spline?

The logic behind constructing a Cubic Spline is to find the best fit curve that passes through all of the given data points while minimizing the error between the curve and the data. This is achieved by using a system of equations and solving for the coefficients of the spline function.

3. How does a Cubic Spline differ from other interpolation methods?

A Cubic Spline differs from other interpolation methods, such as linear or polynomial interpolation, because it uses a piecewise polynomial function to connect the data points rather than a single continuous function. This allows for a smoother and more accurate curve to be created.

4. Can a Cubic Spline be used for both 1-dimensional and multi-dimensional data?

Yes, a Cubic Spline can be used for both 1-dimensional and multi-dimensional data. In 1-dimensional data, the spline function is a continuous curve, while in multi-dimensional data, it is a surface or higher-dimensional shape.

5. What are the advantages of using a Cubic Spline in scientific research?

There are several advantages to using a Cubic Spline in scientific research. Firstly, it allows for a more accurate representation and analysis of complex data. Additionally, it can handle missing data points and outliers better than other interpolation methods. Lastly, it can be easily adjusted and modified to fit different types of data, making it a versatile tool for researchers.

Similar threads

Replies
1
Views
1K
Replies
1
Views
1K
Replies
7
Views
2K
Replies
3
Views
821
  • General Math
Replies
7
Views
910
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Replies
16
Views
3K
Replies
2
Views
1K
Replies
9
Views
1K
  • General Math
Replies
1
Views
1K
Back
Top