2

An N-body simulation typically works directly in terms of the gravitational forces and accelerations. If you can solve the equations exactly, this is fine, but there are many instances where this is impossible for a reasonable definition of impossible. Therefore, we approximate the solution.

Namely, we find the acceleration of each point mass, then increment the position and velocity using Euler's method.

One thing about this is that energy and momentum will not necessarily be preserved. This can lead to bad phenomenon such as mass coming to close and causing each other to shoot away. Generally, if you are viewing a simulation casually, most of the inaccuracies come in when energy or momentum are badly changed.


Can you do an N-body simulation directly in terms of concepts such as energy, momentum, work, impulse, etc...? Namely, what are some methods such that the energy and momentum are guaranteed to be conserved by the simulation?

We could give each point mass a velocity and position. This allows you to determine both the energy and momentum of each particle. You can then, as gravitational potential energy changes, calculate the corresponding change in kinetic energy, from there the change in velocity. I think work may be involved somewhere here as well (and therefore force). The problem is, this does not really tell you anything about direction.

Anyone know how a N-body simulation that conserves energy and momentum could work?

  • 1
    What you are looking for are basically numerical implementations of the Lagrange and Hamilton formalisms. Yes, that is exactly how one would do precise numerical simulations. Did you hear about symplectic integrators https://en.wikipedia.org/wiki/Symplectic_integrator? Having said that, the mentioned problem of bodies coming very close to each other can not be avoided. It is a real physical effect leading to long term unpredictable chaotic systems. – CuriousOne Jan 03 '16 at 03:29
  • @CuriousOne Well, even if it is unpredictable, it would be nice if the energy stayed constant (if you are, say, playing a game, it being off 45 degrees does not matter; it flying into space forever when it shouldn't does.) – Christopher King Jan 03 '16 at 03:39
  • 1
    As a side note... never, ever use the Euler method. That the energy is constant can be assured numerically quite easily. – CuriousOne Jan 03 '16 at 03:39
  • @CuriousOne What are you supposed to use instead? – Christopher King Jan 03 '16 at 03:39
  • Use, at least https://en.wikipedia.org/wiki/Semi-implicit_Euler_method. – CuriousOne Jan 03 '16 at 03:41
  • @PyRulez As CuriousOne noted, Euler method is a bad, bad, bad idea. Either the semi implicit Euler will work, or a fully implicit Euler, or an implicit Runge-Kutta, or a leapfrog, or a Verlet (also called a Newmark) scheme -- I prefer the velocity-Verlet form -- etc.. But a forward Euler is a really bad idea, particularly if energy conservation is the goal. – tpg2114 Jan 03 '16 at 03:53
  • @CuriousOne Looking up the Lagrange and the Hamilton, they look considerably more complicated than how I described my question. Is my question intrinsically this complicated, or is there a simpler way to answer it (both the Lagrange and Hamilton both appear more general than I require at this time, I was looking for a proof of concept anyway, not necessarily a precise numerical simulation)? – Christopher King Jan 03 '16 at 03:53

0 Answers0