I'm writing a program that models the gravitational interactions of a number of objects. After the number of bodies exceeds two, the motion can no longer be solved analytically, so the behavior of the chaotic system must be approximated using small timesteps.
At the moment, my code loops through each object hundreds of times a second, sums up the forces from the other objects using Newton's law of universal gravitation, and determines the resulting change in position and velocity over the timestep using $\Delta v = at$ and displacement $= v_it + \frac{1}{2}at^2$. (My actual code breaks this down into $x$ and $y$ components.)
However, the basic formulas I am using assume acceleration is constant throughout the timestep, when in reality it can can be quite a bit different at the end of a larger timestep. I implemented variable timesteps to make it a bit smoother, where the objects are iterated on more frequently when they are experiencing large acceleration and less frequently when the forces acting on them are small. However, there is still quite a bit of energy drift in order to make it run at a reasonable pace.
Is there a better way to more accurately predict change in velocity and position over each timestep?