Popular recipes by Eric-Olivier LE BIGOT http://code.activestate.com/recipes/users/2672032/2010-01-15T06:08:56-08:00ActiveState Code RecipesCalculations with error propagation, and semi-formal expressions (Python)
2010-01-15T06:08:56-08:00Eric-Olivier LE BIGOThttp://code.activestate.com/recipes/users/2672032/http://code.activestate.com/recipes/576721-calculations-with-error-propagation-and-semi-forma/
<p style="color: grey">
Python
recipe 576721
by <a href="/recipes/users/2672032/">Eric-Olivier LE BIGOT</a>
(<a href="/recipes/tags/calculus/">calculus</a>, <a href="/recipes/tags/error_propagation/">error_propagation</a>, <a href="/recipes/tags/expressions/">expressions</a>, <a href="/recipes/tags/formal_calculations/">formal_calculations</a>, <a href="/recipes/tags/lazy_evaluation/">lazy_evaluation</a>, <a href="/recipes/tags/uncertainties/">uncertainties</a>).
Revision 22.
</p>
<p><strong>Do not use this module</strong>, but use instead the more powerful <a href="http://pypi.python.org/pypi/uncertainties/">uncertainties.py module</a>.</p>
<p>Module for performing calculations with error propagation, such as (1 +- 0.1) * 2 = 2 +- 0.2. Mathematical operations (addition, etc.), operations defined in the math module (sin, atan,...) and logical operations (<, >, etc.) can be used.</p>
<p>Correlations between parts of an expression are correctly taken into account (for instance, the error on "x-x" is strictly zero).</p>
<p>Code written for floats should directly work with the numbers with uncertainty defined here, without much need for modifications.</p>
<p>The module also contains a class that represents non-evaluated mathematical expressions. This class is used for performing the differentiation required by the error propagation calculation, but can be used on its own, for manipulating "semi-formal" expressions whose variables can be accessed.</p>