Numeric error propagation: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 1,475: | Line 1,475: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
=== Using Measurement library === |
|||
<lang julia> |
<lang julia> |
||
using Measurements |
|||
⚫ | |||
x1 = measurement(100, 1.1) |
|||
x2 = measurement(200, 2.2) |
|||
y1 = measurement(50, 1.2) |
|||
y2 = measurement(100, 2.3) |
|||
d = sqrt((x1 - x2)^2 + (y1 - y2)^2) |
|||
@show d |
|||
@show d.val, d.err |
|||
</lang>{{out}} |
|||
The Measurement library will round to correct decimal place precision when displaying tolerances, so the fields are shown to show the calculations are equivalent. |
|||
<pre> |
|||
d = 111.8 ± 2.5 |
|||
(d.val, d.err) = (111.80339887498948, 2.4871670631463423) |
|||
</pre> |
|||
=== With custom module === |
|||
⚫ | |||
import Base: convert, promote_rule, +, -, *, /, ^ |
import Base: convert, promote_rule, +, -, *, /, ^ |