And the following I want to explain to you two methods and how we can fit the data that we have just
created.
The first method will be quite mathematical.
So not really related to a physical model, but just like the mathematically ideal approach here, I
will consider Splice.
So maybe you have heard of spleens already.
They are typically used in graphics programs, for example.
But yeah, they're very, very useful, but not really related to any physical model.
So then the second option will, of course, be then in related motor physics so that we will use some
model function that could be motivated by some theory.
And then we have coefficients in this model functions that we are trying to optimize to reproduce our
data.
So first of all, let us use the unperturbed data and let's try to use Blind's to interpolate the data.
And yeah, I wrote down that explain interpolation always fits the data perfectly and even have it has
a continuous derivative.
If a cubic spined blind is used and therefore the spleen is simply defined piece wise.
So basically, you take neighboring points like this and that, and then you use either a linear function
between those.
So this would be really the most easy way of interpolating.
These just take linear functions connecting the dots or you use third order polynomials.
And so what is really, really nice about the third order polynomial is that then the derivative were
two of these political formulas.
Meat is still continuous, so it looks really, really smooth.
And that is very useful also for some algorithms that you can do then later on with this data.
But of course, it is a nice thing on one hand side that every data point is fitted perfectly, but
also it's a bit unrealistic.
For example, if we think about this in terms of physical data that we have some noise, so then we
do not actually want that.
We have some very complicated function connecting all of these dots, but we want to have a rough function
going roughly through these dots.
So let's see how this works out in detail.
And that's yeah, let's use this spline interpolation.
So we begin by looking once again at our data.
So for this, we can just load this one just so that we have it here.
And then the next step we will do is we will load the molecule so pi.
And from there, we will load just to interpolate commands.
So you see inside Pi, which is a module for Python.
There is already a method implements.
It's called Interpolate, and we will use this in the following we will not construct these lines by
ourselves.
So we will start with the linear splice basically just connecting the dots.
This would actually be pretty easy to do ourselves.
We would just have to define a Piece Y's function.
And then we would just have to define the lines connecting the dots.
But here, since we have loaded this interpolate command, it's even more easy so we can just write
interpolate dots and then the command is into p 1d and then we must give the X values.
So this would be theta zero zero and then the Y values theta zero one, and then we must define the
type of the interpolation.
And here the argument is then kind and the string with the type of interpolation.
And here, first of all, we want to use linear and we want to store this function that will be generated
in the variable or in the function.
We give it a name called spline linear zero.
And now we have our spleen function.
We can, of course, plot this.
So I will take this one, copy it here and then use a new line p t dot plot and here right data zero
zero for the X values and then for the Y values, I will use spline linear zero acting on data zero
zero.
And so you see the lines here, they are really explained supplying function and the function connects
all of the dots.
So maybe now it's a good idea to zoom in.
So I have to zoom here and.
To zoom in, we will just redefine the X range into why rates, so I would write X plot Dot X line going
from two to four.
And then we have to adapt also the Y limits.
And I've found that it looks quite good when we use minus five to 15.
So then this will be our plot and you see that we have now points that are our data points and they
are connected just by straight lines.
And of course, they are just connected by straight lines because we say that we want to create a plot
where we have pairs of X and Y values and they can just be connected by dots.
So just to make sure that these are really straight lines, we should increase our resolution for this
plot here.
So I write X list, which will be a list for the plot here.
So just for the plot, not for the fit and for this arrow right and p dot line space from two to four.
And now I will not just use a very few points, so here I have five points.
Instead, I will use 201 points and you see the plot doesn't change at all.
So, for example, if it is your setup, then oh sorry my, that I have to change this, of course x
list.
And you're also x list.
Then you can see we have no many, many points.
So let's go back to plots and you see it's still the straight line.
So all the points that are just correct by this line, linear zero are these piece wise linear functions.
And this is, of course, OK.
In a sense, if you have a lot of data points and you don't really care about the derivatives because
on this plot range here looks quite good.
But when you zoom in, you see the derivative is discontinuous and this is, of course, very on physical.
If you relate this data to some real world problem, then this can be very, very, very bad.
And to solve this problem, we can use a cubic spine and we can do this in the following way.
Let me copy the plot here, and then let me copy also the command for creating this plane.
And then we could call this here blind cubic.
And here we just have to change the optional argument to cubic.
And then here are right.
Also quick, and I think that should be it already.
And you see, now we have cubic spines.
So a third order polynomial connecting these dots and you see the derivative is now continuous and it
works very, very well.