Calculating Inital Velocity required to stablize an orbit of a moon

I am currently attempting to create a little solar system simulation and I was curious if there's a decent way to calculate what a moon or planet's initial velocity would need to be to remain in orbit around a main body. I know $$\sqrt{\frac{GM}{d}}$$ will give the velocity required to keep an object of mass m in orbit at distance d around a mass of M, however it seems to be more complex when adding in multiple gravity sources (other planets and such). Is there a way to determine what velocity an object of mass m needs to keep in orbit around $$M_1$$ which in turn is in orbit around $$M_2$$. In other words - a way to find how fast a moon has to be going to remain in orbit without crashing into the planet or being overtaken by the sun.

• If the moon is within the planet's sphere of influence, it's usually a fine approximation to say the Sun has no significant influence on it. But if you want to do a full three-body solution, you'll have to do that numerically because there is no analytic solution. For centuries, scientists have grappled with the three-body problem, so that might be difficult. But with a simulation, you could always plug in the laws of motion and numerically integrate each time step. Might be computationally intensive and you'd have to guess the initial conditions, but it would work – Jim Mar 1 at 13:58
• Are you aware that the three-body problem is, in general, not analytically solved? – ACuriousMind Mar 1 at 17:01