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

I wanted to design a 2-dimensional gravity simulator as part of a larger research project. I wrote it in Python using numpy to store positions, velocities, and accelerations, and matplotlib to display the trajectories; code is available upon request.

In order to solve the problem I've used Euler's method, which I know is numerically unstable over long timescales. In particular, I've been observing that over time many bodies are propelled away, in straight lines, from their original positions. By imposing an artificial minimum limit of 0.3 meters on effective gravitational radius (the masses and gravitational constant I'm using for testing purposes are very different from what I'll actually use) I'm able to reduce this mostly, although this reduces the accuracy of predictions at small radii.

I've read up on Runge-Kutta integration and other, more exotic methods of calculating orbits, but I have no idea of how to implement them in an orbital simulator. Would anyone here be able to help? Thanks in advance to everyone.

**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!

# Help designing an n-body gravity simulator in Python

Loading...

Similar Threads - Help designing body | Date |
---|---|

C/++/# Help with MATLAB code? | Feb 9, 2018 |

What's wrong with my bisection method code? | Dec 10, 2017 |

Help: Convert Matlab to Python code | Dec 8, 2017 |

Need help designing an algorithm for similarities between words | Feb 25, 2014 |

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