Hi !(adsbygoogle = window.adsbygoogle || []).push({});

first, excuse my english, I'm just a poor french student... and we are so bad in languages here... anyway..

I'm trying to make a little program which could calculate the motion (and some other little things) of n bodies linked with gravitationnal interaction.

(my final aim will be to simulate planets orbits arount binary stellar systems)..

In fact I have already wrote the code, but I don't understand some things... that I hope you'll be able to explain to me ;)

I use the 4th order runge-kutta method to solve the equations of the motion, with a fixed step for the moment (I'll write a method with an adaptable step later).

I have tested my code with the three bodies system : Earth moon and sun. using the JPL orbital parameters for my starting conditions.

I suppose that at time t=0, the orbits are elliptic so I can calculate positions and velocities with the semi-major axis 'a', the excentricity 'e' and the inclinaision angle 'i'.

At time t=0 I put the planets at their apogee with the formula Rmax = a*(1+e).

so for example the cartesian coordonnates for earth at t=0 are :

x_t = a*(1+e)

y_t=0

z_t=0

for the moon, the inclinaison i is 5.16 deg, so :

x_m = x_t + a_m*(1+e_m)*cos(i)

y_m = 0

z_m = a_m*(1+e_m)*sin(i)

(a_m and e_m are respectively semi major axis and excentricity of the moon).

for the velocities, they're purely according to Oy with the module :

v = 2*pi*a*sqrt(1-e²)/(T*(1+e))

(with T the period)

of course, I have added the earth velocity for the moon..

but my result, seems to be incorrect, since I find a minimal distance earth-sun of only 149.5 millions of km, whereas it should be around 147...

You can see my results and the graphics here : http://nicolas.aunai.free.fr/cours/magistere/3c/tl2a2s/tl2a.htm [Broken]

(please do not pay attention to the x and y labels, I made some mistakes with my plotting program)

thanks if you can help me to solve this mystery :)

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# N-body simulation test with sun, earth and moon

**Physics Forums | Science Articles, Homework Help, Discussion**