.
In this segment, we're going to talk about linear spline interpolation.
So we're going to talk about the theory
in this particular segment, and we'll take an example in the next segment.
The theory of liner spline interpolation is simple, that somebody is
giving you n plus 1 data points, let's suppose, x0, all the way up
to xn, yn, and somebody's saying that go ahead and
interpolate the data
to linear splines.
So let's see how that can be done.
Now, the first thing which you have to understand about linear splines is that these
values of x0, x1, and so on and so forth, they have to be in some kind of ascending or descending
order, so maybe I should write it down here, x0 is less than x1 is less than x2,
all the way up to less than xn.|So they need
to be in some kind of ascending or descending order, so you do need to have x0 less than x1
less than x2, and the last one less than xn.|If the data is not given to you in
that particular form, where x0 is less than x1 and so on and so forth, you need to just rearrange
the data.|It doesn't mean that you cannot do spline interpolation, but you do need to rearrange it
so that it's in that particular form.|So we can assume that somebody is giving it to us in that particular form.
If not, then we're going to change it accordingly.|So let's go ahead and see that
what linear spline interpolation is all about by drawing a figure here,
by showing the data points.|So if I have x0, y0 here,
and then I have x1, y1 here, and let's
suppose this is xi, comma, yi, and let's suppose this is x-sub-i-plus-1
comma, y-sub-i-plus-1, some intermediate data point, and let's suppose the last
one is xn, comma, yn.|So I have these data points of y versus x.
What linear spline interpolation is all about is simply drawing straight lines.|You're going to
draw a straight line from one point to the next one, so you're going to draw
straight lines between consecutive data points.|Similarly, you're going to draw a straight line right here
between xi and x-sub-i-plus-1.|Similarly, you're going to draw a straight line here
between xn-minus-1, y-sub-n-minus-1, and xn,
yn.|So you're simply drawing separate straight lines between two consecutive data
points, that's all you are doing in linear spline interpolation.|So if somebody told you, hey, I want you to find
out the value at some other point, let's suppose, then you will take this particular linear spline,
and find out what the value of y at that particular value of x is.|So that's how linear
spline works.|So if I was going to write a general formula, then the function
f1 of x, for example, which is standing for linear spline,
for this spline, which is between xi and x-sub-i-plus-1, it will be yi, plus
y-sub-i-plus-1 minus yi, divided by
x-sub-i-plus-1 minus xi, times x minus xi.
That's what it'll be, because that's the equation of a straight line.|That's the equation of a straight line between
two data points, and of course, this particular spline will be only valid between xi
and x-sub-i-plus-1.|So it's going to be only valid between the
points of xi and x-sub-i-plus-1, and that's the equation
of a straight line.|So you can write down the same equations for any other spline.
So for example, if I was going to write down the equation for the first spline, it would look like this,
y1 . . . y0, plus y1 minus y0, divided by
x1 minus x0, times x minus x0, and this will be valid between
x0 and x1.|So that's the equation
of the spline which is valid between x0 and x1.|So if I have a point x which is
between x0 and x1, I just plug in the value of x in there, and I'll be able to get the value of the
linear spline data at that particular point.|Similarly,
the second spline, which is from x1 to x2, will be
y1, plus y2 minus y0, divided by x2
minus . . . sorry, y2 minus y1, x2 minus x1,
times x minus x1, and this will be valid between x1
and x2.|So similarly, if I go all the way down,
the linear spline which I will have for the last data point will be y-sub-n-minus-1, plus
yn minus y-sub-n-minus-1, divided by xn minus x-sub-n-minus-1,
times x minus xn-minus-1.|Again, it will be valid
for the last . . . for any value of x between the last two data points, which will be x-sub-n-minus-1,
less than equal to x, less than xn.|So what you are basically finding
out is that the equations of the linear splines are separate for each of the two consecutive
data points, as you're seeing from these things shown here.
So that's how linear spline works.|Linear spline works just like your linear interpolation, the
only thing is that you are writing down the equations for every two consecutive data points, so as to be
able to write down the splines going from the first data point to the last data point, so that's
what linear splines is all about.|Now, one of the drawbacks of linear splines
is that, let's go back to this figure here, so let me draw x2, comma,
y2 here.|So if you look at this figure here, what you are finding out is that
the drawbacks of a linear spline is that you are finding out that the value
of the function, or the value which you are trying to find, is only dependent
on this straight line.|There is no consideration given to the
values of the y at any other data point, because you are finding out this linear
spline by just taking the values at x equal to x0 and x equal to x1.
So if you are going to find the value of the function at some point here, let's suppose, you will only consider
the value of x at x0 and the value at x1, the other points
do not make any difference to what your estimate will be.|So what
you are doing is you are using only limited information to find the value of y at x.|The second
one is right here, that if you look at this, this is called an interior knot, because the
reason why it's called an interior knot, because it's an interior data point, and it's a knot
because it is shared by two lines.|So at the interior knot, what you are finding out here
is that your derivative is suddenly changing.|So imagine that you had a smooth
velocity versus time data given to you, so y was velocity, x was time,
what you would find out is that at this particular point, artificially you're going to get discontinuity in the
acceleration, because the derivative is piecewise continuous.|So those are two drawbacks
of linear spline interpolation which you've got to keep in mind.|One is that it's not able to use the information
from other data points, other than the two which you have taken to draw the straight line, and the second one is that
the derivatives are not continuous, even the first derivative is not continuous, let alone the second derivative and so on
and so forth, that the first derivative is not continuous, because you do get a piecewise
continuous derivative there.|And that's the end of this segment.
.