I am really, really stuck! I am trying to write java code to model the solar system, or at least currently just earth, the sun and mercury. I've made a big mistake somewhere, the planets are very unstable and either move in a line or spiral inwards! I just wanted to check that I'm doing things in the right order, I have so many loops.(adsbygoogle = window.adsbygoogle || []).push({});

I've set the sun to start at the origin, and the earth's position is

$$x = 1.496 \times 10^{11}m$$ and Mercury is at $$x = 5.971 \times 10^{10}m$$

I want everything to be done in the centre of mass frame, so I then calculate the position of the centre of mass and subtract it from the initial positions, e.g. so the sun is at x - centreOfMass.

The velocity of each body is given by $$v = \frac{2\pi r}{T}$$ This is probably where I go wrong. I know the orbital period of mercury and earth around the sun, so I can calculate their velocities around the centre of mass. But the sun will also move, even if only a tiny, tiny bit, and I don't have its orbital period around the centre of mass! So how can I work out its velocity?

Assuming I have the sun's velocity around the centre of mass, I then work out the velocity of the centre of mass. Because I want to stay in the centre of mass frame, I then subtract this velocity from the velocities of the planets.

My code is then written so that the position is recalculated, given a time step, then the centre of mass position is recalculated and subtracted from the new position. A new velocity for each planet is calculated, then the centre of mass velocity is recalculated and again subtracted from each velocity.

Is this the correct procedure? Do I need to recalculate the centre of mass position/velocity after each time step, or is that the problem?

**Physics Forums - The Fusion of Science and Community**

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

# Order of calculations solar system model

Loading...

Similar Threads - Order calculations solar | Date |
---|---|

What should i study in order to build my first Android app? | Jan 8, 2018 |

Symbolic calculations in MATLAB | Nov 21, 2017 |

Ordering of CSV table | May 14, 2017 |

Python Testing code to solve 2nd order wave equation | Oct 8, 2016 |

C/++/# Runge-Kutta 4th order program copying array element | Aug 9, 2016 |

**Physics Forums - The Fusion of Science and Community**