Uncertainty (error) propogation using a Monte Carlo method and complex functions
Code: "errors_mc_multi.py". Programming language: Python DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/errors_mc_multi_1799.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.



from java.lang import Math 
from jhplot import *
from jhpro.upropog import UPropogate

class MyFunc(FNon):   
     def value(self, x):                
              y=x[0]*x[0]*Math.sqrt(x[0])*self.p[0]+self.p[1]
              if (x[0]<4): y=0
              return y 

pl = MyFunc("test",1,2)    
print "f(2)=  ",pl.value([2])
print pl.numberOfParameters() 
print pl.dimension()
print pl.parameterNames().tolist() 

# define parameters and their errors
p0=100
p1=20

p0_err=10
p1_err=2

# do calculations at x=10 (with zero error)
xval=10
xval_err=0

ff=UPropogate(pl,[p0,p1],[p0_err,p1_err],[xval],[xval_err],10000)
err=ff.getStd()
pl.setParameter("par0",p0) 
pl.setParameter("par1",p1)
val=pl.value([xval])
print "val=",val," +- ",err


hh=ff.getHisto()
c1=HPlot()
c1.visible()
c1.setAutoRange()
c1.draw(hh)

Ads help maintain this website.