So far, we have discovered the Taylor expansion, we have discussed the properties of polynomials,
and we have found that basically any continuous function can be expanded in terms of a Taylor expansion.
So of course, in this total expansion, we can never take into account all terms because there is an
infinite number of these terms, but we have to stop at some point.
But we've also seen that even for difficult functions, the approximate form of the Taylor expansion
works quite well in the vicinity of the value zero that we have chosen for the expansion of the series.
So what we do next is we will use polynomials to interpolate functions or better to say, to interpolate
data, to get the function that describes this data.
So this is a very, very common phenomenon in science and in physics, for example, where you do some
measurement and you know, the mechanism that is behind the data that gave rise to the data.
And then you have a model function, for example, and then you try to fit some parameters so that you
find out what exactly are the parameters that allow you to describe the measured data in terms of the
model function?
And of course, I could have just started this lecture here by giving you some data points, but I think
it's also a good practice and a good exercise to to find these data points and to generate the data.
And also then I can be very honest with you what the data is and how it has been generated.
So first of all, I will define here a function called correct data.
Sorry, correct function.
And the argument would just be so this will be a one dimensional problem and the future will be some
polynomial because we have seen that polynomials are quite nice.
So let's use a polynomial here, but it's in general not really necessary to do.
But I will use it because then we know also the coefficients.
So I will talk about this in a second.
So this will be our function.
And you see, it's a third order polynomial where we have four coefficients 15 two point four minus
0.5 and minus zero point three five.
And what we will do later on this, we will establish a model function, which will be a polynomial
and a third order polynomial.
And then we will try to fit the coefficients here to fit the data that we are going to create using
this correct function.
And then we can compare if the parameters that we have determined by this fit are correct because we
know what are the correct values.
These are these coefficients you.
So let me go ahead and define some some constants here, called number of points.
And let's use 21 and then we have an ex list that is given violin space.
And it goes from minus five to five, and the number of points will be and points.
And our data with which we will start will be data zero will be an array and the coordinates will of
course be given by the list at the Y, coordinates will be given by a correct function acting on the
ex list.
So I run both of these cells and now we should have our data so we can we can look at it by writing.
But clotting experts is why.
So we can do it like this, of course.
And then we just write penalty dot plot data, zero comma data one.
And of course, we want to plot here data zero and data zero.
So this will be our third order polynomial.
And if I use your scatter.
With Tuti, of course, then you see, this is our data that we have generated, and these are the points
that we try to fit.
However, in reality, when you do measurement and experiment, the measured data is not always that
perfect.
So there is some noise in the data and there is some error in the data.
And here, for example, you could definitely see easily, OK?
We just take a 3.0 polynomial and then it should work.
But actually, this data will be blurred and it will be distorted in reality.
So what we will do next is we will modify the X and Y values by adding some random numbers, and I will
do this in the following way we will right and p dot random dot rant.
And then we can just say, for example, end points.
And this will give us an array of 21 points in this or 21 random values in this case, and the random
values will be in the range of zero and one.
So if we want to have it in the range of minus one and one, we just have to subtract one and then we
have to multiply
two.
But only two the first yeah, to to randomize itself.
So then the range will be from minus one to plus one.
OK, and then we can, of course, scale it with any value that we want, for example, zero point one
and then the range will be in the range of minus 0.1 + + 0.1.
So what I will do next is I will create P file or an R equal data and it will be an array.
And this array will be based on our previous data as a data zero and data one, data zero zero and data
zero one.
And so I can basically it could just copy them here.
But what I want to do instead is I will write X List, which is data zero zero plus, and then I tested
what looks good.
Basically, this random random command here, this array of random numbers scaled by a 0.25.
So this will be the will you.
And then for the Y value, we take
our basically or.
So so we have we could also see just data zero zero.
And then for the Y value, we take data zero one.
And here we add a similar thing.
But I tested that's 0.25 is maybe a bit too low.
Let's use a higher value of five point zero.
So I think, or I hope that I don't have a typo here.
Let's test let's copy this code and use data instead of data zero.
And OK, yeah, we have some blurred values here.
So what we can do now also is we can
plot the actual function to see what is here, the difference so we can write X list.
Well, we could also write, you know, later zero
zero and date zero one and the color will be black.
So this will be the correct function that we have used for creating the data.
And then you see, due to the random fluctuations we have that our data on this one will be a bit different.
So this could be quite real realistic physical situation from a measurement where you have some noise
on top of your data.
And so in the following, we will discuss which options we have to fit this function.
For example, I mean, we know what is the correct function to fit this because we have created the
data.
But let's say we have just a measurement with these points.
How would we find out what would be a good fit or a good description of this data?
And then the following lectures we will talk about spleens and fitting model functions.