ExpertAlmost Posted July 13, 2010 Share Posted July 13, 2010 Good morning! I have a set of discrete data points from which I need to interpolate new values. My (neophyte) mathematical research suggests that cubic spline interpolation gives the best result with the least amount of calculation overhead. I expected to find any number of functions in PHP (input two x,y points, and a point to interpolate: output the interpolated point) but cannot find any. I find C/C++ code, Matlab, even VBA. I could probably port some of that code over, but can anyone point me to so tested-ready-to-run code? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/207565-looking-for-cubic-spline-interpolation-code/ Share on other sites More sharing options...
ChrisA Posted July 13, 2010 Share Posted July 13, 2010 Cubic spline looks like some fairly hardcore maths to code up. Whats the background to the interpolation required? Is is in 1D, or 2D? As an aside, for anything other than basic linear interpolation, you would need to input more two input points. Anything more complicated meeds to know a larger area which it can use to interpolate. Quote Link to comment https://forums.phpfreaks.com/topic/207565-looking-for-cubic-spline-interpolation-code/#findComment-1085290 Share on other sites More sharing options...
ExpertAlmost Posted July 13, 2010 Author Share Posted July 13, 2010 "Hardcore" is a great word for it Actually, I have a set of 50 data points, with some of the points clustered. This is not for a graphics application, but for a statistical one. What I eventually need to do is find the points that approximate 5%, 80% and 95% areas under the curve described by those points. Rarely (eg. randomly) will my actual data points hit those values. Similar to an approximation done under a bell curve but I do not have the luxury of that simplicity. Once I figure out how to do the cubic spline interpolation, I was going to use a simple trapazoidal method. Another piece of PHP code I hope to find Of course if I found a piece of code that gave me the solutions for 5%, 80% and 95% areas under a curve given a set of data points.....well....I could....take a nap Any ideas? (for the math or code --- naps I can manage) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/207565-looking-for-cubic-spline-interpolation-code/#findComment-1085294 Share on other sites More sharing options...
ChrisA Posted July 13, 2010 Share Posted July 13, 2010 Is this a particular curve with a formula, that you could perhaps fit to the points you have? Then use the formula to calculate your points? Or would cubic interpolation be good enough? Quote Link to comment https://forums.phpfreaks.com/topic/207565-looking-for-cubic-spline-interpolation-code/#findComment-1085308 Share on other sites More sharing options...
ExpertAlmost Posted July 13, 2010 Author Share Posted July 13, 2010 It is financial data...so the arguments abound about various curves fitting and various fixes to various curves making things fit, etc. Cubic spline interpertation is certainly close enough. Rather than spend 20 hours coding and testing php splines code, I would go to linear if I had to. I was just hoping for some luck. Cubic splines is not a new process nor is approximating areas under curves using trapezoids (Riemann sums). I am actually a bit suprised these are not in the PHP library! What happened? hahahaha Hoping for the best Quote Link to comment https://forums.phpfreaks.com/topic/207565-looking-for-cubic-spline-interpolation-code/#findComment-1085313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.