Complex error (uncertainty) propogation with covariance matrix
Code: "propog_errors1.py". Programming language: Python DMelt Version 1. Last modified: 05/09/2015. License: Free
https://datamelt.org/code/cache/propog_errors1_780.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



""" This example is based on a Python code. It will not work in Java/Groovy"
"""

import uncertainties
from uncertainties.umath import sin
from uncertainties import ufloat,AffineScalarFunc, ufloat_fromstr, umath

x=ufloat(1, 0.1)  # x = 1+/-0.1
print "2*x=",2*x
print "x**2=",x*x
print "sin(1+2*x)=",sin(1+2*x)
print "Derivative=",(2*x+1000).derivatives[x]
print "Correlations between variables are automatically handled"

square=x*x
print square.n , " +-", square.s  

print "Covariance and correlation matrices"
x = ufloat(1, 0.1)
y = -2*x+10
z = -3*x
covs = uncertainties.covariance_matrix([x, y, z])
print covs