1
00:00:00,060 --> 00:00:06,180
Welcome back to our calls, where we are currently discussing how to solve ordinary differential equations,

2
00:00:06,689 --> 00:00:13,650
and so far we have programmed ourselves a function that solves these equations, according to the Euler

3
00:00:13,650 --> 00:00:14,080
methods.

4
00:00:14,460 --> 00:00:19,470
And we have solved the dysfunction first order and also second order differential equations.

5
00:00:19,980 --> 00:00:26,040
We've seen that this can be really nice to get the results that we weren't able to get when we would

6
00:00:26,040 --> 00:00:28,260
just rely on analytical methods.

7
00:00:29,520 --> 00:00:35,130
Now, of course, this Euler method is just the most simple approach and the most simple way of solving

8
00:00:35,130 --> 00:00:35,970
these equations.

9
00:00:36,060 --> 00:00:43,050
We've also seen that when the step size is too small, it can get slightly wrong results.

10
00:00:43,410 --> 00:00:48,630
And also, you could imagine that when our problem problem becomes more difficult and if we want to

11
00:00:48,630 --> 00:00:54,840
simulate it over a very long time and we want to still get the accurate solution, then we would really

12
00:00:55,050 --> 00:00:58,890
have to decrease the step size and then the solution would take forever.

13
00:01:00,060 --> 00:01:02,970
So it's much better to use a solvent.

14
00:01:02,970 --> 00:01:09,030
It is provided by Python that is optimized and it uses more improved and advanced methods.

15
00:01:10,020 --> 00:01:15,690
And to use them, we have to load a module that we have actually loaded in the very beginning of this

16
00:01:15,690 --> 00:01:20,220
notebook, and this module is called PSI Pi.

17
00:01:20,700 --> 00:01:24,930
And here we are only going to use the integrated part of place.

18
00:01:24,930 --> 00:01:28,050
So I wrote from Typekit import integrate.

19
00:01:28,060 --> 00:01:29,790
But you could also write import side.

20
00:01:30,000 --> 00:01:32,340
So fine, so pi.

21
00:01:32,350 --> 00:01:39,090
And then you would just have to write every time, say Pi Dot, integrate and then the solver that we

22
00:01:39,090 --> 00:01:39,960
are going to use.

23
00:01:40,590 --> 00:01:46,590
And since I wrote it down like this, we just have to write, integrate dots and then the command that

24
00:01:46,590 --> 00:01:47,400
we want to use.

25
00:01:48,360 --> 00:01:55,860
So let me go down to the notebook just where we left after the last lecture, and this was when we have

26
00:01:55,860 --> 00:01:59,400
simulated this driven and attempt pendulum.

27
00:02:00,450 --> 00:02:09,060
So as I said now we will discuss improved methods and there are actually two useful solvers in this

28
00:02:09,060 --> 00:02:09,960
Sci-Fi module.

29
00:02:10,710 --> 00:02:13,050
There is an old one that is called.

30
00:02:14,970 --> 00:02:21,900
Yeah, all the story O and the E ins and I was just confused because it says old.

31
00:02:22,380 --> 00:02:29,070
But it stands, of course, for ordinary linear differential equation and that interface and integration

32
00:02:29,730 --> 00:02:36,330
methods this you can still use, but it's kind of old and not really profitable anymore.

33
00:02:36,600 --> 00:02:45,930
Much better is now the new command, which is sci fi not integrate dot solve underscore IVP for now.

34
00:02:47,070 --> 00:02:50,340
Yeah, and and this is what we're going to use.

35
00:02:50,340 --> 00:02:55,360
And for this, you can even select different methods and different solvers.

36
00:02:55,380 --> 00:02:58,860
So it's a nice tool that we will explore in the following lectures.

37
00:03:00,000 --> 00:03:07,800
And the first thing is we are going to compare our results, for example, to which time and fight decay

38
00:03:08,220 --> 00:03:09,480
with our old results.

39
00:03:09,930 --> 00:03:11,580
So here we have the old methods.

40
00:03:12,120 --> 00:03:13,950
And let me run this.

41
00:03:15,450 --> 00:03:16,570
We've seen it worked.

42
00:03:16,590 --> 00:03:21,930
And now we must, of course, verify that our new solver can also restore these results.

43
00:03:23,100 --> 00:03:25,590
So how does it work?

44
00:03:26,400 --> 00:03:34,710
Well, first, let's create a new cell and then the the command will be integrate dots.

45
00:03:35,640 --> 00:03:38,850
So underscore heap, as I wrote above.

46
00:03:38,850 --> 00:03:42,000
And then we just have to take care of the arguments.

47
00:03:42,750 --> 00:03:46,230
So if you wouldn't know what the arguments are, how would you find out?

48
00:03:46,860 --> 00:03:49,200
Well, you have to Google in the internet.

49
00:03:49,530 --> 00:03:55,140
So here is a link where you can go to or you just Google Python.

50
00:03:55,380 --> 00:04:00,420
Solve IVP and then you will get probably to this side or to another side.

51
00:04:00,870 --> 00:04:05,640
And there they will really list all the arguments that you need to provide and we'll explain what they

52
00:04:05,640 --> 00:04:07,230
mean and what you have to provide.

53
00:04:08,550 --> 00:04:13,260
So here we first have to provide our function like in our own solution.

54
00:04:13,260 --> 00:04:15,990
So we need everybody.

55
00:04:17,760 --> 00:04:24,660
Then we need the time span and this is here given by such a list of two values starting volume and end

56
00:04:24,660 --> 00:04:25,170
value.

57
00:04:26,140 --> 00:04:30,300
Then we have to provide the starting value for the value of why.

58
00:04:31,380 --> 00:04:34,950
And here we use one and we have to give it also as a list.

59
00:04:35,100 --> 00:04:40,620
The reason for this is that once we try to solve higher order differential equations, then we would

60
00:04:40,620 --> 00:04:46,980
have to provide here two or more values, as we have seen for the free fall, where we have to provide

61
00:04:47,400 --> 00:04:49,740
the starting position and the starting velocity.

62
00:04:51,180 --> 00:04:56,220
So here, from a logical point of view, it wouldn't really be necessary to use this as a list, but

63
00:04:56,670 --> 00:04:57,620
that's the syntax.

64
00:04:57,630 --> 00:04:59,100
So we have to provide a list.

65
00:05:00,940 --> 00:05:07,120
And now it would work already, but fortunately, we can provide the method and we will discuss too

66
00:05:07,120 --> 00:05:13,420
soon a bit more detail, but a pretty standard method that's always a good first guess is the only a

67
00:05:13,420 --> 00:05:17,080
quarter four or five methods or short RJ 45.

68
00:05:18,580 --> 00:05:28,180
So we must now stored the solution and I call this solution or AK 45, and I run this.

69
00:05:30,040 --> 00:05:31,120
And now we can have a look.

70
00:05:31,720 --> 00:05:33,100
What is the actual solution?

71
00:05:33,820 --> 00:05:43,630
So solution underscore our K 45 Bob T would be the syntax for the T list, just an area of some dots.

72
00:05:43,630 --> 00:05:46,720
And then we can also access the why list.

73
00:05:51,180 --> 00:05:57,600
Which is, of course, also an array of dots of coordinates, and together they will be dots.

74
00:05:58,230 --> 00:06:05,610
So let's look at those and let's just copy the plot from here and replace these two commands with our

75
00:06:05,760 --> 00:06:11,130
new solutions so we can leave everything as it is and just change this one.

76
00:06:11,460 --> 00:06:12,860
So here we will.

77
00:06:12,890 --> 00:06:18,630
Right solution RJ 45 T and then Dot.

78
00:06:18,990 --> 00:06:19,430
Why?

79
00:06:20,760 --> 00:06:23,700
And if I run this, you will see this is the solution.

80
00:06:24,900 --> 00:06:30,180
And first of all, you see, OK, the most important thing is that the end value is correct.

81
00:06:30,630 --> 00:06:31,590
You see, it is correct.

82
00:06:31,590 --> 00:06:33,090
It's right on the red curve.

83
00:06:33,090 --> 00:06:35,490
And it's also the same as an hour in a miracle approach.

84
00:06:36,230 --> 00:06:40,190
But what you can also see is that this could R45.

85
00:06:40,590 --> 00:06:48,000
The methods used only very, very few points could even see this year only one two three four five 11

86
00:06:48,000 --> 00:06:48,570
points.

87
00:06:49,590 --> 00:06:56,700
And therefore, it's very, very fast compared to our 100 points or even 300 that we used here.

88
00:06:57,660 --> 00:07:03,870
So it's enormous, I think, how comical to solve this differential equation with only such a few points.

89
00:07:04,620 --> 00:07:11,580
And also what's remarkable is that we never told the wrong a quota algorithm how many points to choose.

90
00:07:12,450 --> 00:07:18,360
And this is really a nice thing because we have seen previously that once we choose the step with too

91
00:07:18,360 --> 00:07:22,800
large into all the methods that our solution will become in an inaccurate.

92
00:07:23,850 --> 00:07:28,740
And so there's always this danger that you don't get the correct solution, but you don't really know

93
00:07:28,740 --> 00:07:30,030
if that's correct or not.

94
00:07:30,510 --> 00:07:37,110
However, for the human quota 45, you will not have these problems as the algorithm determines these

95
00:07:37,110 --> 00:07:38,310
values automatically.

96
00:07:40,110 --> 00:07:47,730
So the next thing that we are going to do is we, of course, wants to reproduce this graph here.

97
00:07:48,180 --> 00:07:51,510
So we want to get two more points on the curve.

98
00:07:52,500 --> 00:07:59,910
So for this, what we can do is we can provide an additional optional argument here.

99
00:08:01,620 --> 00:08:02,490
So let me copy this.

100
00:08:03,810 --> 00:08:05,910
And let me also copy the plot.

101
00:08:09,800 --> 00:08:16,810
And to do this, we just have to provide an additional argument here, which is called to evaluate,

102
00:08:17,050 --> 00:08:19,840
to evaluate, and then we have to provide here some.

103
00:08:20,840 --> 00:08:26,870
And for example, we could provide a very similar array to be we right and peddled within space.

104
00:08:27,610 --> 00:08:36,770
And then we go from, I don't really remember from zero to let's see zero to 30 and the step number

105
00:08:36,770 --> 00:08:37,980
would be three hundreds.

106
00:08:38,000 --> 00:08:38,419
Yes.

107
00:08:39,350 --> 00:08:49,820
So this would be age times and max, cola and max that I run this around this.

108
00:08:50,060 --> 00:08:57,350
And then it tells R.K. 45 explicitly to use these points.

109
00:08:57,800 --> 00:09:04,310
And so at least these points as the T points for which it will evaluate the solution.

110
00:09:05,300 --> 00:09:10,880
So I think in general, it's really much better to have only a few points here because then the calculations

111
00:09:10,880 --> 00:09:14,960
will be faster and in the end, you will only be interested in the end value.

112
00:09:15,290 --> 00:09:21,020
But since for some reason you want to have a dense list of points here, and then you can use this by

113
00:09:21,020 --> 00:09:27,080
using such an optional argument, and then you will get such a nice solution, which is exactly what

114
00:09:27,080 --> 00:09:29,600
we got before with our Euler methods.

