Skip to content

math.uncertainty

measurements with a margin of error, like 5 ± 0.1 m, carried through calculations

Measurements with a margin of error. A length measured as 5 m might really be anywhere from 4.9 m to 5.1 m, written 5 ± 0.1 m. Use these values in calculations as usual, and zil works out how far off the result could be.

Errors are taken to be independent and random, the standard way in science, so they partly cancel: adding 5 ± 0.3 and 2 ± 0.4 gives 7 ± 0.5, not 7 ± 0.7.

Tags: statistics

  • value the measured value without its error: 5 for 5 ± 0.1
  • error the error alone, in the same unit: 0.1 for 5 ± 0.1
  • rel_error the error as a fraction of the value, so 0.02 for 5 ± 0.1
1
# x ± e, also typed x +- e
2
5 ± 0.1 m
3
# x ± n%: an error of n% of x
4
20 ± 5%20 ± 1
5
# adding: errors combine as sqrt(0.3² + 0.4²)
6
(5 ± 0.3) + (2 ± 0.4)7 ± 0.5
7
# multiplying: percentage errors combine
8
(10 ± 1 m) * (2 ± 0.1 m)20 ± 2.23607 m^2
9
# functions carry the error through
10
sqrt(16 ± 1)4 ± 0.125
11
# and so do unit conversions
12
5 ± 0.1 km to mi3.10686 ± 0.0621371 mi
Example outputCtrl+Enter to run
1
# long, the default: in the best-fitting unit
2
pretty(1500 ± 20 m)"1.5 ± 0.02 km"
3
# short: K, M, B and T for thousands up to trillions
4
pretty(1234567 ± 1000, "short")"1.23M ± 1K"
Example outputCtrl+Enter to run
value(x: uncertain) -> num|quantity

the measured value without its error: 5 for 5 ± 0.1

1
(5 ± 0.1 m).value5 m
Example outputCtrl+Enter to run

See also error, rel_error

error(x: uncertain) -> num|quantity

the error alone, in the same unit: 0.1 for 5 ± 0.1

1
(5 ± 0.1 m).error0.1 m
2
(20 ± 5%).error1
Example outputCtrl+Enter to run

See also value, rel_error

rel_error(x: uncertain) -> float

the error as a fraction of the value, so 0.02 for 5 ± 0.1

A plain number with no unit, so .percent shows it as a percentage

1
(5 ± 0.1 m).rel_error0.02
2
(20 ± 5%).rel_error.percent"5%"
Example outputCtrl+Enter to run

See also error, value

1
# area of a measured rectangle
2
(2 ± 0.05 m) * (3 ± 0.05 m)6 ± 0.180278 m^2
3
# a 1 m pendulum's swing time, in seconds
4
2 * pi * sqrt((1 ± 0.01) / 9.81)2.00607 ± 0.0100303
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.