nbody: calculate acceleration and velocity based on gravity formula