views:

1557

answers:

4

I have some nice Cubic spline code, but it is for interpolation only. now I need to extrapolate just a little into the future.

For example the series shown here:

http://en.wikipedia.org/wiki/Extrapolation

Anyone know of a good source of CODE for doing this (not a library)

This is the code I wrote in basic (now ASM) for interpolating http://www.coastrd.com/basic-cubic-spline-interpolation

+1  A: 

You'll really have to expand that question a little. Also, "cubic spline" is a very wide term.

If you're interested in splines, I can heartly reccomend Carl de Boors "A Practical Guide to Splines". It is however a little mathematically oriented, but it has code examples included (they can be downloaded from the author's home page). Googling and wikiing for "cubic spline" can bring up some examples, maybe even in particular languages - another thing to add to the question (if you're looking for code).

If you're interested in extrapolation and curve fitting, googling those could help. Matlab package has a very nice curve fitting toolbox. Wikipedia has some links to useful references

Really, it is too wide a question, to even start guessing an answer.

Also, could you explain what exactly are you trying to do ? What kind of data ? Anything ?


Edit1: Here, try this: you may find something useful in here - link

ldigas
MATLAB is a library, im looking for code as mentioned.I have a seriesof data points producing a curve. I need to extend the curve foreward just a little. Its no more complicated than that.
Mike Trader
Well, just take the last 3rd order curve you've got and calculate the desired values then. If you've fitted it through, you've already got the coefficients.
ldigas
This code was written many many years ago when I could do this level of math easily. Now I would have to tear the whole thing apart and brush up on the concepts... non trivial. I was hoping this post would prompt a link to some code...
Mike Trader
But you have to know *something* about the algorithm used, and the code you wrote. After all, this is trivial if you wrote the spline in the first place. I cannot give you any help regarding code, because I don't know what you did. As I said in my post, "cubic spline" is not an exact description, really.
ldigas
+1  A: 

Generally for spline interpolation you use a variable t to interpolate over the line. As long as 0 <= t <= 1 you're interpolating. However, when t < 0 or t > 1 you're simply extrapolating the spline.

Jasper Bekkers
yes that is correct. I need datapoints for t > 1 in this example (but only slightly > t
Mike Trader
Just evaluate the spline formula with t > 1, for small t you should be fine.
Jasper Bekkers
+1  A: 

You don't need new code for that.

To extrapolate the spline you can extrapolate the parameters of the first and last spline.

Depending on your existing code/library that might not be possible without modifying the code. In that case just prepend/append two other points to the beginning/end of your list of points. You can get those two points by linearily interpolating between the first/last two points.

Be careful: Depending on the original meaning of the points that extrapolation might be completely inappropriate, especially when it comes to statistical data. In that case you should consider using regression analysis.

DR
>You can get those two points by linearily interpolating between the first/last two points.That defeats the purpose of the exercise. I want to extend based on the CURVE produced by the spline.
Mike Trader
A: 

You need to write better requirements for requested code. Splines are usually used for interpolation of some unknown or complex function by using of some fixed data set. If you want to have an estimate of function's value outside of boundaries of this data set then you shouldn't use splines.

If your spline is function defined in the place where you really want to evaluate your value (cubic, but not piecewise-cubic) then you already can evaluate that value.

If you want to have ability to evaluate your spline outside of interpolation range, but leave it as piecewise-cubic function with the same values inside of interpolation range then you should extend spline range by some nodes, and add some logic of evaluation values at the new nodes (for example you want to have your spline be not only a continuous function, but also have some number of first derivatives be also continuous functions)

Really I suggest you to use some algorithm more suitable for extrapolation, like usage of Lagrange polynomial if everything you really need is single value not very far from points of original data set.

Dmitriy Matveev
>you shouldn't use splines. Why not? The 3rd order polynominal is already calculated. I just need to use the"curvature" and extend foreward slightly. I will study the Lagrange polynominal
Mike Trader