So what we will do next is we will program these equations and we will do this in a similar way as we
always do.
But first of all, we need to really use our system here so the Sun, the Earth and the Moon.
By this, I mean, I write and one is equal to sun and two is equal to Earth.
So these are the constants that we have to find previously.
And M3 is equal to the Moon and now we can go ahead and program these.
So we define a function f only as we always do, and it depends on T.
Well, it does not actually depend on T, but this is how we must define the function so that we can
use our solver.
So there could be a term here that depends on T.
And it turns out later on when we consider the spaceship and we will add a fourth equation for the spaceship,
then we will make our our equation time dependent because we will sometimes turn on our engine.
OK, but so far, it's not T dependent.
It's only our dependence and our is a vector or an array of these 18 variables and total here.
So the first thing that I want to do here is not really necessary, but it helps a bit.
So I write our one is, of course, X1, Y1 Z1, but our one is the first three elements of this array.
And then for our two and our three, it's very similar are two is the other three elements and then
are three the next three elements.
So this goes from six to eight and python, we have to write to nine because nine will not be included.
So of course, we could do now the same thing with the velocity, for example, of the one is equal
to our and then the next three elements.
This would be reasonable to do, but we actually don't need it here.
So I just write it as a comment.
You could do it, but it's not really necessary here.
So another thing that I want to introduce is I want to introduce these distances here because you see,
we have here many of these distances.
And these are the three distances between the three objects.
And so I define our one two is equal to ENPI.
Then I calculate the norm, so the distance by using NPY dawdling our norm.
And then I provide the vector, which in this case will be our one minus R2.
And then I do the same thing for the other two distances.
So we have here are two to three.
So this will be two and three and R3 one one minus, I'm sorry, three minus R1.
You could, of course, also do it in the other way, but it doesn't matter because the norm is always
positive.
And now we can calculate or we can program these equations to get these three equations, which are
actually nine, because we have the components.
So I write, the equations for our will be G times and now I write an array.
So you see G is really in every single terms.
I can pull it out here and write G Times and P Dot.
Alright.
Now come the equations and I will write these really in the vector form, so I will just program he
three equations.
So let's get started minus and then to divide divided by our one two to the power of three plus and
three divided by our three one two, the power of three.
And then this whole thing in brackets.
Here is this one times I want.
And the other two terms will be to divide us by our one to two, the top of three times are two.
And the other term, I'm three divided by our three one to call three times our three.
And now I have to program the similar equations for the other two cases.
So this is, of course, a bit tedious, but it has to be done.
So then I don't have to type so much.
I will copy here a bit and just changed indices.
It's the first term and one and then I want to do all three times one.
Then we get this double term with the negative sign.
Of course, we also have to correct the indices.
So this will be anyone divided by one to two the par three plus and three the outer space here and three
divided by our two three to the power of three times are two.
And then we have another term, which will just be the single entry here.
And this will be.
And three divided by our two three to power three times are three.
And we're almost done.
Just the last equation will be very similar here.
The index will be three one and we get another of these single terms.
This one will be added two divided by our two three to three times are two.
And then the double term.
This one will be one divided by our three one power of three plus and two divided by our two three power
of three times.
All three.
OK, now that's done.
So sorry, this was probably a bit annoying and tedious, but it has to be done.
Sometimes you just have to also do the knowing stuff and programmed these equations, but that's all
we have to do here.
So let me run this whole thing and I hope I don't have a typo.
So now we have programmed these equations, and of course, now we can go ahead and call our routine.
Well, one thing I forgot we have to use the return.
Of course, we must return in total 18 equations, and so far we only have nine of those because here
we have three equations which are victoriously equations where these ones all have three entries.
So we are missing another nine equations, and these as previously will just be the velocities.
So I write return and basically we have to return first to velocities.
So these will be our going from nine to 18.
And then we need our equations.
And it turns out that we need a single list or a single array as the return.
So what we need is we need to concatenate these two lists race that we have here.
So like this.
So this basically just means merge these two lists and then these ones here, as I told you, our three
equations of three equations each.
So this is your basically an array three by three.
So we must flatten this array to make it a nine component vector, basically.
So this is something I tested, of course, before.
At first I also did a mistake here, of course, and just wrote like this.
But it's not working.
We need to flatten this and we need to concatenate.
All right.
So before we can really use the solver, we need, of course, the starting conditions, the starting
conditions are as follows.
First, we defined a son.
This will be our one start.
Or at least this will be how I will program it.
I one start is and Peter ParaIt and now the X, Y and Z components.
And I want to see the sun is positioned in the center of a coordinate system, so it will all be zero.
And also, we don't want that the Sun moves in this coordinate system.
So our velocity v on zero or v one start is also an array full of zeros.
So that's not really special so far.
But now comes the Earth.
And here we have our to start is given by.
So maybe let me just copy this and then I will consider here that the Earth is positioned on the x axis.
And of course, the value will be our sun earth.
This is how I have to find the variable in the very beginning of our notebook.
And the velocity is now perpendicular, it will be along the Y direction.
So you see it, the Earth is positioned on the x axis and the velocity is perpendicular to this along
to wider action.
So, all right, way to start is given by an that rate zero and then the Earth comma zero.
OK, so now we have a starting velocity perpendicular to the position vector.
And now we add the moon and for the Moon, we can of course use many choices now.
And one particularly easy choice is the following.
Let me just copy this one more time.
All three start is given by it.
And now we must be careful because the Moon is, of course, pretty close to the Earth.
But we could now, for example, adhere to distance from Earth to Moon.
But I will just put it here if it's offset on the y axis right here, our Earth Moon, and for the starting
velocity, I do it also similar to this one.
So the starting velocity in the coordinate system where the Sun does not move will be similar to the
velocity of the Earth.
But now we have to add on top the velocity of the Moon.
And since we have positioned the moon offset along the Y direction compared to the Earth, the velocity
that we will add now must be perpendicular to this.
So it will be, for example, minus the moon.
OK, so if this is confusing, I think so far it is pretty easy.
But then maybe this is a bit confusing.
But just think about you take now the Earth as the reference point.
So you have to start from these two vectors and then you have to add the distance of our Earth Moon
and you have to add the velocity of the Moon.
And you can do this in several ways.
And this is the way that I have chosen to do it.
And now the last thing will be we right?
R0 is our starting input vector.
So this will be as here and concatenate.
And now we will merge these six vectors.
So we start with our one start are to start our three start and then we do the same thing.
But with the velocity, so be one start.
We to start with three start.
And now we can test if all of this worked and we will just write.
Everybody, at some point of time, it doesn't matter because the equation is independent of time,
so we can just take zero and then for zero and we get an output, that's always great because that means
there is no stupid mistake on no syntax error.
And also, we get here are 18 components as the output.
That's also great.
So a value for each of our differential equations.
OK, so now everything is prepared.
We have programmed our equations of motions.
We have programmed our starting conditions.
Now we can solve these equations and we can discuss them the physics of the three body problem.