z}\right)_{z = \bar{z}} \sigma_z \right)^2\]</p><p>What <code>Measurements.jl</code> really does is to calculate the derivatives like <span>$\partial a/\partial x$</span> and <span>$\partial G/\partial x = (\partial G/\partial a)(\partial a/\partial x) + (\partial G/\partial b)(\partial b/\partial x)$</span>, and store them in the <code>der</code> field of <span>$a$</span> and <span>$G$</span> respectively in order to be able to perform further operations involving these quantities.</p><p>This method is also described in the paper by Giordano, M.</p><h2 id="Defining-Methods-for-Mathematical-Operations"><a class="docs-heading-anchor" href="#Defining-Methods-for-Mathematical-Operations">Defining Methods for Mathematical Operations</a><a id="Defining-Methods-for-Mathematical-Operations-1"></a><a class="docs-heading-anchor-permalink" href="#Defining-Methods-for-Mathematical-Operations" title="Permalink"></a></h2><p><code>Measurements.jl</code> defines new methods for mathematical operations in order to make them accept <code>Measurement</code> arguments. The single most important thing to know about how to define new methods in the package is the <code>Measurements.result</code>. This function, not exported because it is intended to be used only within the package, takes care of propagating the uncertainty as described in the section above. It has two methods: one for functions with arity equal to one, and the other for any other case. This is its syntax:</p><pre><code class="language-julia hljs">result(val::Real, der::Real, a::Measurement)</code></pre><p>for functions of one argument, and</p><pre><code class="language-julia hljs">result(val, der, a)</code></pre><p>for functions of two or more arguments. The arguments are:</p><ul><li><code>val</code>: the nominal result of the operation <span>$G(a, \dots)$</span>;</li><li><code>der</code>: the partial derivative <span>$\partial G/\partial a$</span> of a function <span>$G = G(a)$</span> with respect to the argument <span>$a$</span> for one-argument functions or the tuple of partial derivatives with respect to each argument in other cases;</li><li><code>a</code>: the argument(s) of <span>$G$</span>, in the same order as the corresponding derivatives in <code>der</code> argument.</li></ul><p>In the case of functions with arity larger than one, <code>der</code> and <code>a</code> tuples must have the same length.</p><p>For example, for a one-argument function like <span>$\cos$</span> we have</p><pre><code class="language-julia hljs">cos(a::Measurement) = result(cos(a.val), -sin(a.val), a)</code></pre><p>Instead, the method for subtraction operation is defined as follows:</p><pre><code class="language-julia hljs">-(a::Measurement, b::Measurement) =
0 commit comments