I am trying to replicate a formula I found on this website, it relates to calculating the radius of the earth at a given latitude.
https://rechneronline.de/earth-radius/ or https://planetcalc.com/7721/
I then use the calculator on the website to determine whether I have replicated the formula correctly.
I have written the following code, but I can't replicate the answer given on the website (except when the latitude is equal to zero). Since the equation is quite complicated, I've even split each part into a seperate variable. However, my results are still not correct.
import math
def radius (B):
a = 6378.137 #Radius at sea level at equator
b = 6356.752 #Radius at poles
c = (a**2*math.cos(B))**2
d = (b**2*math.sin(B))**2
e = (a*math.cos(B))**2
f = (b*math.sin(B))**2
R = math.sqrt((c+d)/(e+f))
return R
For example, using a latitude of 2 (the variable B), the website calculates the radius of the earth as 6378.111km. My answer is 6360.481km.
Any help will be appreciated. Thank you in advance
python math library takes radians as input for trignometric functions,
so make sure you convert the value of B into radians
it can be done by B=math.radians(B)
final code:
import math
def radius (B):
B=math.radians(B) #converting into radians
a = 6378.137 #Radius at sea level at equator
b = 6356.752 #Radius at poles
c = (a**2*math.cos(B))**2
d = (b**2*math.sin(B))**2
e = (a*math.cos(B))**2
f = (b*math.sin(B))**2
R = math.sqrt((c+d)/(e+f))
return R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With