# About the gravitational potential energy formula and the conservation of energy

I am making a $$n$$-body simulation, and for reasons beyond the purposes of this question, I need to know what is the gravitational potential energy, but when i searched up in google this formula showed up:

$$-G\frac{m_1m_2}{r}.$$

what this formula says is that, the further away the two bodies are, the smaller is the gravitational potential energy, but then from where does the kinetic energy come from when the two bodies are closer together?

I mean, when the two bodies are far away, with no speed, both gravitational potential and kinetic energy are low, and when they start to approach each other (because of gravity) both gravitational potential and kinetic energy are high. Doesn't this violate conservation of energy?

• Gravitational potential energy is negative.. that should compensate for large kinetic energy Commented Jan 29, 2022 at 13:42
• oh... that makes sense... Commented Jan 29, 2022 at 13:43

...what this formula says is that, the further away the two bodies are, the smaller is the gravitational potential energy

No, notice the negative sign in front of the expression. As $$r$$ increases, $$\frac{Gm_1m_2}{r}$$ decreases and consequently $$U_g = -\frac{Gm_1m_2}{r}$$ increases.

When the bodies start to approach each other ($$r$$ decreases), the kinetic energy $$K$$ increases, the expression $$\frac{Gm_1m_2}{r}$$ increases and the gravitational potential energy of the system $$U_g = -\frac{Gm_1m_2}{r}$$ decreases, in accordance with the conservation of energy for an isolated system.

Hope this helps.