For a school project i created a simple 2D gravity sim in Matlab using the simplest possible method. There are 2 nested loops so that the total force and acceleration of every object can be calculated. I found that conservation of momentum in x and y works perfectly. I also use a damping so if two object are very close, their acceleration doesn't explode.
Then i place two objects of equal mass on coördinates (-100,0) and (100,0) with initial speeds 0. If i start the sim, the two objects will move towards eachother, pass though eachother and move away again. However, they move away much farther than where they originally started. Would that mean that kynetic energy + pot energy is violated, or is this normal?
In the real world this obviously never happens because objects can't pass through eachother.
It is not very important to solve the problem, the project is from a few months ago. I just wonder what went wrong.
Here is my code. The circle.m must be in the same folder as the gravity.m Some names of variables are in Dutch, but i translated the comments.