1
00:00:00,690 --> 00:00:07,650
So what we will do next is we will program these equations and we will do this in a similar way as we

2
00:00:07,650 --> 00:00:08,280
always do.

3
00:00:09,060 --> 00:00:15,210
But first of all, we need to really use our system here so the Sun, the Earth and the Moon.

4
00:00:15,450 --> 00:00:22,260
By this, I mean, I write and one is equal to sun and two is equal to Earth.

5
00:00:22,680 --> 00:00:25,620
So these are the constants that we have to find previously.

6
00:00:26,040 --> 00:00:31,230
And M3 is equal to the Moon and now we can go ahead and program these.

7
00:00:32,220 --> 00:00:37,560
So we define a function f only as we always do, and it depends on T.

8
00:00:37,860 --> 00:00:42,750
Well, it does not actually depend on T, but this is how we must define the function so that we can

9
00:00:42,750 --> 00:00:43,680
use our solver.

10
00:00:44,070 --> 00:00:46,710
So there could be a term here that depends on T.

11
00:00:47,160 --> 00:00:54,120
And it turns out later on when we consider the spaceship and we will add a fourth equation for the spaceship,

12
00:00:54,120 --> 00:01:01,680
then we will make our our equation time dependent because we will sometimes turn on our engine.

13
00:01:02,850 --> 00:01:04,530
OK, but so far, it's not T dependent.

14
00:01:04,530 --> 00:01:12,390
It's only our dependence and our is a vector or an array of these 18 variables and total here.

15
00:01:13,500 --> 00:01:18,570
So the first thing that I want to do here is not really necessary, but it helps a bit.

16
00:01:19,350 --> 00:01:28,020
So I write our one is, of course, X1, Y1 Z1, but our one is the first three elements of this array.

17
00:01:28,950 --> 00:01:36,150
And then for our two and our three, it's very similar are two is the other three elements and then

18
00:01:36,330 --> 00:01:37,980
are three the next three elements.

19
00:01:39,270 --> 00:01:45,450
So this goes from six to eight and python, we have to write to nine because nine will not be included.

20
00:01:46,820 --> 00:01:51,680
So of course, we could do now the same thing with the velocity, for example, of the one is equal

21
00:01:51,680 --> 00:01:53,930
to our and then the next three elements.

22
00:01:54,620 --> 00:01:57,920
This would be reasonable to do, but we actually don't need it here.

23
00:01:58,130 --> 00:01:59,660
So I just write it as a comment.

24
00:01:59,930 --> 00:02:03,080
You could do it, but it's not really necessary here.

25
00:02:04,400 --> 00:02:09,560
So another thing that I want to introduce is I want to introduce these distances here because you see,

26
00:02:09,560 --> 00:02:11,430
we have here many of these distances.

27
00:02:11,900 --> 00:02:15,260
And these are the three distances between the three objects.

28
00:02:16,130 --> 00:02:20,810
And so I define our one two is equal to ENPI.

29
00:02:21,140 --> 00:02:28,010
Then I calculate the norm, so the distance by using NPY dawdling our norm.

30
00:02:29,660 --> 00:02:34,610
And then I provide the vector, which in this case will be our one minus R2.

31
00:02:35,690 --> 00:02:38,230
And then I do the same thing for the other two distances.

32
00:02:38,240 --> 00:02:40,670
So we have here are two to three.

33
00:02:41,150 --> 00:02:48,350
So this will be two and three and R3 one one minus, I'm sorry, three minus R1.

34
00:02:49,310 --> 00:02:54,230
You could, of course, also do it in the other way, but it doesn't matter because the norm is always

35
00:02:54,230 --> 00:02:54,710
positive.

36
00:02:56,060 --> 00:03:01,820
And now we can calculate or we can program these equations to get these three equations, which are

37
00:03:01,820 --> 00:03:04,430
actually nine, because we have the components.

38
00:03:05,360 --> 00:03:11,450
So I write, the equations for our will be G times and now I write an array.

39
00:03:11,870 --> 00:03:14,440
So you see G is really in every single terms.

40
00:03:14,480 --> 00:03:18,200
I can pull it out here and write G Times and P Dot.

41
00:03:18,850 --> 00:03:19,260
Alright.

42
00:03:21,330 --> 00:03:26,480
Now come the equations and I will write these really in the vector form, so I will just program he

43
00:03:26,560 --> 00:03:27,740
three equations.

44
00:03:28,730 --> 00:03:38,120
So let's get started minus and then to divide divided by our one two to the power of three plus and

45
00:03:38,120 --> 00:03:42,470
three divided by our three one two, the power of three.

46
00:03:43,460 --> 00:03:45,860
And then this whole thing in brackets.

47
00:03:45,860 --> 00:03:48,920
Here is this one times I want.

48
00:03:50,360 --> 00:03:56,840
And the other two terms will be to divide us by our one to two, the top of three times are two.

49
00:03:57,560 --> 00:04:05,690
And the other term, I'm three divided by our three one to call three times our three.

50
00:04:06,920 --> 00:04:11,210
And now I have to program the similar equations for the other two cases.

51
00:04:11,840 --> 00:04:14,990
So this is, of course, a bit tedious, but it has to be done.

52
00:04:15,620 --> 00:04:18,200
So then I don't have to type so much.

53
00:04:18,200 --> 00:04:21,459
I will copy here a bit and just changed indices.

54
00:04:21,470 --> 00:04:27,890
It's the first term and one and then I want to do all three times one.

55
00:04:28,580 --> 00:04:32,300
Then we get this double term with the negative sign.

56
00:04:32,870 --> 00:04:35,890
Of course, we also have to correct the indices.

57
00:04:35,900 --> 00:04:46,610
So this will be anyone divided by one to two the par three plus and three the outer space here and three

58
00:04:46,610 --> 00:04:51,410
divided by our two three to the power of three times are two.

59
00:04:52,100 --> 00:04:55,280
And then we have another term, which will just be the single entry here.

60
00:04:55,640 --> 00:04:56,660
And this will be.

61
00:04:56,900 --> 00:05:01,880
And three divided by our two three to power three times are three.

62
00:05:03,050 --> 00:05:04,250
And we're almost done.

63
00:05:04,250 --> 00:05:08,960
Just the last equation will be very similar here.

64
00:05:08,960 --> 00:05:15,140
The index will be three one and we get another of these single terms.

65
00:05:15,980 --> 00:05:22,010
This one will be added two divided by our two three to three times are two.

66
00:05:22,610 --> 00:05:23,690
And then the double term.

67
00:05:25,250 --> 00:05:34,060
This one will be one divided by our three one power of three plus and two divided by our two three power

68
00:05:34,070 --> 00:05:35,690
of three times.

69
00:05:36,600 --> 00:05:37,100
All three.

70
00:05:38,240 --> 00:05:39,590
OK, now that's done.

71
00:05:39,680 --> 00:05:44,070
So sorry, this was probably a bit annoying and tedious, but it has to be done.

72
00:05:44,090 --> 00:05:50,090
Sometimes you just have to also do the knowing stuff and programmed these equations, but that's all

73
00:05:50,240 --> 00:05:51,170
we have to do here.

74
00:05:52,190 --> 00:05:56,480
So let me run this whole thing and I hope I don't have a typo.

75
00:05:57,860 --> 00:06:03,530
So now we have programmed these equations, and of course, now we can go ahead and call our routine.

76
00:06:04,520 --> 00:06:08,090
Well, one thing I forgot we have to use the return.

77
00:06:09,380 --> 00:06:18,380
Of course, we must return in total 18 equations, and so far we only have nine of those because here

78
00:06:18,380 --> 00:06:23,990
we have three equations which are victoriously equations where these ones all have three entries.

79
00:06:24,800 --> 00:06:30,830
So we are missing another nine equations, and these as previously will just be the velocities.

80
00:06:31,850 --> 00:06:37,490
So I write return and basically we have to return first to velocities.

81
00:06:37,910 --> 00:06:40,970
So these will be our going from nine to 18.

82
00:06:41,750 --> 00:06:44,750
And then we need our equations.

83
00:06:47,660 --> 00:06:54,410
And it turns out that we need a single list or a single array as the return.

84
00:06:55,220 --> 00:07:01,040
So what we need is we need to concatenate these two lists race that we have here.

85
00:07:01,700 --> 00:07:03,810
So like this.

86
00:07:04,190 --> 00:07:11,300
So this basically just means merge these two lists and then these ones here, as I told you, our three

87
00:07:11,300 --> 00:07:14,120
equations of three equations each.

88
00:07:14,120 --> 00:07:16,820
So this is your basically an array three by three.

89
00:07:17,180 --> 00:07:22,040
So we must flatten this array to make it a nine component vector, basically.

90
00:07:23,150 --> 00:07:25,580
So this is something I tested, of course, before.

91
00:07:26,750 --> 00:07:30,380
At first I also did a mistake here, of course, and just wrote like this.

92
00:07:30,380 --> 00:07:31,640
But it's not working.

93
00:07:31,640 --> 00:07:34,460
We need to flatten this and we need to concatenate.

94
00:07:36,230 --> 00:07:36,830
All right.

95
00:07:38,090 --> 00:07:45,650
So before we can really use the solver, we need, of course, the starting conditions, the starting

96
00:07:45,650 --> 00:07:47,030
conditions are as follows.

97
00:07:47,540 --> 00:07:49,100
First, we defined a son.

98
00:07:49,370 --> 00:07:51,230
This will be our one start.

99
00:07:51,770 --> 00:07:54,440
Or at least this will be how I will program it.

100
00:07:54,980 --> 00:08:00,830
I one start is and Peter ParaIt and now the X, Y and Z components.

101
00:08:01,460 --> 00:08:07,160
And I want to see the sun is positioned in the center of a coordinate system, so it will all be zero.

102
00:08:08,480 --> 00:08:12,530
And also, we don't want that the Sun moves in this coordinate system.

103
00:08:12,530 --> 00:08:19,790
So our velocity v on zero or v one start is also an array full of zeros.

104
00:08:21,050 --> 00:08:23,210
So that's not really special so far.

105
00:08:23,210 --> 00:08:24,320
But now comes the Earth.

106
00:08:25,280 --> 00:08:29,090
And here we have our to start is given by.

107
00:08:29,600 --> 00:08:36,919
So maybe let me just copy this and then I will consider here that the Earth is positioned on the x axis.

108
00:08:37,220 --> 00:08:41,419
And of course, the value will be our sun earth.

109
00:08:41,630 --> 00:08:45,320
This is how I have to find the variable in the very beginning of our notebook.

110
00:08:46,840 --> 00:08:52,030
And the velocity is now perpendicular, it will be along the Y direction.

111
00:08:52,900 --> 00:08:58,810
So you see it, the Earth is positioned on the x axis and the velocity is perpendicular to this along

112
00:08:58,810 --> 00:08:59,680
to wider action.

113
00:09:00,730 --> 00:09:10,690
So, all right, way to start is given by an that rate zero and then the Earth comma zero.

114
00:09:13,520 --> 00:09:19,100
OK, so now we have a starting velocity perpendicular to the position vector.

115
00:09:19,430 --> 00:09:25,520
And now we add the moon and for the Moon, we can of course use many choices now.

116
00:09:26,000 --> 00:09:29,420
And one particularly easy choice is the following.

117
00:09:31,100 --> 00:09:33,140
Let me just copy this one more time.

118
00:09:34,430 --> 00:09:36,310
All three start is given by it.

119
00:09:36,770 --> 00:09:41,060
And now we must be careful because the Moon is, of course, pretty close to the Earth.

120
00:09:41,660 --> 00:09:46,640
But we could now, for example, adhere to distance from Earth to Moon.

121
00:09:47,060 --> 00:09:57,380
But I will just put it here if it's offset on the y axis right here, our Earth Moon, and for the starting

122
00:09:57,380 --> 00:10:00,890
velocity, I do it also similar to this one.

123
00:10:00,900 --> 00:10:08,900
So the starting velocity in the coordinate system where the Sun does not move will be similar to the

124
00:10:08,900 --> 00:10:10,140
velocity of the Earth.

125
00:10:10,220 --> 00:10:13,280
But now we have to add on top the velocity of the Moon.

126
00:10:14,300 --> 00:10:25,100
And since we have positioned the moon offset along the Y direction compared to the Earth, the velocity

127
00:10:25,370 --> 00:10:28,070
that we will add now must be perpendicular to this.

128
00:10:28,970 --> 00:10:33,500
So it will be, for example, minus the moon.

129
00:10:35,180 --> 00:10:40,010
OK, so if this is confusing, I think so far it is pretty easy.

130
00:10:40,010 --> 00:10:41,660
But then maybe this is a bit confusing.

131
00:10:41,660 --> 00:10:45,680
But just think about you take now the Earth as the reference point.

132
00:10:45,680 --> 00:10:52,220
So you have to start from these two vectors and then you have to add the distance of our Earth Moon

133
00:10:52,220 --> 00:10:55,070
and you have to add the velocity of the Moon.

134
00:10:56,030 --> 00:10:57,680
And you can do this in several ways.

135
00:10:57,680 --> 00:10:59,960
And this is the way that I have chosen to do it.

136
00:11:01,100 --> 00:11:03,260
And now the last thing will be we right?

137
00:11:03,260 --> 00:11:06,860
R0 is our starting input vector.

138
00:11:07,280 --> 00:11:10,810
So this will be as here and concatenate.

139
00:11:13,040 --> 00:11:17,000
And now we will merge these six vectors.

140
00:11:17,840 --> 00:11:27,110
So we start with our one start are to start our three start and then we do the same thing.

141
00:11:27,110 --> 00:11:30,320
But with the velocity, so be one start.

142
00:11:30,740 --> 00:11:33,020
We to start with three start.

143
00:11:35,060 --> 00:11:40,280
And now we can test if all of this worked and we will just write.

144
00:11:42,930 --> 00:11:47,670
Everybody, at some point of time, it doesn't matter because the equation is independent of time,

145
00:11:47,670 --> 00:11:55,380
so we can just take zero and then for zero and we get an output, that's always great because that means

146
00:11:55,380 --> 00:11:58,380
there is no stupid mistake on no syntax error.

147
00:11:59,160 --> 00:12:03,300
And also, we get here are 18 components as the output.

148
00:12:03,300 --> 00:12:04,170
That's also great.

149
00:12:04,440 --> 00:12:08,760
So a value for each of our differential equations.

150
00:12:10,090 --> 00:12:12,140
OK, so now everything is prepared.

151
00:12:12,160 --> 00:12:14,500
We have programmed our equations of motions.

152
00:12:14,890 --> 00:12:16,970
We have programmed our starting conditions.

153
00:12:16,990 --> 00:12:23,200
Now we can solve these equations and we can discuss them the physics of the three body problem.

