David Peter 2 лет назад
Родитель
Сommit
3641bca398
4 измененных файлов с 82 добавлено и 0 удалено
  1. 1 0
      book/build.sh
  2. 1 0
      book/src/SUMMARY.md
  3. 42 0
      book/src/example-xkcd_2812.md
  4. 38 0
      examples/xkcd_2812.nbt

+ 1 - 0
book/build.sh

@@ -36,6 +36,7 @@ generate_example pipe_flow_rate "Flow rate in a pipe" true
 generate_example recipe "Recipe" true
 generate_example acidity "Acidity" true
 generate_example xkcd_2585 "XKCD 2585" false
+generate_example xkcd_2812 "XKCD 2812" true
 
 generate_example numbat_syntax "Syntax overview" false
 

+ 1 - 0
book/src/SUMMARY.md

@@ -15,6 +15,7 @@
     - [Recipe](./example-recipe.md)
     - [Acidity](./example-acidity.md)
     - [XKCD 2585](./example-xkcd_2585.md)
+    - [XKCD 2812](./example-xkcd_2812.md)
 
 # Numbat language reference
 

+ 42 - 0
book/src/example-xkcd_2812.md

@@ -0,0 +1,42 @@
+<!-- This file is autogenerated! Do not modify it -->
+
+# XKCD 2812
+
+``` numbat
+# Solar panel placement
+#
+# Solar energy tip: To maximize sun exposure, always
+# orient your panels downward and install them on the
+# surface of the sun.
+#
+# https://xkcd.com/2812/
+#
+# [1] https://en.wikipedia.org/wiki/Solar_luminosity
+# [2] https://en.wikipedia.org/wiki/Sun
+
+unit $: Money
+
+let net_metering_rate = $ 0.20 / kWh
+let panel_area = 1 m²
+let panel_efficiency = 20 %
+
+fn savings(i: Irradiance) -> Money / Time =
+    net_metering_rate × i × panel_area × panel_efficiency -> $/year
+
+## Option A: On the roof, south facing
+
+let savings_a = savings(4 kWh/m²/day)
+
+print(savings_a // round)
+
+## Option B: On the sun, downward facing
+
+dimension Luminosity = Power
+
+let sun_luminosity: Luminosity = 3.828e26 W  # [1]
+let sun_area: Area = 6.09e12 km^2            # [2]
+
+let savings_b = savings(sun_luminosity / sun_area)
+
+print(savings_b // round)
+```

+ 38 - 0
examples/xkcd_2812.nbt

@@ -0,0 +1,38 @@
+# Solar panel placement
+#
+# Solar energy tip: To maximize sun exposure, always
+# orient your panels downward and install them on the
+# surface of the sun.
+#
+# https://xkcd.com/2812/
+#
+# [1] https://en.wikipedia.org/wiki/Solar_luminosity
+# [2] https://en.wikipedia.org/wiki/Sun
+
+unit $: Money
+
+let net_metering_rate = $ 0.20 / kWh
+let panel_area = 1 m²
+let panel_efficiency = 20 %
+
+fn savings(i: Irradiance) -> Money / Time =
+    net_metering_rate × i × panel_area × panel_efficiency -> $/year
+
+## Option A: On the roof, south facing
+
+let savings_a = savings(4 kWh/m²/day)
+
+print(savings_a // round)
+assert_eq(savings_a, 58 $/year, 1 $/year)
+
+## Option B: On the sun, downward facing
+
+dimension Luminosity = Power
+
+let sun_luminosity: Luminosity = 3.828e26 W  # [1]
+let sun_area: Area = 6.09e12 km^2            # [2]
+
+let savings_b = savings(sun_luminosity / sun_area)
+
+print(savings_b // round)
+assert_eq(savings_b, 22 million $/year, 1 million $/year)