1
00:00:00,060 --> 00:00:05,970
And the previous lecture, we have seen that there exist many methods that are much more accurate compared

2
00:00:06,180 --> 00:00:10,650
to the conventional Euler method for solving differential equations.

3
00:00:11,280 --> 00:00:14,550
And one of those methods was the quotes methods.

4
00:00:15,030 --> 00:00:18,630
And there is actually a whole family of running Qatar methods.

5
00:00:19,050 --> 00:00:25,260
And one of them was the longer cutoff for five methods, which we are going to implement throughout

6
00:00:25,260 --> 00:00:26,760
the following two lectures.

7
00:00:27,840 --> 00:00:34,590
So the reason why you're able to quit our method is used so often throughout physics is because it is

8
00:00:34,590 --> 00:00:36,280
not that time consuming.

9
00:00:36,600 --> 00:00:41,460
It's not that difficult to implement, but still, it gives very accurate results.

10
00:00:42,150 --> 00:00:48,270
And to explain to you why when we put our method is so much better than the Euler method is pretty difficult.

11
00:00:48,810 --> 00:00:54,810
So we can have a look at this link here, and you can see here's a derivation, and I really don't want

12
00:00:54,810 --> 00:01:00,750
to go through this whole derivation with you together because you see it is quite demanding.

13
00:01:00,930 --> 00:01:06,420
And this is not even going to put up four or five methods, but only the a quarter four methods.

14
00:01:07,470 --> 00:01:13,290
So the simple or simplified and a simplified way, you could say that the reason why the woman quit

15
00:01:13,290 --> 00:01:21,300
on method is much better than the Euler method is that it combines several terms so that arrows cancel

16
00:01:21,300 --> 00:01:21,840
each other.

17
00:01:21,850 --> 00:01:27,960
That's a bit similar to the way that we have to find the more accurate versions for the derivatives

18
00:01:27,960 --> 00:01:29,880
in the earlier section of this course.

19
00:01:31,020 --> 00:01:39,690
So what we are going to implement here is the home equity method called Arc four, which will be the

20
00:01:39,690 --> 00:01:43,170
first step, and then we will take it to even further.

21
00:01:43,440 --> 00:01:49,410
And then we will implement the R.K. four five method, which is the same that is implemented previously

22
00:01:49,800 --> 00:01:53,640
in the problem solver that we have compared to here.

23
00:01:55,510 --> 00:02:02,800
So to get started, let me go back and let me copy the codes for the implementation of our oil methods,

24
00:02:03,190 --> 00:02:06,250
because here we will define a function called R.K. four.

25
00:02:06,610 --> 00:02:12,670
And of course, in general, it will be pretty similar to the old method, and we will just change the

26
00:02:12,670 --> 00:02:16,450
way the the way we'll use updated.

27
00:02:17,050 --> 00:02:18,010
So let me scroll up.

28
00:02:18,040 --> 00:02:21,280
Let me search for our Arla methods.

29
00:02:21,670 --> 00:02:26,560
So not the Euler second order method, but the First Order methods.

30
00:02:29,140 --> 00:02:33,610
I think here it should be in a second or the pendulum.

31
00:02:34,870 --> 00:02:36,910
We have solved quite a few examples.

32
00:02:39,550 --> 00:02:40,630
Yeah, here it is.

33
00:02:41,560 --> 00:02:42,250
The Euler.

34
00:02:43,300 --> 00:02:49,930
So you go to the cell, it's should be cell number seven and we copy this and go back to the bottom

35
00:02:49,930 --> 00:02:52,630
of our notebook and paste it here.

36
00:02:53,740 --> 00:02:56,890
And now what we are going to change is, of course, the name.

37
00:02:57,550 --> 00:03:00,670
We're going to name it, R.K. four and four.

38
00:03:00,670 --> 00:03:01,450
The arguments.

39
00:03:01,690 --> 00:03:08,160
We still need the same things and also the beginning will be pretty much the same at first.

40
00:03:08,170 --> 00:03:14,350
We use our starting value for Y and yes, added to Y and the same for T zero.

41
00:03:14,680 --> 00:03:20,680
Then we start with these lists where we will store our values T and Y, and then there will be the loop

42
00:03:20,830 --> 00:03:22,450
over the next steps.

43
00:03:22,900 --> 00:03:27,190
And now this will be what we are going to calculate next.

44
00:03:27,940 --> 00:03:34,360
And to understand what we are going to do, let me open up this Wikipedia link in a new browser.

45
00:03:34,660 --> 00:03:42,040
And there I will explain to you how we update the value for white in the form of code for methods.

46
00:03:42,430 --> 00:03:49,030
So the trick of avoiding a quota method is that we do not simply go from the old y well you to the new

47
00:03:49,030 --> 00:03:55,840
Y value, but we have intermediate positions over which we will average in a certain way.

48
00:03:56,650 --> 00:03:59,620
So let me write down how I mean this.

49
00:03:59,620 --> 00:04:03,670
So first of all, we are going to calculate some intermediate positions.

50
00:04:03,670 --> 00:04:12,730
So these will be K1 and K2, OK, three and four in this case, because it is a fourth order when we

51
00:04:12,730 --> 00:04:19,870
put our methods and then we will calculate the value K, which will be some weighted average.

52
00:04:19,870 --> 00:04:30,250
In this case, it will be one over six times K one plus one over three times K two plus one over three

53
00:04:30,280 --> 00:04:35,890
times K three and then one over six times K4.

54
00:04:37,630 --> 00:04:44,110
And this K value will be the value that we will add to our value y.

55
00:04:45,130 --> 00:04:52,360
So basically, instead of this derivative four, we go straight from the old value to the new value.

56
00:04:52,780 --> 00:04:59,980
We go from the old value to the new one by adding the value K and K consists out of a weighted average

57
00:04:59,980 --> 00:05:04,180
of four different points that we are going to construct next.

58
00:05:05,080 --> 00:05:07,150
So where can you find these values?

59
00:05:07,900 --> 00:05:16,180
You can find them in any mathematical equation collection for numerical mathematics, for example,

60
00:05:16,180 --> 00:05:17,570
or also on Wikipedia.

61
00:05:17,600 --> 00:05:19,350
So here's the classic fourth.

62
00:05:19,360 --> 00:05:22,210
All the methods the of the hungry put our methods.

63
00:05:22,840 --> 00:05:29,320
And this is a bit of a cryptic way of writing it down in such a tableau, and the values for the key

64
00:05:29,320 --> 00:05:31,090
values are always here at the bottom.

65
00:05:31,270 --> 00:05:35,980
So this would mean one of a six times K1, one over three times K2 and so on.

66
00:05:36,550 --> 00:05:42,180
And Cassie, there exist many different methods and there exist many different values for these key

67
00:05:42,190 --> 00:05:44,680
values and also for the other values.

68
00:05:45,790 --> 00:05:48,700
So these are the ones that we are going to use next.

69
00:05:48,940 --> 00:05:50,650
I would say, let's first use this one.

70
00:05:50,980 --> 00:05:55,690
These are the arguments or the coefficients for the H value.

71
00:05:55,700 --> 00:06:00,850
So for the step with or yeah, step size, we called it here.

72
00:06:01,570 --> 00:06:05,320
So this will always be calculated in the following way.

73
00:06:05,830 --> 00:06:16,930
So step size times F and then T come our way, but we will now modify these arguments here.

74
00:06:17,290 --> 00:06:21,970
So we will change the time argument and we will also change to y arguments.

75
00:06:21,970 --> 00:06:27,370
So basically, we are taking positions that are in between the old and the new Y value.

76
00:06:28,120 --> 00:06:32,200
So let me copy this and then we are going to modify it in all four cases.

77
00:06:33,070 --> 00:06:39,880
So in the first case, or I would say, let's first consider the time argument which is described by

78
00:06:39,880 --> 00:06:40,870
these coefficients.

79
00:06:41,380 --> 00:06:45,220
And this means for the first time argument, we will add zero.

80
00:06:45,460 --> 00:06:50,490
Here we will add one half of h or sorry, one half times h.

81
00:06:50,500 --> 00:06:53,920
You're also one half times h and then one times h.

82
00:06:54,690 --> 00:07:06,770
So we right plus major page of a two plus page of a two plus page times one.

83
00:07:06,790 --> 00:07:12,000
So just h and then we also have to modify the Y arguments.

84
00:07:12,360 --> 00:07:19,770
And here we have to add a linear combination of the K one K to three K four values.

85
00:07:20,160 --> 00:07:27,330
And of course, for K one, we cannot add any other K value, but four K two, we can add some multiple

86
00:07:27,330 --> 00:07:29,310
of the K one four K three.

87
00:07:29,310 --> 00:07:35,910
We can add a weighted some of the K1 and K2, and for K four, we can add a weighted sum of K one,

88
00:07:35,910 --> 00:07:36,660
two and three.

89
00:07:37,410 --> 00:07:40,470
And this is described by these coefficients here.

90
00:07:40,890 --> 00:07:49,200
This means for the K2 value, we add one half of K one for K three, we add one half of K two and four

91
00:07:49,200 --> 00:07:49,740
K four.

92
00:07:49,740 --> 00:07:52,080
We add one times K three.

93
00:07:52,800 --> 00:07:55,260
And you see in general, this can be much more complicated.

94
00:07:55,260 --> 00:08:02,160
For example, here we will add for K for a weighted sum of K one, two and three weighted by these coefficients.

95
00:08:03,090 --> 00:08:10,050
And these coefficients are always calculated in the way so that certain arrows cancel out so that the

96
00:08:10,320 --> 00:08:12,450
solution will then be more accurate.

97
00:08:13,320 --> 00:08:14,130
So let's go ahead.

98
00:08:14,130 --> 00:08:16,020
Let's remember one half on half and one.

99
00:08:16,680 --> 00:08:24,180
So we have here plus one half times K1, so we can also write K one over two here.

100
00:08:24,180 --> 00:08:28,770
We had also one half point and a K two column K two of a two.

101
00:08:29,160 --> 00:08:32,100
And here we just had one in the K three column.

102
00:08:32,400 --> 00:08:36,030
So like this and this is actually it.

103
00:08:36,210 --> 00:08:46,230
So we have constructed four new points that are pretty similar to that from the syntax is pretty similar

104
00:08:46,230 --> 00:08:49,140
to the change for the Y value that we have before the Euler method.

105
00:08:49,560 --> 00:08:54,490
So it's h times some value of our function, which was the derivative.

106
00:08:55,410 --> 00:09:01,290
And the only thing that we have to change here is the argument, the time argument and the Y arguments,

107
00:09:01,980 --> 00:09:07,830
and we have constructed four different K points then have calculated the weighted average over these

108
00:09:07,830 --> 00:09:08,250
points.

109
00:09:08,670 --> 00:09:15,510
And then we have updated our value y with the new value of K for the value of each year.

110
00:09:15,510 --> 00:09:20,580
For the time update, we didn't change anything because we still go in steps of h.

111
00:09:21,630 --> 00:09:28,020
So of course, we have seen that in our example previously, there is some time adaptation.

112
00:09:28,260 --> 00:09:36,330
So when I scroll up to here, for example, we have seen that we do not take equidistant time steps.

113
00:09:36,720 --> 00:09:44,310
So here there's also another trick implemented that's intelligently choses to step with parameter so

114
00:09:44,310 --> 00:09:48,240
that the error is still not too large, but so that we need less points.

115
00:09:48,690 --> 00:09:52,650
But this is a whole nother thing, and this is even more difficult to implement.

116
00:09:52,650 --> 00:09:58,260
So I think we should not bother with it because in the end, we are often often interested in these

117
00:09:58,260 --> 00:09:59,790
equidistant lists of points.

118
00:10:00,300 --> 00:10:04,370
And here we are, even asked the solver to create such lists.

119
00:10:04,370 --> 00:10:08,100
So I think it's OK if we just take an equidistant method here.

120
00:10:09,360 --> 00:10:16,320
So we have now implemented the art form methods, and I would say we do not need to test it here right

121
00:10:16,320 --> 00:10:16,530
away.

122
00:10:16,530 --> 00:10:18,600
Let's just run it and see that there is no error.

123
00:10:18,780 --> 00:10:19,170
OK?

124
00:10:19,260 --> 00:10:20,040
This worked fine.

125
00:10:20,550 --> 00:10:26,250
And before we test it, I would say, let's go right to the next step and implement the arc four five

126
00:10:26,250 --> 00:10:30,630
methods, and then we will compare both of these methods with our own Euler methods.

