浏览代码

Use mean earth radius, update XKCD/What-if examples

David Peter 1 年之前
父节点
当前提交
c8fc155c2c
共有 6 个文件被更改,包括 34 次插入13 次删除
  1. 1 0
      book/build.py
  2. 1 0
      book/src/SUMMARY.md
  3. 19 0
      book/src/example-xkcd_681.md
  4. 3 3
      examples/what_if_11.nbt
  5. 6 9
      examples/xkcd_681.nbt
  6. 4 1
      numbat/modules/extra/astronomy.nbt

+ 1 - 0
book/build.py

@@ -46,6 +46,7 @@ generate_example("pipe_flow_rate", "Flow rate in a pipe")
 generate_example("population_growth", "Population growth")
 generate_example("recipe", "Recipe")
 generate_example("voyager", "Voyager")
+generate_example("xkcd_681", "XKCD 681", strip_asserts=False)
 generate_example("xkcd_687", "XKCD 687")
 generate_example("xkcd_2585", "XKCD 2585")
 generate_example("xkcd_2812", "XKCD 2812")

+ 1 - 0
book/src/SUMMARY.md

@@ -17,6 +17,7 @@
     - [Population growth](./example-population_growth.md)
     - [Recipe](./example-recipe.md)
     - [Voyager](./example-voyager.md)
+    - [XKCD 681](./example-xkcd_681.md)
     - [XKCD 687](./example-xkcd_687.md)
     - [XKCD 2585](./example-xkcd_2585.md)
     - [XKCD 2812](./example-xkcd_2812.md)

+ 19 - 0
book/src/example-xkcd_681.md

@@ -0,0 +1,19 @@
+<!-- This file is autogenerated! Do not modify it -->
+
+# XKCD 681
+<a href="https://numbat.dev/?q=%23+Gravity+wells%0A%23%0A%23+https%3A%2F%2Fxkcd.com%2F681%2F%0A%0Ause+extra%3A%3Aastronomy%0A%0Afn+well_depth%28mass%3A+Mass%2C+radius%3A+Length%29+-%3E+Length+%3D%0A++++G+%C3%97+mass+%2F+%28g0+%C3%97+radius%29+-%3E+km%0A%0Aassert_eq%28well_depth%28earth_mass%2C+earth_radius%29%2C+6379+km%2C+1+km%29%0Aassert_eq%28well_depth%28mars_mass%2C++mars_radius%29%2C++1286+km%2C+3+km%29%0Aassert_eq%28well_depth%28lunar_mass%2C+lunar_radius%29%2C++288+km%2C+1+km%29%0A"><i class="fa fa-play"></i> Run this example</a>
+
+``` numbat
+# Gravity wells
+#
+# https://xkcd.com/681/
+
+use extra::astronomy
+
+fn well_depth(mass: Mass, radius: Length) -> Length =
+    G × mass / (g0 × radius) -> km
+
+assert_eq(well_depth(earth_mass, earth_radius), 6379 km, 1 km)
+assert_eq(well_depth(mars_mass,  mars_radius),  1286 km, 3 km)
+assert_eq(well_depth(lunar_mass, lunar_radius),  288 km, 1 km)
+```

+ 3 - 3
examples/what_if_11.nbt

@@ -5,14 +5,14 @@
 #
 # https://what-if.xkcd.com/11/
 
+use extra::astronomy
+
 @aliases(birds)
 unit bird
 unit mouth
 unit poop
 
-let earth_radius = 6371 km
-
-let frequency = (300 billion birds / 4 pi earth_radius^2) × (1 poop / bird / hour) × (16 hours / day) × (1 mouth / poop) × (15 cm^2 / mouth)
+let frequency = (300 billion birds / 4 π earth_radius^2) × (1 poop / bird / hour) × (16 hours / day) × (1 mouth / poop) × (15 cm^2 / mouth)
 let period = 1 / frequency
 
 print("It happens once every ~{period -> year}s")

+ 6 - 9
examples/xkcd_681.nbt

@@ -2,14 +2,11 @@
 #
 # https://xkcd.com/681/
 
-fn depth(mass: Mass, radius: Length) -> Length =
-    G × mass / (g0 × radius) -> km
-
-let earth_mass = 5.972e24 kg
-let earth_radius = 6371 km
+use extra::astronomy
 
-let moon_mass = 7.342e22 kg
-let moon_radius = 1737 km
+fn well_depth(mass: Mass, radius: Length) -> Length =
+    G × mass / (g0 × radius) -> km
 
-assert_eq(depth(earth_mass, earth_radius), 6379 km, 1 km)
-assert_eq(depth(moon_mass, moon_radius), 288 km, 1 km)
+assert_eq(well_depth(earth_mass, earth_radius), 6379 km, 1 km)
+assert_eq(well_depth(mars_mass,  mars_radius),  1286 km, 3 km)
+assert_eq(well_depth(lunar_mass, lunar_radius),  288 km, 1 km)

+ 4 - 1
numbat/modules/extra/astronomy.nbt

@@ -13,7 +13,10 @@ unit lunar_mass: Mass = 7.342e22 kg
 unit lunar_radius: Length = 1737.4 km
 
 unit earth_mass: Mass = 5.9722e24 kg
-unit earth_radius: Length = 6378.1 km
+unit earth_radius: Length = 6371.0088 km
+
+unit mars_mass: Mass = 6.4171e23 kg
+unit mars_radius: Length = 3389.5 km
 
 unit jupiter_mass: Mass = 1.89813e27 kg
 unit jupiter_radius: Length = 71_492 km