from uncertainties import ufloat
from uncertainties.umath import *
# calculs divers
x = ufloat((545.25, 0.01)) # x = 545.25+/-0.01
y = ufloat((12345.351, 0.001)) # x = 12345.351+/-0.001
print x * x
297297.5625+/-10.905
print x + x
1090.5+/-0.02
print x - x
0.0
carré = x**2
print carré - x*x
0.0
y = ufloat((12345.351, 0.001)) # x = 12345.351+/-0.001
print x * y
6731302.63275+/-123.454714081
print cos(x)/sin(y)
-0.204101841625+/-0.0109873714255
# le module tient compte des corrélations entre variables
carré = x**2
print carré - x*x
0.0
a = 57
poly = x**2 + a
print poly
297354.5625+/-10.905
print poly - x*x
57.0
# les valeurs nominales et les incertitudes peuvent être retrouvées à tout instant
print x.nominal_value
545.25
print x.std_dev()
0.01
# les tableaux (arrays) de Numpy peuvent être utilisés et traités de la même manière
import numpy as np
test = np.array([x,y])
print test.sum()
12890.601+/-0.0100498756211
# ou directement avec unumpy
from uncertainties import unumpy
test2 = = unumpy.uarray(([545.25,12345.351],[0.1,0.01]))
print test2
[545.25+/-0.1 12345.351+/-0.01]
# ou directement :
test3 = unumpy.uarray(([x.nominal_value,y.nominal_value],[x.std_dev(),y.std_dev()]))
print test3
[545.25+/-0.01 12345.351+/-0.001]
print test3.sum()
12890.601+/-0.100498756211
# la matrice des covariances peut être obtenue
from uncertainties import covariance_matrix
fonction = x-3*y
cov_matrix = covariance_matrix([x, y, fonction])
print cov_matrix
[[0.0001, 0.0, 0.0001],
[0.0, 9.9999999999999995e-07,-3.0000000000000001e-06],
[0.0001, -3.0000000000000001e-06, 0.00010900000000000001]]