How do you calculate gravitational potential energy?

From Google:

PE_{\text G} = mg \Delta h
PE_G = potential energy due to gravity
g = acceleration due to gravity
m = mass
\Delta h = distance above a surface (such as the ground)

Say I have a rock of mass m kilograms in my hand.

The weight of the rock pushing down is m g or about 9.81 m Newtons.
If it is not accelerating the force up from my hand is then m g Newtons.
Now
If I lift that rock up a distance z, the work I do with my hand is F z = m g z
If there are no losses to friction or radiation or heat or anything energy is conserved so that work I put in, m g z, is an increase of potential energy of the rock of amount m g z Newtons
or
increase in PE = m g z
Note, important ---- all I calculated with that m g z was increase in potential energy from moving up distance z
There was no starting z = 0, the original height of my hand defined
Therefore to say my potential energy is U = m g z
I must say where z = 0 and U = 0. Often one chooses the level of the earth for z =U = 0, but you can pick any other height for U = 0
This is true of any other potential, always it is relative to some defined zero point.

ah well, who am I to criticize Google ?

Now if you are not just working on the surface of earth but in the much larger universe you must use the more general form of gravitational effect

F = G m M /r^2
m is that mass you are moving
M is the planet or star or whatever
r is the distance between the center of gravity of your rock and that star or whatever.
G is Newton's universal gravitational constant

[ Note if near earth surface r is about constant earth radius and m is earth mass F = [G M/r^2] m where G M/r^2 = g pretty much constant 9.81 m/s^2]
now change in PE = [(GMm)/r^2] dr = (GMm) integral dr/r^2
= GMm/ [1/R1 - 1/R2]
that is
G M m [ R2 - R1] /R1 R2
if R1 is close to R2 like near surface of earth that is
(GmM/R^2 )*( change in height ) or the same old m g z
which is the same old m g * change in height

To calculate the gravitational potential energy, you can use the following formula:

Gravitational Potential Energy (PE) = mass (m) × acceleration due to gravity (g) × height (h)

1. Determine the mass (m) of the object: This is the amount of matter contained in the object. It is usually measured in kilograms (kg).

2. Find the acceleration due to gravity (g): On Earth, the standard value for acceleration due to gravity is approximately 9.8 meters per second squared (m/s^2). However, this value can vary slightly depending on the location and altitude.

3. Measure the height (h) of the object: This is the distance between the reference point (often the ground or a reference level) and the object's center of mass. It is usually measured in meters (m).

4. Substitute the values into the formula: Multiply the mass (m) by the acceleration due to gravity (g), and then multiply the result by the height (h).

5. Calculate the gravitational potential energy (PE): Multiply the mass (m) by the acceleration due to gravity (g), and then multiply the result by the height (h). The unit of gravitational potential energy is usually joules (J).

Example: Let's assume you have a mass of 5 kg, a height of 10 meters, and an acceleration due to gravity of 9.8 m/s^2.
PE = 5 kg × 9.8 m/s^2 × 10 m
PE = 490 J

Therefore, the gravitational potential energy is 490 joules.