# Can you do an n-body simulation in terms of energy and momentum?

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?

• 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 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 3 '16 at 3: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.) – PyRulez Jan 3 '16 at 3:39
• As a side note... never, ever use the Euler method. That the energy is constant can be assured numerically quite easily. – CuriousOne Jan 3 '16 at 3:39
• @CuriousOne What are you supposed to use instead? – PyRulez Jan 3 '16 at 3:39
• Use, at least en.wikipedia.org/wiki/Semi-implicit_Euler_method. – CuriousOne Jan 3 '16 at 3:41