Cubic spline interpolation constructs smooth piecewise polynomials passing through given data points by solving a system of equations derived from point matching, continuity of first and second derivatives at interior points, and boundary conditions. In natural cubic spline, the boundary conditions set the second derivatives at endpoints to zero, while clamped cubic spline uses specified first derivative values at endpoints. For three data points (1,2), (2,3), and (3,5), the natural cubic spline yields polynomials: s₀(x) = 2 + (3/4)(x-1) + (1/4)(x-1)³ for [1,2], and s₁(x) = 3 + (3/2)(x-2) + (3/4)(x-2)² - (1/4)(x-2)³ for [2,3]. With clamped conditions s'(1)=2 and s'(3)=1, the coefficients change accordingly, demonstrating how different boundary conditions produce distinct spline solutions.
Cubic Spline Interpolation: Natural & Clamped Boundary Conditions
Added:so there are this in this video I'm going to look at cubic spline examples so the question is constructive natural cubic spline that passes through the points 1 2 to 3 & 3 5 now there are two regions here the number X our X points data points belong to one two okay and the other one is of course 2 2 3 okay so within 1 2 we have the polynomial as 0 of X equal so we have that and you'll see that this point here this number here 1 X minus 1 squared X minus 1 sorry X minus 1 X minus 1 squared and cubed this one comes from this the first point in the interval so so now the next one is of course s 1 of X and that's equal to a1 plus b1 into similarly the first point in this is 2 here so this will be X minus 2 this second polynomial so your first step will always be split the regions and for each region you see here there will be a polynomial so there's two polynomials in this case three points means there will be two polynomials two splines so next we our next objective is going to be to look for these eight these eight unknowns so we have eight unknowns to find eight unknowns to find eight unknowns to start with we'll use the point 1/2 so s 0 of 1 should be equal to 2 which means as we substitute the point 1 into S 0 you will see here that this will go to 0 this will go to 0 and this will go to 0 and all it'll leave is the a 0 so a 0 equals 2 so we have one of the points and so we have seven more to go so he found one of these ok similarly we'll go to the next point so s 0 of 2 in fact is equal to so now we have to let me just clarify something here you see these two points here 1 2 & 2 3 ok both are both are in this region from 1 to 2 ok and these two points well this is an overlap and this point are both in this other region 2 3 so the 2 3 point here this one here that you see is overlapping this is where the matching condition also will apply so anyway as 0 of 2 should be 3 according to the data so that means we'll end up with so what's going on here just to show you so what I've done is basically I'm substituting this 2 into here so 2 minus 1 2 minus 1 2 minus 1 all these are ones so you end up with a 0 plus B 0 C 0 D 0 now a 0 we already have so I'm gonna replace that ok and I'm gonna put in sorry this one second I'm gonna put in instead of a 0 will substitute the 2 but anyway this should be equal to 3 and this implies that we end up so we end up with B 0 plus C 0 plus D 0 equals 1 because put in the the value of a 0 is 2 so we end up with this and we label this as equation 1 now we'll go to the next one which is in the second polynomial so let's use the other two data points so we'll use now s 1 of 2 and that's equal to 3 as well remember that also is the matching condition so s 1 of 2 means that when we substitute that end we end up with a 1 equals 3 because when the 2 goes in this will be 0 0 and 0 so they'll all disappear just leave this a 1 alone so a 1 should be equal to 3 so let's put a box around that now we have in fact 6 unknowns to find still and so far we've got one equation so let's move further on as one of the other and last point now is 3 and it should be equal to 5 and s 1 of 3 equals 5 means when we substitute that in we end up with so we'll end up with this does it take the 3 across the other side so we end up with this equation B 1 plus C 1 plus D 1 equals a 2 so we labeled that as our second equation now we'll start using now we'll start using the matching second matching condition which is on the first derivative so let's do that so s 0 dash of X let's compute that as 0 dash of x is going to be a sorry so the first derivative of s 0 turns out to be this B 0 plus 2 0 0 into X minus 1 plus 3 D 0 and X minus 1 squared similarly s 1 prime turns out to be turns out to be this ok so let's move on so the matching addition s 0 dash of 2 should equal s 1 dash of 2 this implies that we will have the situation when we substitute the 2 into the first one here the 0 derivative we end up with B 0 plus 2 0 0 plus 3 D 0 and that should be equal to when we substitute the 2 into the second this equation that you see here the S 1 Prime everything turns to 0 except B 1 so we have this and this turns out to be the equation so we'll label this as equation 3 the other matching condition remember is as same thing only with the second derivative now in order to do that let's just this this implies of course that the second derivative of s 0 turns out to be - c0 + 6 D 0 into X minus 1 ok and this one s 1 double prime of X turns out to be of course 2 c1 + 6 D 1 into X - 2 so now when we substitute and into the first of these the number 2 for X we end up with this implies that we get to C 0 okay + 6 D 0 equals and then the other one we'll put the 2 in remember so that will give us equals to C 1 so that is equation 4 alright now let's move on now now we all applied all the matching conditions so now the only thing that remains is to apply the boundary condition so the boundary condition the boundary condition B see here just short s 0 double prime of the first of the end one of the endpoints the starting point which is 1 should be equal to 0 and of course the other one will be that I'm sorry s one because the other point is 3 remember the other end point so that will that is for this polynomial s 1 double prime of 3 and that should be also equal to 0 so these are the boundary conditions now these conditions will imply the first one of these implies that s 1 double prime s 0 double prime of 1 so if I substitute the 1 in here you'll see that'll go away and leave you with the 2 C 0 so that means that C 0 equals 0 so we found yet another one of the unknowns so we still have now now we've got five to go ok five to go anyway this condition here implies that in the second this expression here the second derivative we put in 3 instead of X so 3 minus 2 is 1 so 2 c1 2 c1 + 6 D 1 equals 0 and we label this as equation 5 so if you see now we've got 5 and we've got five equations now let's update and collect these together with the value of c0 also updating the equations and let's summarize the equations below or next sorry let's summarize the equations next so this is the summary of the equations as you can see here we've got the five equations and we've got five unknowns now I'll I'm not gonna show you the whole solution but I can show you how you can proceed and the one way to do this is of course the best way to do this is to go by solving this as a system of linear equations and that means you need to order your your unknowns first and the order we we we have here is as follows so we have basically got this order B 0 D 0 ok and then B 1 C 1 D 1 and our right hand side so accordingly we'll end up with this system let me just show you here quickly so you have 1 1 and then 0 0 0 the first equation and then 1 and the second equation will be 0 0 1 1 1 2 and then the third equation will be 1 3 D 0 D 0 and minus B 1 minus B 1 so minus 1 0 0 0 this equation here so that's this one done this one done this one done this will be 3 D 0 minus C 1 so 0 3 and the last one will be wait wait excuse me sorry sorry sorry sorry yeah no it's okay right let's finish this off so the last one which is this 1 2 C 1 so 0 B 0 ok 0 and then 0 here as well 2 6 0 so there you have your Augmented matrix and you can use something as simple as Gaussian elimination to solve this and when you do we get this result this implies that B 0 it turns out to be equal to 3 over 4 ok and D 0 is gonna be 1/4 ok and B 1 B 1 is 3 over 2 and then we have C 1 so C 1 is going to be 3 over 4 and D 1 last one here is going to be minus 1/4 so these are these are the values now how we write the final is as follows so we have 2 so this will be the first polynomial remember now let me bring back here remember a is 0 we already have these so just to remind you let's go back here there's a 0 is 2 and a 1 is 3 and remember C 0 is 0 ok so a 0 2 & 3 so a 0 is 2 so a 0 is 2 a 1 is 3 and C 0 is 0 so now we've got one two three four five six and eight of our unknowns so now as we put these together remember the first polynomial is the the with the zero subscript so a 0 is 2 B 0 is 3 over 4 so plus 3 over 4 into X minus 1 okay and then C 0 is 0 so nothing there and D 0 is a so you'll get plus a quarter into X minus 1 cubed and this is for of course X in the first region or the first range first region yeah 1 2 and then the next polynomial is going to be the though the subscript ones so a 1 a 1 is 3 plus B 1 is 3 over 2 into X minus 2 plus C 1 is 3 over 4 into X minus 2 squared plus D 1 is negative 1/4 into X minus 2 cubed and this is for X in the region 2 2 3 so that is that completes our cubic spline interpolation for the three data points so just as an added example just to show you that we used the natural we found the natural cubic spline in this example which you see above there now if we want to do the same problem but find the clamped cubic spline remember all the conditions will be the same except let me just go back here very quickly and you saw this condition here this is the condition that will change everything above all of these conditions and everything all of the equations everything is fine up to equation up to this equation up to 4 everything's good but this these two conditions now will be replaced by other conditions so if we were to do that let's let's so therefore look at trying to continue this with with these two conditions changed and let's see what happens so let's see what happens so let's do that let me just say something else here important in order to solve this problem first of all you will have to be given this condition that s 1 - that s dash of 1 is equal to 2 and s dash at the other endpoint 3 is equal to 1 so these have to be given to you in the question okay so given these conditions this means that s0 - of one should be - and of course s 1 - of 3 should be equal to 1 so these are the two additional conditions and then when we apply these conditions to our polynomial if we go back here I see here this is where we are now this is our s 0 and s 1 this is this is here you'll see as 0 - is this one and s 1 - is this one so we are applying s 0 - of 1 which means all of these will disappear and leave you just with the be 0 here ok so that will mean that B 0 is 2 and s 1 prime of 3 is gonna give us an equation so let's have a look and what results so let's just do that and if if we do we end up with this condition tells us that clearly B 0 is equal to 2 and s 1 3 - is equal to 3 gives us this equation that be easier be sorry 1 plus 2 C 1 + 3 D 1 is equal to 1 so we get this equation so now if we were to summarize our equations I've just written them here again for you a 0 is 2 so all of these equations now we need to update them with B 0 equals 2 so if we do that in here so if I can so this equation this will be changed and this will become C 0 plus D 0 equals the B 0 is to go the other side gives us minus 1 ok and this equation of course will also need to be updated and will be 2 C 0 + 3 D 0 minus B 1 equals we'll take the 2 to the other side so it's minus 2 so that becomes minus 2 so that one's updated and now we have this system of equations which when we solve in fact like I said in the previous in the previous example as we solve it to be end up with the following result s of X turns out to be this time equal to you can see here this is the resulting polynomial and what I want to do is just show you both here so you can see the difference between these two here you'll see that 2 3 same 2 3 same three 4s changed as you can see this is 2 this this 3 over 2 is the same this 1/4 has become minus 5 over 2 it's this is different as well and you can see there's a cubic appearing here and there was there here the square was missing now it's appearing here and so on so anyway you can see the clamped condition gives you a different polynomial fit or a cubic spline so now this brings us to the end of this example so we've looked at two examples one with the same same three data points nor natural cubic spline and clamped cubic splines we'll stop
Up Next

Simpson's Rule & Numerical Integration | Calculus Tutorial
@TheOrganicChemistryTutor
812.9K views•2018-03-13

Gain Recalibration in Hippocampal Path Integration: Math Theory
@1024kyz
144 views•2020-07-02

Cubic Spline Interpolation Basics | Numerical Analysis
@the-Math-guy
88.6K views•2017-10-30

The Mathematical Impossibility of Accurate World Maps
@Vox
23.3M views•2016-12-02
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Mathematics







































