You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/src/list-functions-math.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -886,24 +886,24 @@ Compute the numerical derivative of the function \\( f \\) at point \\( x \\) us
886
886
More information [here](https://en.wikipedia.org/wiki/Numerical_differentiation).
887
887
888
888
```nbt
889
-
fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X) -> Y / X
889
+
fn diff<X: Dim, Y: Dim>(f: Fn[(X) -> Y], x: X, Δx: X) -> Y / X
890
890
```
891
891
892
892
<details>
893
893
<summary>Examples</summary>
894
894
895
895
Compute the derivative of \\( f(x) = x² -x -1 \\) at \\( x=1 \\).
896
-
<pre><divclass="buttons"><buttonclass="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><codeclass="language-nbt hljs numbat">use numerics::diff
896
+
<pre><divclass="buttons"><buttonclass="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%2C%201e%2D10%29')""></button></div><codeclass="language-nbt hljs numbat">use numerics::diff
897
897
fn polynomial(x) = x² - x - 1
898
-
diff(polynomial, 1)
898
+
diff(polynomial, 1, 1e-10)
899
899
900
900
= 1.0
901
901
</code></pre>
902
902
903
903
Compute the free fall velocity after \\( t=2 s \\).
904
-
<pre><divclass="buttons"><buttonclass="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><codeclass="language-nbt hljs numbat">use numerics::diff
904
+
<pre><divclass="buttons"><buttonclass="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%2C%201e%2D10%20s%29%0Avelocity%282%20s%29')""></button></div><codeclass="language-nbt hljs numbat">use numerics::diff
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=has%5Funit%2820%20km%2Fh%2C%20km%2Fh%29')""></button></div><codeclass="language-nbt hljs numbat">has_unit(20 km/h, km/h)
203
+
204
+
= true [Bool]
205
+
</code></pre>
206
+
207
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=has%5Funit%2820%20km%2Fh%2C%20m%2Fs%29')""></button></div><codeclass="language-nbt hljs numbat">has_unit(20 km/h, m/s)
208
+
209
+
= false [Bool]
210
+
</code></pre>
211
+
212
+
</details>
213
+
214
+
### `is_dimensionless`
215
+
Returns true if `quantity` is dimensionless, or if `quantity` is zero.
216
+
217
+
```nbt
218
+
fn is_dimensionless<T: Dim>(quantity: T) -> Bool
219
+
```
220
+
221
+
<details>
222
+
<summary>Examples</summary>
223
+
224
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=is%5Fdimensionless%2810%29')""></button></div><codeclass="language-nbt hljs numbat">is_dimensionless(10)
225
+
226
+
= true [Bool]
227
+
</code></pre>
228
+
229
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=is%5Fdimensionless%2810%20km%2Fh%29')""></button></div><codeclass="language-nbt hljs numbat">is_dimensionless(10 km/h)
230
+
231
+
= false [Bool]
232
+
</code></pre>
233
+
234
+
</details>
235
+
236
+
### `unit_name`
237
+
Returns a string representation of the unit of `quantity`. Returns an empty string if `quantity` is dimensionless.
238
+
239
+
```nbt
240
+
fn unit_name<T: Dim>(quantity: T) -> String
241
+
```
242
+
243
+
<details>
244
+
<summary>Examples</summary>
245
+
246
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=unit%5Fname%2820%29')""></button></div><codeclass="language-nbt hljs numbat">unit_name(20)
247
+
248
+
= "" [String]
249
+
</code></pre>
250
+
251
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=unit%5Fname%2820%20m%5E2%29')""></button></div><codeclass="language-nbt hljs numbat">unit_name(20 m^2)
252
+
253
+
= "m²" [String]
254
+
</code></pre>
255
+
256
+
<pre><divclass="buttons"><buttonclass="fa fa-play play-button"title="Run this code"aria-label="Run this code"onclick="window.open('https://numbat.dev/?q=unit%5Fname%2820%20km%2Fh%29')""></button></div><codeclass="language-nbt hljs numbat">unit_name(20 km/h)
fn unit_of<T: Dim>(x: T) -> T = if x_value == 0 then error("Invalid argument: cannot call `unit_of` on a value that evaluates to 0") else x / value_of(x)
11
11
where x_value = value_of(x)
12
+
13
+
@description("Returns true if `quantity` has the same unit as `unit_query`, or if `quantity` evaluates to zero.")
@description("Adds the given time span to a `DateTime`. This uses leap-year and DST-aware calendar arithmetic with variable-length days, months, and years.")
error("calendar_add: Unsupported unit for `span`")
77
77
78
78
@description("Subtract the given time span from a `DateTime`. This uses leap-year and DST-aware calendar arithmetic with variable-length days, months, and years.")
0 commit comments