CHAPTER 05.04: LAGRANGE METHOD: Cubic Interpolation: Example: Part 1 of 2   In this segment, we're going to take an example of Lagrangian interpolation. And as we said that these are just forms of polynomial interpolation, just written in different forms.  And we're going to take an example of cubic interpolation.  So the example does have quite a number of algebraic expressions, so you need to be careful about following each of the steps carefully.  So the example says that, hey, we are given the velocity as a function of time, time is in seconds, velocity is in meters per second, and it's given as 0, 0, 10, 227.04, 15, 362.78, 20, 517.35, 22.5, 602.97, and 30, 901.67. So you are given six data points, you're asked to find out the value of the velocity at 16 by using cubic interpolation. So the first thing which we have to think about is that, hey, okay, we're going to do cubic interpolation in order to find the value of the velocity at 16, we have to choose four data points to do that.  So since we are trying to find the value of velocity at 16, that means we've got to take 15 and 20, because these are the two closest points which bracket the value of time, t equal to 16, and so they are around 16, and they're the closest two data points.  Then we have to choose two more data points, so we're going to choose 10 and 22.5, mainly because the distance between 16 and all the points which are given to us, other than 15 and 20, which we have already selected, the minimum distance is from 10 and 22.5.  What I mean by that, the distance here is 16, distance here is 6, the distance here is 6.5, and the distance here is 14 from 16.  So since I've already chosen 15 and 20, because those are the closest points which bracket 16, the other two closest points turn out to be 10 and 22.5. So these are the four data points which you're going to choose for cubic interpolation. So let's go ahead and write this down here.  That means that t0 is 10, the value of the velocity at t0 is 227.04, then we have t0 equal to . . . sorry, t1 equal to 15, so t1 is equal to 15, the value of the velocity at t1 is 362.78, then t2 is 20, the value of the velocity at this particular point is 517.35, and then t3 is 22.5, and the value of velocity at this particular point is 602.97. All we're trying to do here is to isolate the four data points which you're going to choose for our cubic interpolation so that it's clear that what subscripts of time and velocity we have prescribed to them.  So if you go back and look at the original formula for the Lagrangian interpolation, it'll be summation of i equal to 0 to n, Li t v of ti.  So that is the general formula for Lagrangian interpolation, and since we are doing cubic interpolation, that means that we'll have i equal to 0 to 3, Li t v of ti, that's what we're going to have. So if we expand this, we'll have four terms in this summation. So we'll have L0 of t v of t0, that's the first term, because i is equal to 0, then L1 of t times the velocity at t1, and then plus L2 of t times the velocity at t2, then L3 of t times the velocity at t3. So what it is basically saying is that we have to calculate, the velocities are given to us at these four different times, and what we have to do is to weight them with these Lagrangians here which we have, which are functions of time itself.  So if we are able to show what L0, L1, L2, and L3 are, then it simply involves substitution on our part. So let's go ahead and do that, but let's be careful about what we mean by each of those.  If you look at L0 of t, that is equal to the product going from j equal to 0, always starts from j equal to 0, goes all the way up to the order of the polynomial which we have chosen, which is cubic in this case, so it is 3, and j will be not equal to whatever this subscript is, which is i, which is 0, and we'll have t minus tj, divided by t0 minus tj, this subscript is same as this subscript right here.  So this particular product here will then turn out to be t minus t1, divided by t0 minus t1, the second part of the product will be t minus t2, divided by t0 minus t2, and the third one will be t minus t3, divided by t0 minus t3. So similarly we're going to have the other products.  So let's go ahead and write those down, although they are similar, but for completion purposes, I'm writing all of those down. So L1 t now, so i is equal to 1 here, so j will be . . . you're going again from 0 to 3, this never changes once you have chosen what interpolation . . . what order of interpolation you want, but j will be not equal to 1 now, because i is equal to 1 here, and it'll be t minus tj, divided by t1 minus tj.  So this expansion here will become t minus t0, divided by t1 minus t0, then it'll be t minus t2, divided by t1 minus t2, and then it'll be t minus t3, divided by t1 minus t3. So that's what L1 of t is.  So similarly, we have to find two more of these weights, L2 t and L3 t, let's go ahead and find those. L2 t, again, will be the product, j will again go from 0 to 3, but j will be not equal to this number, which is 2, and again, it will be t minus tj, divided by t2, which is this, minus tj. So if we expand this, we're going to get t minus t0, divided by t2 minus t0, then we have t minus t1, divided by t2 minus t1, and then we have t minus t3, because 2 will be skipped because of this, and it will be t2 minus t3. Same thing here for L3 t, will be equal to Pi, j equal to 0 to 3, and j will be not equal to 3 now, because again, i is equal to 3, so j not equal to 3.  Again, t minus tj, divided by t3 minus tj, this 3 same as this one here.  If we expand this, we're going to get t minus t0, divided by t3 minus t0, times t minus t1, divided by t3 minus t1, and then t minus t2, divided by t3 minus t2.  So those are how the weights of these each individual velocities will be calculated.  So if I was going to now write down the expression for the velocity itself, then all I have to do is to substitute these L0, L1, L2, L3 into the original formula.