| New Reply |
Cubic Spline Interpolation Tutorial |
Share Thread | Thread Tools |
| Nov24-09, 02:55 PM | #18 |
|
|
Cubic Spline Interpolation Tutorial
great tuto, very precise. Thanks a lot
|
| Jul19-10, 09:59 AM | #19 |
|
|
Thanks
That was helpful |
| Jul21-10, 07:55 AM | #20 |
|
|
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 |
| Jul22-10, 02:08 PM | #21 |
|
Recognitions:
|
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. |
| Jul24-10, 06:03 PM | #22 |
|
Recognitions:
|
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. |
| Aug8-10, 11:02 AM | #23 |
|
|
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 |
| Oct8-10, 08:54 AM | #24 |
|
|
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; |
| Oct11-10, 06:21 PM | #25 |
|
|
Thanks a lot
|
| Oct13-10, 01:40 PM | #26 |
|
|
Thanks. It really help me a lot.
|
| Nov10-10, 01:03 AM | #27 |
|
|
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 |
| Nov30-10, 12:29 PM | #28 |
|
|
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
|
| Dec26-10, 11:15 PM | #29 |
|
|
By using spherical coordinates how can we get the volume of a right circular cylinder with radius a and height h
|
| Feb9-11, 11:41 AM | #30 |
|
|
Thnks it really helped me a lot on my project that i'm doing... keep up the noble work...lol
|
| Feb15-11, 07:53 PM | #31 |
|
|
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 |
| Apr5-11, 07:49 AM | #32 |
|
|
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 |
| Apr6-11, 03:02 PM | #33 |
|
Recognitions:
|
|
| Jul5-11, 10:08 AM | #34 |
|
|
Excellent tutorial.
Somebody knows the formula to calulate the 95%CI for the spline? Thank you for your help. |
| New Reply |
| Thread Tools | |
Similar Threads for: Cubic Spline Interpolation Tutorial
|
||||
| Thread | Forum | Replies | ||
| Spline degree?? | General Math | 2 | ||
| Deriving Greens Theorem for 3D Thin Plate Spline | Calculus | 0 | ||
| Spline in N dimensions | General Math | 1 | ||
| Interpolation | Calculus & Beyond Homework | 1 | ||
| Shortest distance from point to Catmull-Rom spline | General Math | 2 | ||