## Cubic Spline Interpolation Tutorial

great tuto, very precise. Thanks a lot

 I have trouble implementing the interpolation. not sure what is wrong. appreciate if someone can point out which part I'm wrong. Im pretty sure I have the coefficients correct but somehow im using the spline equations incorrectly (my guess). So here are my original x and y x y 0.90 1.30 1.30 1.50 1.90 1.85 2.10 2.10 3.00 1.95 3.80 0.40 4.30 0.25 Here are my coefficients a b c d Equation 1 -0.282 0.000 0.545 1.30 Equation 2 1.046 -0.338 0.410 1.50 Equation 3 -4.815 1.545 1.134 1.85 Equation 4 -0.162 -1.344 1.174 2.10 Equation 5 1.757 -1.780 -1.638 1.95 Equation 6 -1.625 2.437 -1.112 0.40 Now If I want to interpolate x=1, my formula would read y=-0.282*(1-0.9)^3 + 0.000*(1-0.9)^2 +0.545*(1-0.9) + 1.30 y=1.354230991 I think the answer is wrong because I validated it against the utility at http://www.akiti.ca/CubicSpline.html.. Would appreciate if someone can tell me if my coefficients are correct and if i am using the formulas correctly. Thanks
 Recognitions: Homework Help Using natural boundary conditions (f" = 0 at either end) I derived the same result as you. The utility doesn't state what algorithm is being used nor what assumptions are being made on boundary conditions. The routines mentioned in the credits refer to Hermite interpolation. If that's what is being used by the utility, then it's a different algorithm than what I posted. From what I read, Hermite interpolation isn't C2 compatible at spline boundaries whereas classic cubic spline interpolation is. Bottom line is that there are many interpolation methods. There is no right one. The other possibility is that the utility is performing cubic spline interpolation but is making some assumption about the end boundary conditions. Just for kicks I was able to replicate the result of the utility by adjusting the slope at the first point to 0.811 and the slope of the last point to 2.226. I checked several points in between and they all matched. Black box utilities are great because they can be easy to use, but a caveat is that you may not know what they are doing.
 Recognitions: Homework Help I believe I've unraveled the mystery of the black box utility. It appears to use cubic splines with end boundary conditions called 'not-a-knot', which is continuous 3rd derivatives in the end pairs of splines. See page 5 in the following link: http://www.maths.lth.se/na/courses/F.../lecture11.pdf This means the cubic term (a in the tutorial) is the same in the end pairs of splines. If we equate the cubic terms of the 1st two splines, the resulting boundary condition after some rearranging is: -h2y1'' + (h1+h2)y2'' - h1y3'' = 0 There is a similiar condition at the other end. If these are used as the end boundary conditions, the resulting splines produce the same results as the utility. Fyi, according to the link, MATLAB uses this boundary condition. An interesting way to confirm would be to obtain 4 interpolated points from the utility (2 end points are given so you'd just need 2 intermediate points), from which you could easily derive the coefficients of the cubic polynomial and compare to the ones calculated using the algorithm in the cubic spline tutorial (and not-a-knot boundary conditions). They should match.
 Hi all, I have a stupid question regarding calculating the derivative of cubic spline. I'm currently looking at the code here http://www.ee.ucl.ac.uk/~mflanaga/java/CubicSpline.java at method calcDeriv(), and I do not understand what are these 2 lines are for sig=(this.x[i]-this.x[i-1])/(this.x[i+1]-this.x[i-1]); p=sig*this.d2ydx2[i-1]+2.0; Any help would be appreciated. Cheers, Wins
 Hi All, I am trying to convert a file that has three arrays of 528 samples into three arrays of 301. The first is log spaced frequency points the second is the impedance values at each frequency and the last is phase values. I have the routines spline and splint. My problem is the the second to last sample [299] is off scale. The last sample [300] is correct. I know it is some kind of boundary problem, but it is beyond me to figure it out. fr,re,ph are arrays[1..528] of float Spline(fr,re,528,re[1],re[528],y2); Spline(fr,ph,528,ph[1],ph[528],y4); fm:=Power((20000.0/10.0),1.0/300); For i:=1 to 301 do begin tempARRF[i]:=10.0*Power(fm,i-1); end; For i:=1 to 301 do begin splint(fr,re,y2,528,tempARRF[i],tempARRR[i]); splint(fr,ph,y4,528,tempARRF[i],tempARRP[i]); end; CloseFile(impFile); For i:=0 to 300 do begin impARR[i].Freq:=tempARRF[i+1]; impARR[i].Res:=tempARRR[i+1]; impARR[i].Phs:=tempARRP[i+1]; end;
 Thanks a lot
 Thanks. It really help me a lot.
 you have no idea how this tutorial helped me it is one of the bests that i found I only wish it had more exemples ty anyway
 Worst thing about this topic is that you get different formulae each time from different tutorials and books. I was freaked out of this diversity before exam and almost screwd a 15 mark question but hope it was all ok
 By using spherical coordinates how can we get the volume of a right circular cylinder with radius a and height h
 Thnks it really helped me a lot on my project that i'm doing... keep up the noble work...lol
 I was just browsing for related blog posts for my project research and I happened to discover yours. Thanks for the excellent information! --------------------- Watch TV Online
 Hello, Thank you for this excellent tutorial! I've now implemented cubic splines in C++ and shared the result on my website should anyone want a reference C++ implementation... Cubic Spline C++ class Marcus

Recognitions:
Homework Help
 Quote by toastedcrumpets Hello, Thank you for this excellent tutorial! I've now implemented cubic splines in C++ and shared the result on my website should anyone want a reference C++ implementation... Cubic Spline C++ class Marcus
Thanks for the acknowledgement on your website!

 Excellent tutorial. Somebody knows the formula to calulate the 95%CI for the spline? Thank you for your help.