I was reading John Denker's excellent document on uncertainties,
http://www.av8n.com/physics/uncertainty.htm, and thought it'd be fun
to program the Monte Carlo simulation technique he describes in it.
Although a spreadsheet can be used, and is given on that site, I find
it easier to use something like Python for analysis. In my code, you
specify the value and the uncertainty, like:
b=Quantity(0.4,0.04)
or
d=Quantity('0.4 +- 10%')
and some other ways.
You then then ask it to evaluate some expression, like:
x=evaluate('(((a+b)+c)+d)+e')
It then samples (default 10000 samples) all of the values you
specified, with a Gaussian distribution with mean and standard
deviation set by the value and uncertainty of the quantity. It
returns then the mean and standard deviation of the result.
I use as demonstrations two examples from John Denker's site. The
following code: