Error propogations for multiple measurements
Code: "p1d_errors.py". Programming language: Python DMelt Version 1. Last modified: 12/08/2015. License: Pro
https://datamelt.org/code/cache/p1d_errors_115.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.



# Shows how to combine multiple measurements with errors
from java.util import Random
from jhplot  import *
from math import *

rand=Random()

# sum of all measurements
ptot=P1D("test")
ptot.add(0,0,0)
# each measurement has a measured value 10 and error with sigma=1 (Gaussian)
# relative error: 10%
# add 10 numbers with errors
for i in range(100):
   p1=P1D("single measurement: value 10 and error from Gaussian")
   p1.add(0, 10,abs(rand.nextGaussian()))
   print i, "Value=",p1.getY(0), " Error=",p1.getYupper(0)," Relative error (%) =",100*p1.getYupper(0)/p1.getY(0)
   ptot.oper(p1,"+")  # add them together with errors 
                      # treat errors independently

print "sum value=",ptot.getY(0)
print "error value=",ptot.getYupper(0)
print "Relative error (%) =",100*ptot.getYupper(0)/ptot.getY(0)

You see the box below because you did not login.