1
00:00:00,180 --> 00:00:05,610
So in the following, we want to, of course, solve more examples of differential equations and not

2
00:00:05,610 --> 00:00:11,880
just the specific ordinary differential equation that characterizes a radioactive decay.

3
00:00:12,870 --> 00:00:18,750
So what we're going to do is we are going to define a new function of herself, which basically mimics

4
00:00:19,020 --> 00:00:20,580
these two cells here.

5
00:00:21,450 --> 00:00:26,610
And in order to do this, let me just copy the code from these two cells.

6
00:00:27,690 --> 00:00:29,040
And also this one.

7
00:00:30,570 --> 00:00:34,860
And now, of course, we will change these cells and define a function.

8
00:00:36,180 --> 00:00:39,740
So to define the function, we write death.

9
00:00:40,350 --> 00:00:41,640
And then we give it a name.

10
00:00:41,640 --> 00:00:42,480
And I recall it.

11
00:00:42,780 --> 00:00:49,500
Euler Ozdemir, you can give it any name, basically, that is not given for other functions already.

12
00:00:50,190 --> 00:00:55,770
And now we have to specify here the arguments and here will be the code.

13
00:00:57,510 --> 00:01:01,830
And the code will, of course, be pretty similar to what we have written down here.

14
00:01:02,790 --> 00:01:12,660
So let me first write down what we need as arguments we need definitely f where f will be the function

15
00:01:13,200 --> 00:01:14,490
of the differential equation.

16
00:01:14,940 --> 00:01:20,270
So when I scroll up here, it will be this one here.

17
00:01:20,280 --> 00:01:27,690
So basically the first derivative of Y with respect to T, then we will need a starting time.

18
00:01:28,860 --> 00:01:34,080
This is not really necessary because most of the time will be we will be starting at zero but could

19
00:01:34,080 --> 00:01:38,850
be helpful to to find a starting time, then we will need a starting value.

20
00:01:39,240 --> 00:01:41,940
So this will be essentially this one here.

21
00:01:42,720 --> 00:01:47,670
So I will write y zero for the starting value of Y.

22
00:01:48,570 --> 00:01:51,480
Then we need the number of iterations

23
00:01:54,540 --> 00:02:00,930
which is and max, and then we need to step six.

24
00:02:02,740 --> 00:02:03,730
Which is H.

25
00:02:06,310 --> 00:02:10,570
And now I, of course, have to add all of these arguments to the function.

26
00:02:10,930 --> 00:02:17,000
So I write f comma, t zero comma, y zero comma and max comma.

27
00:02:17,940 --> 00:02:21,520
Page Sorry, it's too.

28
00:02:21,520 --> 00:02:22,000
It's like this.

29
00:02:24,850 --> 00:02:25,240
All right.

30
00:02:25,240 --> 00:02:28,260
So now we have our arguments and we have here.

31
00:02:28,360 --> 00:02:31,030
This commons define what these arguments mean.

32
00:02:31,030 --> 00:02:36,130
So this is a recommendation from me that you do this for the functions that you define yourself so that

33
00:02:36,130 --> 00:02:40,690
later on you understand what these arguments actually describe.

34
00:02:42,070 --> 00:02:44,140
So now we need to get going.

35
00:02:44,860 --> 00:02:48,730
So what we definitely are going to need is this one here.

36
00:02:49,120 --> 00:02:55,750
So the preparation of the arrays and then we will also need the loop, of course.

37
00:02:56,860 --> 00:03:03,830
But now we must change this maybe a bit because maybe it's not really correct anymore.

38
00:03:03,850 --> 00:03:08,650
For example, we provide here the function F, so we do not need this command here anymore.

39
00:03:08,830 --> 00:03:10,240
We already have our F.

40
00:03:11,290 --> 00:03:12,580
And so here we are.

41
00:03:12,650 --> 00:03:23,770
Right Y is equal to y plus f with the arguments t comma y and we multiply by h then what we also need

42
00:03:24,040 --> 00:03:25,120
since we do not.

43
00:03:26,350 --> 00:03:35,320
Yeah, since basically we have this time t zero now is we need to have time, an internal time running

44
00:03:35,320 --> 00:03:35,980
in the system.

45
00:03:36,550 --> 00:03:41,260
So of course, we could just add here a t0, but I think it's a bit more.

46
00:03:42,640 --> 00:03:45,070
It's it gives you a bit of a better overview.

47
00:03:45,070 --> 00:03:49,350
If you define here a variable called T, it's not really necessary.

48
00:03:49,360 --> 00:03:52,720
You could also solve this differently, but I will define your variable T.

49
00:03:53,380 --> 00:03:58,980
And so in each time step, we will increase T by H.

50
00:04:00,820 --> 00:04:04,780
Of course, here just starting value, we will now use T and not zero.

51
00:04:05,590 --> 00:04:09,090
And we will adhere to T values.

52
00:04:09,100 --> 00:04:15,880
So I write just values append T and I think now we are almost finished.

53
00:04:15,880 --> 00:04:18,399
We just need to load this y0 zero here.

54
00:04:18,399 --> 00:04:22,029
So we need to write y is equal to y zero.

55
00:04:22,870 --> 00:04:25,450
And I think this should already be sufficient.

56
00:04:25,450 --> 00:04:28,270
So you see, we haven't really changed much.

57
00:04:28,300 --> 00:04:30,400
Basically, we have just changed the function.

58
00:04:30,820 --> 00:04:36,820
We have changed the starting value and then we have done this t0, which was optional, however.

59
00:04:38,020 --> 00:04:43,810
So you see, it's really not difficult once you solve a specific example to define a function.

60
00:04:44,170 --> 00:04:50,800
And this is also my recommendation that when you are not quite sure how to define the function, just

61
00:04:50,800 --> 00:04:56,890
try to solve an example without a function and then use the solution to define the function later on.

62
00:04:57,490 --> 00:04:59,890
Because you see, it was pretty easy to do this.

63
00:05:01,300 --> 00:05:09,430
So the only thing that's missing here is the output, because all of this code is just internal in this

64
00:05:09,430 --> 00:05:11,320
function, it will give no output yet.

65
00:05:12,160 --> 00:05:15,490
So we need to write to return.

66
00:05:16,720 --> 00:05:23,050
So we could write print, then it would just print what we whatever we want as the output.

67
00:05:23,470 --> 00:05:29,290
But we want to actually use return so that we are then able to assign these values to variables.

68
00:05:30,310 --> 00:05:37,390
So we print an array of T values and Y values.

69
00:05:39,790 --> 00:05:42,370
So I have run this, of course, it gives me no output.

70
00:05:42,970 --> 00:05:47,050
And now we can test this at our example.

71
00:05:47,350 --> 00:05:53,110
This is always the best thing you should do first, when you define a function and you have already

72
00:05:53,110 --> 00:05:58,630
solved an example, try to solve the example now with the function and see if the solution is still

73
00:05:58,630 --> 00:05:59,080
correct.

74
00:06:00,970 --> 00:06:10,780
So what we need is we need to call, of course, this function, so we write oiler potty and then we

75
00:06:10,780 --> 00:06:12,850
must provide all of these arguments.

76
00:06:13,180 --> 00:06:19,000
So we provide a function f, which I will call F40.

77
00:06:19,360 --> 00:06:21,340
So this function we still have to define.

78
00:06:21,910 --> 00:06:28,630
So let me write this down here so that we do it later on, so define function.

79
00:06:29,530 --> 00:06:35,170
And here we call the other method.

80
00:06:37,790 --> 00:06:45,080
And then we need to provide the t0, which I will just use zero, as in our previous example, then

81
00:06:45,080 --> 00:06:53,660
for the Y0 we will use, yeah, we used one previously, but I will write here why zero zero is equal

82
00:06:53,660 --> 00:06:54,080
to one.

83
00:06:54,770 --> 00:07:00,170
We could also do it like this t0 and T zero is equal to one.

84
00:07:00,560 --> 00:07:01,310
Sorry, two zero.

85
00:07:01,820 --> 00:07:02,810
Then we have.

86
00:07:04,040 --> 00:07:08,670
And Max and Max was equal to 20.

87
00:07:08,690 --> 00:07:13,010
I think it was equal to 200.

88
00:07:16,580 --> 00:07:20,230
And age was equal to zero point zero one.

89
00:07:24,110 --> 00:07:28,280
OK, so now the only thing that's left to do is to define the function.

90
00:07:28,880 --> 00:07:35,630
And this is not so easy, maybe at if you have never done it before, because here we have provided

91
00:07:35,630 --> 00:07:37,820
this with the arguments T and why.

92
00:07:38,330 --> 00:07:41,450
So we must define a function that also has these arguments.

93
00:07:41,840 --> 00:07:45,110
So we cannot just right here minus y.

94
00:07:45,540 --> 00:07:52,370
So I write the I'm sorry, the fine f o d e.

95
00:07:53,270 --> 00:07:56,030
And then we provide the same arguments as above.

96
00:07:59,660 --> 00:08:00,920
T come away, of course.

97
00:08:01,850 --> 00:08:08,510
And then the only thing the function does is give the value of the functions, so return and the value

98
00:08:08,510 --> 00:08:10,160
of the function is minus Y.

99
00:08:11,270 --> 00:08:13,160
And I think now it should work.

100
00:08:14,180 --> 00:08:21,710
So I run this and it gives me a new solution, which is a list of X. Well, I sort of T values and the

101
00:08:21,710 --> 00:08:22,850
list of Y values.

102
00:08:24,110 --> 00:08:30,350
So now we can store any solutions in the variables, so I will call this solution.

103
00:08:33,520 --> 00:08:38,110
And now we can plot this so we can just take the plot from here.

104
00:08:41,590 --> 00:08:49,750
And changed the T values to solution the first element, so index zero and then the Y values is the

105
00:08:49,930 --> 00:08:50,770
other element.

106
00:08:52,420 --> 00:08:59,320
And you see, it still gives the correct result, even though now the solution has been determined by

107
00:08:59,320 --> 00:09:05,470
calling our all the method function that we have just programmed in this lecture.

