1
00:00:00,030 --> 00:00:05,310
And the following I want to explain to you two methods and how we can fit the data that we have just

2
00:00:05,310 --> 00:00:05,910
created.

3
00:00:06,630 --> 00:00:09,030
The first method will be quite mathematical.

4
00:00:09,390 --> 00:00:16,230
So not really related to a physical model, but just like the mathematically ideal approach here, I

5
00:00:16,230 --> 00:00:18,050
will consider Splice.

6
00:00:18,600 --> 00:00:20,520
So maybe you have heard of spleens already.

7
00:00:20,790 --> 00:00:24,030
They are typically used in graphics programs, for example.

8
00:00:24,450 --> 00:00:29,220
But yeah, they're very, very useful, but not really related to any physical model.

9
00:00:30,270 --> 00:00:35,310
So then the second option will, of course, be then in related motor physics so that we will use some

10
00:00:35,310 --> 00:00:38,730
model function that could be motivated by some theory.

11
00:00:39,150 --> 00:00:45,120
And then we have coefficients in this model functions that we are trying to optimize to reproduce our

12
00:00:45,120 --> 00:00:45,570
data.

13
00:00:46,740 --> 00:00:53,940
So first of all, let us use the unperturbed data and let's try to use Blind's to interpolate the data.

14
00:00:55,020 --> 00:01:01,680
And yeah, I wrote down that explain interpolation always fits the data perfectly and even have it has

15
00:01:01,680 --> 00:01:03,660
a continuous derivative.

16
00:01:04,260 --> 00:01:14,160
If a cubic spined blind is used and therefore the spleen is simply defined piece wise.

17
00:01:14,640 --> 00:01:21,090
So basically, you take neighboring points like this and that, and then you use either a linear function

18
00:01:21,090 --> 00:01:21,830
between those.

19
00:01:21,840 --> 00:01:26,370
So this would be really the most easy way of interpolating.

20
00:01:26,370 --> 00:01:32,100
These just take linear functions connecting the dots or you use third order polynomials.

21
00:01:32,880 --> 00:01:38,700
And so what is really, really nice about the third order polynomial is that then the derivative were

22
00:01:38,730 --> 00:01:40,020
two of these political formulas.

23
00:01:40,020 --> 00:01:44,640
Meat is still continuous, so it looks really, really smooth.

24
00:01:44,640 --> 00:01:50,760
And that is very useful also for some algorithms that you can do then later on with this data.

25
00:01:52,020 --> 00:01:59,970
But of course, it is a nice thing on one hand side that every data point is fitted perfectly, but

26
00:01:59,970 --> 00:02:01,620
also it's a bit unrealistic.

27
00:02:01,890 --> 00:02:07,200
For example, if we think about this in terms of physical data that we have some noise, so then we

28
00:02:07,200 --> 00:02:08,520
do not actually want that.

29
00:02:08,520 --> 00:02:14,280
We have some very complicated function connecting all of these dots, but we want to have a rough function

30
00:02:14,280 --> 00:02:16,200
going roughly through these dots.

31
00:02:17,190 --> 00:02:19,770
So let's see how this works out in detail.

32
00:02:19,770 --> 00:02:23,910
And that's yeah, let's use this spline interpolation.

33
00:02:24,900 --> 00:02:30,090
So we begin by looking once again at our data.

34
00:02:30,510 --> 00:02:38,370
So for this, we can just load this one just so that we have it here.

35
00:02:40,140 --> 00:02:45,780
And then the next step we will do is we will load the molecule so pi.

36
00:02:46,140 --> 00:02:49,530
And from there, we will load just to interpolate commands.

37
00:02:50,580 --> 00:02:55,320
So you see inside Pi, which is a module for Python.

38
00:02:55,680 --> 00:02:57,490
There is already a method implements.

39
00:02:57,490 --> 00:03:04,080
It's called Interpolate, and we will use this in the following we will not construct these lines by

40
00:03:04,080 --> 00:03:04,710
ourselves.

41
00:03:05,610 --> 00:03:10,680
So we will start with the linear splice basically just connecting the dots.

42
00:03:11,220 --> 00:03:14,070
This would actually be pretty easy to do ourselves.

43
00:03:14,080 --> 00:03:16,320
We would just have to define a Piece Y's function.

44
00:03:16,710 --> 00:03:21,450
And then we would just have to define the lines connecting the dots.

45
00:03:22,260 --> 00:03:27,780
But here, since we have loaded this interpolate command, it's even more easy so we can just write

46
00:03:27,900 --> 00:03:38,040
interpolate dots and then the command is into p 1d and then we must give the X values.

47
00:03:38,050 --> 00:03:47,430
So this would be theta zero zero and then the Y values theta zero one, and then we must define the

48
00:03:47,430 --> 00:03:48,870
type of the interpolation.

49
00:03:48,870 --> 00:03:56,130
And here the argument is then kind and the string with the type of interpolation.

50
00:03:56,130 --> 00:04:03,000
And here, first of all, we want to use linear and we want to store this function that will be generated

51
00:04:03,570 --> 00:04:05,610
in the variable or in the function.

52
00:04:05,940 --> 00:04:11,730
We give it a name called spline linear zero.

53
00:04:13,140 --> 00:04:16,110
And now we have our spleen function.

54
00:04:17,190 --> 00:04:18,510
We can, of course, plot this.

55
00:04:18,510 --> 00:04:28,380
So I will take this one, copy it here and then use a new line p t dot plot and here right data zero

56
00:04:28,380 --> 00:04:39,930
zero for the X values and then for the Y values, I will use spline linear zero acting on data zero

57
00:04:39,930 --> 00:04:40,380
zero.

58
00:04:42,300 --> 00:04:49,320
And so you see the lines here, they are really explained supplying function and the function connects

59
00:04:49,500 --> 00:04:50,520
all of the dots.

60
00:04:51,960 --> 00:04:54,690
So maybe now it's a good idea to zoom in.

61
00:04:55,140 --> 00:04:58,770
So I have to zoom here and.

62
00:05:02,020 --> 00:05:10,060
To zoom in, we will just redefine the X range into why rates, so I would write X plot Dot X line going

63
00:05:10,060 --> 00:05:11,560
from two to four.

64
00:05:12,340 --> 00:05:14,560
And then we have to adapt also the Y limits.

65
00:05:15,400 --> 00:05:21,430
And I've found that it looks quite good when we use minus five to 15.

66
00:05:22,420 --> 00:05:33,310
So then this will be our plot and you see that we have now points that are our data points and they

67
00:05:33,310 --> 00:05:35,590
are connected just by straight lines.

68
00:05:36,340 --> 00:05:41,080
And of course, they are just connected by straight lines because we say that we want to create a plot

69
00:05:42,010 --> 00:05:48,040
where we have pairs of X and Y values and they can just be connected by dots.

70
00:05:48,670 --> 00:05:54,010
So just to make sure that these are really straight lines, we should increase our resolution for this

71
00:05:54,010 --> 00:05:54,550
plot here.

72
00:05:55,330 --> 00:05:59,290
So I write X list, which will be a list for the plot here.

73
00:05:59,680 --> 00:06:07,960
So just for the plot, not for the fit and for this arrow right and p dot line space from two to four.

74
00:06:08,240 --> 00:06:12,880
And now I will not just use a very few points, so here I have five points.

75
00:06:12,880 --> 00:06:18,580
Instead, I will use 201 points and you see the plot doesn't change at all.

76
00:06:19,030 --> 00:06:30,580
So, for example, if it is your setup, then oh sorry my, that I have to change this, of course x

77
00:06:30,580 --> 00:06:31,030
list.

78
00:06:31,150 --> 00:06:32,530
And you're also x list.

79
00:06:34,270 --> 00:06:36,700
Then you can see we have no many, many points.

80
00:06:37,870 --> 00:06:42,400
So let's go back to plots and you see it's still the straight line.

81
00:06:42,820 --> 00:06:49,840
So all the points that are just correct by this line, linear zero are these piece wise linear functions.

82
00:06:50,650 --> 00:06:53,500
And this is, of course, OK.

83
00:06:53,500 --> 00:06:59,170
In a sense, if you have a lot of data points and you don't really care about the derivatives because

84
00:06:59,590 --> 00:07:01,720
on this plot range here looks quite good.

85
00:07:02,230 --> 00:07:07,750
But when you zoom in, you see the derivative is discontinuous and this is, of course, very on physical.

86
00:07:07,750 --> 00:07:13,120
If you relate this data to some real world problem, then this can be very, very, very bad.

87
00:07:14,080 --> 00:07:22,180
And to solve this problem, we can use a cubic spine and we can do this in the following way.

88
00:07:23,140 --> 00:07:29,320
Let me copy the plot here, and then let me copy also the command for creating this plane.

89
00:07:30,760 --> 00:07:34,240
And then we could call this here blind cubic.

90
00:07:34,960 --> 00:07:40,090
And here we just have to change the optional argument to cubic.

91
00:07:41,920 --> 00:07:43,000
And then here are right.

92
00:07:43,960 --> 00:07:46,930
Also quick, and I think that should be it already.

93
00:07:48,130 --> 00:07:50,410
And you see, now we have cubic spines.

94
00:07:50,410 --> 00:07:58,360
So a third order polynomial connecting these dots and you see the derivative is now continuous and it

95
00:07:58,360 --> 00:07:59,890
works very, very well.

