|
|
@@ -13,6 +13,16 @@ Return the input value.
|
|
|
fn id<A>(x: A) -> A
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=id%288%20kg%29')""></button></div><code class="language-nbt hljs numbat">>>> id(8 kg)
|
|
|
+
|
|
|
+ = 8 kg [Mass]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `abs` (Absolute value)
|
|
|
Return the absolute value \\( |x| \\) of the input. This works for quantities, too: `abs(-5 m) = 5 m`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.abs).
|
|
|
@@ -21,6 +31,16 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn abs<T: Dim>(x: T) -> T
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=abs%28%2D22%2E2%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> abs(-22.2 m)
|
|
|
+
|
|
|
+ = 22.2 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `sqrt` (Square root)
|
|
|
Return the square root \\( \sqrt{x} \\) of the input: `sqrt(121 m^2) = 11 m`.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Square_root).
|
|
|
@@ -29,6 +49,16 @@ More information [here](https://en.wikipedia.org/wiki/Square_root).
|
|
|
fn sqrt<D: Dim>(x: D^2) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=sqrt%284%20are%29%20%2D%3E%20m')""></button></div><code class="language-nbt hljs numbat">>>> sqrt(4 are) -> m
|
|
|
+
|
|
|
+ = 20 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `cbrt` (Cube root)
|
|
|
Return the cube root \\( \sqrt[3]{x} \\) of the input: `cbrt(8 m^3) = 2 m`.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Cube_root).
|
|
|
@@ -37,6 +67,16 @@ More information [here](https://en.wikipedia.org/wiki/Cube_root).
|
|
|
fn cbrt<D: Dim>(x: D^3) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=cbrt%288%20L%29%20%2D%3E%20cm')""></button></div><code class="language-nbt hljs numbat">>>> cbrt(8 L) -> cm
|
|
|
+
|
|
|
+ = 20.0 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `sqr` (Square function)
|
|
|
Return the square of the input, \\( x^2 \\): `sqr(5 m) = 25 m^2`.
|
|
|
|
|
|
@@ -44,6 +84,16 @@ Return the square of the input, \\( x^2 \\): `sqr(5 m) = 25 m^2`.
|
|
|
fn sqr<D: Dim>(x: D) -> D^2
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=sqr%287%29')""></button></div><code class="language-nbt hljs numbat">>>> sqr(7)
|
|
|
+
|
|
|
+ = 49
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `round` (Rounding)
|
|
|
Round to the nearest integer. If the value is half-way between two integers, round away from \\( 0 \\). See also: `round_in`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.round).
|
|
|
@@ -52,13 +102,45 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn round(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=round%285%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> round(5.5)
|
|
|
+
|
|
|
+ = 6
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=round%28%2D5%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> round(-5.5)
|
|
|
+
|
|
|
+ = -6
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `round_in` (Rounding)
|
|
|
-Round to the nearest multiple of `base`. For example: `round_in(m, 5.3 m) == 5 m`.
|
|
|
+Round to the nearest multiple of `base`.
|
|
|
|
|
|
```nbt
|
|
|
fn round_in<D: Dim>(base: D, value: D) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Round in meters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=round%5Fin%28m%2C%205%2E3%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> round_in(m, 5.3 m)
|
|
|
+
|
|
|
+ = 5 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+Round in centimeters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=round%5Fin%28cm%2C%205%2E3%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> round_in(cm, 5.3 m)
|
|
|
+
|
|
|
+ = 530 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `floor` (Floor function)
|
|
|
Returns the largest integer less than or equal to \\( x \\). See also: `floor_in`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.floor).
|
|
|
@@ -67,13 +149,40 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn floor(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=floor%285%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> floor(5.5)
|
|
|
+
|
|
|
+ = 5
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `floor_in` (Floor function)
|
|
|
-Returns the largest integer multiple of `base` less than or equal to `value`. For example: `floor_in(m, 5.7 m) == 5 m`.
|
|
|
+Returns the largest integer multiple of `base` less than or equal to `value`.
|
|
|
|
|
|
```nbt
|
|
|
fn floor_in<D: Dim>(base: D, value: D) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Floor in meters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=floor%5Fin%28m%2C%205%2E7%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> floor_in(m, 5.7 m)
|
|
|
+
|
|
|
+ = 5 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+Floor in centimeters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=floor%5Fin%28cm%2C%205%2E7%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> floor_in(cm, 5.7 m)
|
|
|
+
|
|
|
+ = 570 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `ceil` (Ceil function)
|
|
|
Returns the smallest integer greater than or equal to \\( x \\). See also: `ceil_in`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.ceil).
|
|
|
@@ -82,13 +191,40 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn ceil(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=ceil%285%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> ceil(5.5)
|
|
|
+
|
|
|
+ = 6
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `ceil_in` (Ceil function)
|
|
|
-Returns the smallest integer multuple of `base` greater than or equal to `value`. For example: `ceil_in(m, 5.3 m) == 6 m`.
|
|
|
+Returns the smallest integer multiple of `base` greater than or equal to `value`.
|
|
|
|
|
|
```nbt
|
|
|
fn ceil_in<D: Dim>(base: D, value: D) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Ceil in meters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=ceil%5Fin%28m%2C%205%2E3%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> ceil_in(m, 5.3 m)
|
|
|
+
|
|
|
+ = 6 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+Ceil in centimeters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=ceil%5Fin%28cm%2C%205%2E3%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> ceil_in(cm, 5.3 m)
|
|
|
+
|
|
|
+ = 530 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `trunc` (Truncation)
|
|
|
Returns the integer part of \\( x \\). Non-integer numbers are always truncated towards zero. See also: `trunc_in`.
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.trunc).
|
|
|
@@ -97,13 +233,45 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn trunc(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=trunc%285%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> trunc(5.5)
|
|
|
+
|
|
|
+ = 5
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=trunc%28%2D5%2E5%29')""></button></div><code class="language-nbt hljs numbat">>>> trunc(-5.5)
|
|
|
+
|
|
|
+ = -5
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `trunc_in` (Truncation)
|
|
|
-Truncates to an integer multiple of `base` (towards zero). For example: `trunc_in(m, -5.7 m) == -5 m`.
|
|
|
+Truncates to an integer multiple of `base` (towards zero).
|
|
|
|
|
|
```nbt
|
|
|
fn trunc_in<D: Dim>(base: D, value: D) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Truncate in meters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=trunc%5Fin%28m%2C%205%2E7%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> trunc_in(m, 5.7 m)
|
|
|
+
|
|
|
+ = 5 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+Truncate in centimeters.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=trunc%5Fin%28cm%2C%205%2E7%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> trunc_in(cm, 5.7 m)
|
|
|
+
|
|
|
+ = 570 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `mod` (Modulo)
|
|
|
Calculates the least nonnegative remainder of \\( a (\mod b) \\).
|
|
|
More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.rem_euclid).
|
|
|
@@ -112,6 +280,16 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
|
|
|
fn mod<T: Dim>(a: T, b: T) -> T
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=mod%2827%2C%205%29')""></button></div><code class="language-nbt hljs numbat">>>> mod(27, 5)
|
|
|
+
|
|
|
+ = 2
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
## Transcendental functions
|
|
|
|
|
|
Defined in: `math::transcendental`
|
|
|
@@ -124,6 +302,16 @@ More information [here](https://en.wikipedia.org/wiki/Exponential_function).
|
|
|
fn exp(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=exp%284%29')""></button></div><code class="language-nbt hljs numbat">>>> exp(4)
|
|
|
+
|
|
|
+ = 54.5982
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `ln` (Natural logarithm)
|
|
|
The natural logarithm with base \\( e \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
@@ -132,6 +320,16 @@ More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
fn ln(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=ln%2820%29')""></button></div><code class="language-nbt hljs numbat">>>> ln(20)
|
|
|
+
|
|
|
+ = 2.99573
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `log` (Natural logarithm)
|
|
|
The natural logarithm with base \\( e \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
@@ -140,6 +338,16 @@ More information [here](https://en.wikipedia.org/wiki/Natural_logarithm).
|
|
|
fn log(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=log%2820%29')""></button></div><code class="language-nbt hljs numbat">>>> log(20)
|
|
|
+
|
|
|
+ = 2.99573
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `log10` (Common logarithm)
|
|
|
The common logarithm with base \\( 10 \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Common_logarithm).
|
|
|
@@ -148,6 +356,16 @@ More information [here](https://en.wikipedia.org/wiki/Common_logarithm).
|
|
|
fn log10(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=log10%28100%29')""></button></div><code class="language-nbt hljs numbat">>>> log10(100)
|
|
|
+
|
|
|
+ = 2
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `log2` (Binary logarithm)
|
|
|
The binary logarithm with base \\( 2 \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Binary_logarithm).
|
|
|
@@ -156,6 +374,16 @@ More information [here](https://en.wikipedia.org/wiki/Binary_logarithm).
|
|
|
fn log2(x: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=log2%28256%29')""></button></div><code class="language-nbt hljs numbat">>>> log2(256)
|
|
|
+
|
|
|
+ = 8
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `gamma` (Gamma function)
|
|
|
The gamma function, \\( \Gamma(x) \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Gamma_function).
|
|
|
@@ -264,27 +492,57 @@ fn atanh(x: Scalar) -> Scalar
|
|
|
Defined in: `math::statistics`
|
|
|
|
|
|
### `maximum` (Maxmimum)
|
|
|
-Get the largest element of a list: `maximum([30 cm, 2 m]) = 2 m`.
|
|
|
+Get the largest element of a list.
|
|
|
|
|
|
```nbt
|
|
|
fn maximum<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=maximum%28%5B30%20cm%2C%202%20m%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> maximum([30 cm, 2 m])
|
|
|
+
|
|
|
+ = 2 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `minimum` (Minimum)
|
|
|
-Get the smallest element of a list: `minimum([30 cm, 2 m]) = 30 cm`.
|
|
|
+Get the smallest element of a list.
|
|
|
|
|
|
```nbt
|
|
|
fn minimum<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=minimum%28%5B30%20cm%2C%202%20m%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> minimum([30 cm, 2 m])
|
|
|
+
|
|
|
+ = 30 cm [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `mean` (Arithmetic mean)
|
|
|
-Calculate the arithmetic mean of a list of quantities: `mean([1 m, 2 m, 300 cm]) = 2 m`.
|
|
|
+Calculate the arithmetic mean of a list of quantities.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Arithmetic_mean).
|
|
|
|
|
|
```nbt
|
|
|
fn mean<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=mean%28%5B1%20m%2C%202%20m%2C%20300%20cm%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> mean([1 m, 2 m, 300 cm])
|
|
|
+
|
|
|
+ = 2 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `variance` (Variance)
|
|
|
Calculate the population variance of a list of quantities.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Variance).
|
|
|
@@ -293,6 +551,16 @@ More information [here](https://en.wikipedia.org/wiki/Variance).
|
|
|
fn variance<D: Dim>(xs: List<D>) -> D^2
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=variance%28%5B1%20m%2C%202%20m%2C%20300%20cm%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> variance([1 m, 2 m, 300 cm])
|
|
|
+
|
|
|
+ = 0.666667 m² [Area]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `stdev` (Standard deviation)
|
|
|
Calculate the population standard deviation of a list of quantities.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Standard_deviation).
|
|
|
@@ -301,6 +569,16 @@ More information [here](https://en.wikipedia.org/wiki/Standard_deviation).
|
|
|
fn stdev<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=stdev%28%5B1%20m%2C%202%20m%2C%20300%20cm%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> stdev([1 m, 2 m, 300 cm])
|
|
|
+
|
|
|
+ = 0.816497 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `median` (Median)
|
|
|
Calculate the median of a list of quantities.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Median).
|
|
|
@@ -309,6 +587,16 @@ More information [here](https://en.wikipedia.org/wiki/Median).
|
|
|
fn median<D: Dim>(xs: List<D>) -> D
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=median%28%5B1%20m%2C%202%20m%2C%20400%20cm%5D%29')""></button></div><code class="language-nbt hljs numbat">>>> median([1 m, 2 m, 400 cm])
|
|
|
+
|
|
|
+ = 2 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
## Random sampling, distributions
|
|
|
|
|
|
Defined in: `core::random`, `math::distributions`
|
|
|
@@ -413,6 +701,16 @@ More information [here](https://en.wikipedia.org/wiki/Greatest_common_divisor).
|
|
|
fn gcd(a: Scalar, b: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=gcd%2860%2C%2042%29')""></button></div><code class="language-nbt hljs numbat">>>> gcd(60, 42)
|
|
|
+
|
|
|
+ = 6
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `lcm` (Least common multiple)
|
|
|
The smallest positive integer that is divisible by both \\( a \\) and \\( b \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Least_common_multiple).
|
|
|
@@ -421,6 +719,16 @@ More information [here](https://en.wikipedia.org/wiki/Least_common_multiple).
|
|
|
fn lcm(a: Scalar, b: Scalar) -> Scalar
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=lcm%2814%2C%204%29')""></button></div><code class="language-nbt hljs numbat">>>> lcm(14, 4)
|
|
|
+
|
|
|
+ = 28
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
## Numerical methods
|
|
|
|
|
|
Defined in: `numerics::diff`, `numerics::solve`, `numerics::fixed_point`
|
|
|
@@ -433,6 +741,26 @@ More information [here](https://en.wikipedia.org/wiki/Numerical_differentiation)
|
|
|
fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X) -> Y / X
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Compute the derivative of \\( f(x) = x² -x -1 \\) at \\( x=1 \\).
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20numerics%3A%3Adiff%0Afn%20polynomial%28x%29%20%3D%20x%C2%B2%20%2D%20x%20%2D%201%0Adiff%28polynomial%2C%201%29')""></button></div><code class="language-nbt hljs numbat">>>> fn polynomial(x) = x² - x - 1
|
|
|
+diff(polynomial, 1)
|
|
|
+
|
|
|
+ = 1.0
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+Compute the free fall velocity after \\( t=2 s \\).
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20numerics%3A%3Adiff%0Afn%20distance%28t%29%20%3D%200%2E5%20g0%20t%C2%B2%0Afn%20velocity%28t%29%20%3D%20diff%28distance%2C%20t%29%0Avelocity%282%20s%29')""></button></div><code class="language-nbt hljs numbat">>>> fn distance(t) = 0.5 g0 t²
|
|
|
+fn velocity(t) = diff(distance, t)
|
|
|
+velocity(2 s)
|
|
|
+
|
|
|
+ = 19.6133 m/s [Velocity]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `root_bisect` (Bisection method)
|
|
|
Find the root of the function \\( f \\) in the interval \\( [x_1, x_2] \\) using the bisection method. The function \\( f \\) must be continuous and \\( f(x_1) \cdot f(x_2) < 0 \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Bisection_method).
|
|
|
@@ -441,6 +769,18 @@ More information [here](https://en.wikipedia.org/wiki/Bisection_method).
|
|
|
fn root_bisect<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x1: X, x2: X, x_tol: X, y_tol: Y) -> X
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Find the root of \\( f(x) = x² +x -2 \\) in the interval \\( [0, 100] \\).
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20numerics%3A%3Asolve%0Afn%20f%28x%29%20%3D%20x%C2%B2%20%2Bx%20%2D2%0Aroot%5Fbisect%28f%2C%200%2C%20100%2C%200%2E01%2C%200%2E01%29')""></button></div><code class="language-nbt hljs numbat">>>> fn f(x) = x² +x -2
|
|
|
+root_bisect(f, 0, 100, 0.01, 0.01)
|
|
|
+
|
|
|
+ = 1.00098
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `root_newton` (Newton's method)
|
|
|
Find the root of the function \\( f(x) \\) and its derivative \\( f'(x) \\) using Newton's method.
|
|
|
More information [here](https://en.wikipedia.org/wiki/Newton%27s_method).
|
|
|
@@ -449,6 +789,19 @@ More information [here](https://en.wikipedia.org/wiki/Newton%27s_method).
|
|
|
fn root_newton<X: Dim, Y: Dim>(f: Fn[(X) -> Y], f_prime: Fn[(X) -> Y / X], x0: X, y_tol: Y) -> X
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Find a root of \\( f(x) = x² -3x +2 \\) using Newton's method.
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20numerics%3A%3Asolve%0Afn%20f%28x%29%20%3D%20x%C2%B2%20%2D3x%20%2B2%0Afn%20f%5Fprime%28x%29%20%3D%202x%20%2D3%0Aroot%5Fnewton%28f%2C%20f%5Fprime%2C%200%20%2C%200%2E01%29')""></button></div><code class="language-nbt hljs numbat">>>> fn f(x) = x² -3x +2
|
|
|
+fn f_prime(x) = 2x -3
|
|
|
+root_newton(f, f_prime, 0 , 0.01)
|
|
|
+
|
|
|
+ = 0.996078
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `fixed_point` (Fixed-point iteration)
|
|
|
Compute the approximate fixed point of a function \\( f: X \rightarrow X \\) starting from \\( x_0 \\), until \\( |f(x) - x| < ε \\).
|
|
|
More information [here](https://en.wikipedia.org/wiki/Fixed-point_iteration).
|
|
|
@@ -457,6 +810,18 @@ More information [here](https://en.wikipedia.org/wiki/Fixed-point_iteration).
|
|
|
fn fixed_point<X: Dim>(f: Fn[(X) -> X], x0: X, ε: X) -> X
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Compute the fixed poin of \\( f(x) = x/2 -1 \\).
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20numerics%3A%3Afixed%5Fpoint%0Afn%20function%28x%29%20%3D%20x%2F2%20%2D%201%0Afixed%5Fpoint%28function%2C%200%2C%200%2E01%29')""></button></div><code class="language-nbt hljs numbat">>>> fn function(x) = x/2 - 1
|
|
|
+fixed_point(function, 0, 0.01)
|
|
|
+
|
|
|
+ = -1.99219
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
## Geometry
|
|
|
|
|
|
Defined in: `math::geometry`
|
|
|
@@ -468,6 +833,16 @@ The length of the hypotenuse of a right-angled triangle \\( \sqrt{x^2+y^2} \\).
|
|
|
fn hypot2<T: Dim>(x: T, y: T) -> T
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=hypot2%283%20m%2C%204%20m%29')""></button></div><code class="language-nbt hljs numbat">>>> hypot2(3 m, 4 m)
|
|
|
+
|
|
|
+ = 5 m [Length]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `hypot3`
|
|
|
The Euclidean norm of a 3D vector \\( \sqrt{x^2+y^2+z^2} \\).
|
|
|
|
|
|
@@ -475,6 +850,16 @@ The Euclidean norm of a 3D vector \\( \sqrt{x^2+y^2+z^2} \\).
|
|
|
fn hypot3<T: Dim>(x: T, y: T, z: T) -> T
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=hypot3%288%2C%209%2C%2012%29')""></button></div><code class="language-nbt hljs numbat">>>> hypot3(8, 9, 12)
|
|
|
+
|
|
|
+ = 17
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
### `circle_area`
|
|
|
The area of a circle, \\( \pi r^2 \\).
|
|
|
|
|
|
@@ -515,6 +900,17 @@ More information [here](https://en.wikipedia.org/wiki/Quadratic_equation).
|
|
|
fn quadratic_equation<A: Dim, B: Dim>(a: A, b: B, c: B^2 / A) -> List<B / A>
|
|
|
```
|
|
|
|
|
|
+<details>
|
|
|
+<summary>Examples</summary>
|
|
|
+
|
|
|
+Solve the equation \\( 2x² -x -1 = 0 \\)
|
|
|
+<pre><div class="buttons"><button class="fa fa-play play-button" title="Run this code" aria-label="Run this code" onclick=" window.open('https://numbat.dev/?q=use%20extra%3A%3Aalgebra%0Aquadratic%5Fequation%282%2C%20%2D1%2C%20%2D1%29')""></button></div><code class="language-nbt hljs numbat">>>> quadratic_equation(2, -1, -1)
|
|
|
+
|
|
|
+ = [1, -0.5] [List<Scalar>]
|
|
|
+</code></pre>
|
|
|
+
|
|
|
+</details>
|
|
|
+
|
|
|
## Trigonometry (extra)
|
|
|
|
|
|
Defined in: `math::trigonometry_extra`
|