# Should energy be conserved in an N-body simulation where particles don't lose energy in collisions?

In an N-body simulation where forces between particles are attractive and particles do not lose energy on colliding with walls or each other, should energy be conserved? How could it be, with total kinetic energy increasing to unlimited values and total potential energy capped by the number of particles and their closest allowed proximity?

(I'm not sure if this is the correct forum to ask this, as it doesn't question the implementation mechanism itself. Feel free to tell me to repost it elsewhere.)

Think of the collisions between particles or walls as being modeled by a potential energy term of the form: $$U(r) = \begin{cases} 0, & \text{if r > r_c}, \\ +\infty, & \text{if r \le r_c}, \end{cases}$$ where $r_c$ is the radius of a particle (or wall). You can see that the energy goes to infinity, compensating the attractive forces. Another way of looking at the problem is to consider a sequence $U_n$ of smooth approximations to $U$ and to see that conservation of energy holds for every one of those approximations.