Numeric error propagation: Difference between revisions

m
no edit summary
mNo edit summary
Line 1,475:
 
=={{header|Julia}}==
=== Using Measurement library ===
<lang julia>
using Measurements
module NumericError
 
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 ===
<lang julia>module NumericError
 
import Base: convert, promote_rule, +, -, *, /, ^
4,105

edits