Examples¶
Imagine you measured a rectangular table whose sides measure 1.5m
and 80cm
with ruler with precision up to 1mm
. Then, you can initialize the Value
as
- Python:
from uncvalue import Value
L1 = Value(1.5, 1e-3)
L2 = Value(0.8, 1e-3)
- Julia:
using UncValue
L1 = Value(1.5, 1e-3)
L2 = Value(0.8, 1e-3)
You now want to calculate the area of the table, so you multiply both lengths
- Python:
A = L1 * L2
print(A)
- Julia:
A = L1 * L2
println(A)
and obtain as outcome (1200.0 ± 1.7)·10^-3
.
Of course, it is possible to perform more complex operations like
- Python (
numpy
required, functions from pythonmath
will only compute the value)
import numpy as np
print(L1 ** L2) # power -> (13831.6 ± 9.3)·10^-4
print(np.sin(L1)) # sinus -> (99749.5 ± 7.1)·10^-5
print(np.exp(L2)) # exponential -> (2225.5 ± 2.2)·10^-3
- Julia
println(L1^L2) # power -> (13831.6 ± 9.3)·10^-4
println(sin(L1)) # sinus -> (99749.5 ± 7.1)·10^-5
println(exp(L2)) # exponential -> (2225.5 ± 2.2)·10^-3
You can also take a look at the sample floder containing real use and more complex examples.