I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

Cubic spline

POLY\′s Photo
6 Oct 08, 8:38AM
(3 replies)
Cubic spline
I'm new on this site and my englist poor. Sorry in advance.

Anyway I'll try ti descibe my problem in a few words. I need C++ code calculating cubic spline with "not-a-knot" boundary conditions. I'm not quite experienced in C++ to do this job and I didn't find any appropriate code in the net.

There is similar program on this site but it's not "not-a-knot" (it's natural) and it seems to me it's realized on CS. Also there are many examples on Fortran/Pascal/C/C++ in the net (for example http://www.koders.com/cpp/fid4F41907755E6B96390F4DFEF3A20ADD9A61A3BC1.aspx?s=Chebyshev - quite workable but it doesn't work for 3 knots and too exceeding and slow) but I wasn't be able to find any to handle my problem.

I'd like to ask valuable members is this proper place to distribte an order for C++ coders for reasonable payment?

Best regards. Sergey
will\′s Photo
6 Oct 08, 7:26PM
Hi,

I'll have a look at the code from Koders. I've some familiar with quantlib.

Do you have any good test cases. Before building a new component, it would be useful to see exactly how it might be used, what range of parameters etc you are planning to use. I'm fairly certain with this information we can find someone to help you (if not myself).

Best wishes, will.
POLY\′s Photo
6 Oct 08, 9:41PM
Hi, will. The main points of using this code the following:

1.Input data are three one-dimensional arrays - X - arguments of interpolated function, Y - values of this function, XX - points in which spline should be calculated;

2. Dimensions of this arrays (X, Y) are expected quite big up to 200-300 thousand knots therefore problem of algorithm's performance is critical (the code from Koders processing 50 000 knots about 45 000 000 "units of time" (i don't know exactly what is this :) are measured by QueryPerformanceCounter whereas some other code (for example this one http://forum.sources.ru/index.php?showtopic=9853 ) does this job (but incorrect :) 500 times faster(!));

3. I do need to calculate spline for 3 knots too (and 2 - minimum) (Koders produce an error in this case);

4. Boundary conditions are not-a-knot strictly (the result should fully coincide with the matlab's one);

5. Output is an array of the values of cubic spline in points given in XX. Looks like the most impotant things I've described.

Best regards. Sergey
lucian\′s Photo
7 Oct 08, 11:13AM
Hi Sergey,

I have found some code that does exactly what you need, and is also quite fast. I have tested it for 300,000 knots and it provided an answer in less than 1 second on my 1.6 GHz computer. The code is available at the following link http://www.pcs.cnu.edu/~bbradie/cinterpolation.html

The only drawback is that this library provides several other interpolation routines inside the same header file, and that there are basically 3 functions (cubic_nak, tridiagonal, spline_eval) that you need in order to solve your problem. That's why I suggest that I first create a single class/function based on these 3 functions, and perhaps also optimize their code a bit. In the end we will have new module solving not-a-knot cubic spline interpolation, which should be identical to the matlab version.

I can send you my VC++ project to demonstrate how this library works. Just send me an email and I'll reply as soon as possible. You can send me an email by going to: http://www.codecogs.com/pages/email/sendmail.php?user=lucian~9ca206432b
Currently you need to be logged in to leave a message.