Saturday, May 30, 2026

Numworks (Python): Determining Earth’s Acceleration of Gravity

Numworks (Python): Determining Earth’s Acceleration of Gravity



Introduction



Note: We will only be using SI units on this blog entry and program.



In general, the Earth’s acceleration constant, labeled with a lower case g, is conventionally defined to be 9.80665 m/s². Did you know that the gravitation acceleration on this planet actually varies (albeit slightly) depending on factors? For example, the gravity’s acceleration in Los Angeles, California, is about 9.796 m/s² (see Wikipedia article in the Source section).



On today’s blog, we will estimate the gravity of Earth based with two parameters: the latitude (North/South position on Earth’s grid) and elevation (in meters). This will give us a more accurate estimated on gravity, which in turn will give other physics calculations more accuracy.



For this program, I’m using a mix of formulas to estimate Earth’s gravitational acceleration:



Let Φ = latitude in radian measure:

Φ = (degrees + minutes ÷ 60 + seconds ÷ 3600) * π ÷ 180



For this calculation, consider the absolute value of the latitude. Gravity acceleration is the a given the northern latitude north and the corresponding southern latitude. (Example: gravity is about 9.79325 m/s² at 30° north and 30° south).



Gravity at the surface (0 m) is calculated as:

gs = (a * ga * (cos Φ)^2 + b * gb * (sin Φ)^2) ÷ √((a * cos(Φ))^2 + (b * sin(Φ))^2)

[Bilsin]



Where:

Φ = latitude in radians (see formula above)

a = 6378137 m (Earth’s radius at the equator)

ga = 9.70803253359 m/s² (gravity at the equator)

b = 6356752.3142 m (Earth’s radius at the poles)

gb = 9.8321849378 m/s² (gravity at the poles)

[Bilsin, Table 2]



Gravity at the selected elevation is estimated at:

ge = (100 * gs – 0.3086 * h ÷ 1000) ÷ 100

[Glover]



Where:

h = height in meters (m)



Note: The table on the Desk Ref list gravity as cm/s² and the original formula called for the height in kilometers (km).



To convert feet to meters, multiply by 0.3048.



Numworks Program: earthg.py


https://my.numworks.com/python/ews31415/earthg


Code:


from math import *

# Numworks, EWS, January 2026


# constants

# equator: radius, gravity

a=6378137

ga=9.7803253359

# poles: radius, gravity

b=6356721.3142

gb=9.8321849378


print("Latitude:","\nNorth or South")

d=eval(input("Decimal? "))

m=eval(input("Minutes? "))

s=eval(input("Seconds? "))

phi=radians(d+m/60+s/3600)


print("Height (m)?")

h=eval(input("? "))


gs=a*ga*cos(phi)**2+b*gb*sin(phi)**2

gs/=sqrt((a*cos(phi))**2+(b*sin(phi))**2)


print("Gravity on the surface:")

print(str(gs)," m/s**2")


print("At altitude: ",str(h)," m")

ge=(100*gs-0.3086*h/1000)/100

print(str(ge)," m/s**2")




Examples


Latitude

Elevation

g_surface

g_elevation

30°0’0”

0

9.793247191840559

9.793247191840559

40°0’0”

304.8

9.801696762579571

9.800756149779572

45°0’0”

762

9.806197665936962

9.803846133936961

12°5’13”

1219.2

9.782589588493437

9.778827137293437

34°26’44”

500

9.796866770553882

9.795323770553882


g_surface: gravity at surface level (0 m)

g_elevation: gravity at the selected elevation



Sources


Bislin, Walter. “Earth Gravity Calculator” September 1, 2018. https://walter.bislins.ch/bloge/index.asp?page=Earth+Gravity+Calculator Retrieved January 15, 2026.


Glover, Thomas J. and Richard A. Young Desk Ref Sequoia Publishing, Inc. Anchorage, AK. 4th Edition, 2022. Soft Cover ISBN 978-1-885071-60-6. pg. 587


“Gravity of Earth” Wikipedia. Last edited January 31, 2026. https://en.wikipedia.org/wiki/Gravity_of_Earth Retrieved February 1, 2026.



Eddie


All original content copyright, © 2011-2026. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Numworks (Python): Determining Earth’s Acceleration of Gravity

Numworks (Python): Determining Earth’s Acceleration of Gravity Introduction Note: We will only be using SI units on this blog en...