Error propagation - Three approaches

In PHYS 211 we did an experiment to determine “little g” from measurements of the length and period of a pendulum.   The following cell defines a function giving g for known values of l and t;  the cell also gives typical data for l and t, along with associated uncertainties.  The uncertainties are assumed to represent the standard deviations of normally distributed values.

g[l_,t_]:= 4 π^2 l/t^2
lMean = 1.0;    (* Measured length of pendulum in meters *)
σl = 0.004;      (* Uncertainty in length - assumed to be s.d. of normal dist.*)
tMean = 2.0;   (* Measured period in seconds *)
σt = 0.005;       (* Uncertainty in  period assumed- to be s.d. of normal dist. *)

"Functional Approach"

Approach used in Hughes & Hase 4.1.1 and 4.2.1

Δgl = g[lMean,tMean] - g[lMean+σl,tMean]

Δgt = g[lMean,tMean] - g[lMean,tMean+σt]

Δg = Sqrt[Δgl^2 + Δgt^2]

"Calculus Approach"

Approach used in Hughes & Hase 4 .1 .2 and 4.2 .2 :

Clear[l,t,σl,σt]

Δgl = D[g[l,t],l]*σl

Δgt = D[g[l,t],t]*σt

Δg = Sqrt[Δgl^2 + Δgt^2]

Total uncertainty using Mathematica "rules":

Δg/. {t->tMean,l->lMean,σt -> 0.005,σl->0.004}

OR Total uncertainty via explicit assignment of values to t, l, σt, and σl :

t = tMean;
l = lMean;
σt = 0.005;
σl = 0.004;

Δg

OR Total uncertainty via making derivatives functions of t and l (no delayed evaluation):

Clear[l,t]

dgdt[l_,t_] = D[g[l,t],t] σt
dgdl[l_,t_] =D[g[l,t],l] σl

dg = Sqrt[dgdt[lMean,tMean]^2+ dgdl[lMean,tMean]^2]

Monte Carlo Technique

Here we are going to get the uncertainty in a different way, using simulated data.  Our propagation of uncertainty formulas assume that the uncertainties are standard deviations of normally  distributed data.  We can “redo” the experment, with new “measurements” sampled from the assumed  distributions:

Specify distributions for l and t from which we will be sampling:

lDistribution = NormalDistribution[lMean, σl];
tDistribution = NormalDistribution[tMean, σt];

Two Mathematica Techniques :

 Version 1 - Sample a value of l, sample a value of t, calculate g, and repeat (using the Table command).

Sample l and t values from appropriate distribution (note delayed evaluation) :

lValue := RandomVariate[lDistribution]
tValue := RandomVariate[tDistribution]

Generate nEx random values for g:

gDistribution =Table[g[lValue,tValue],{100}];

Statistics of distribution of g-values:

Mean[gDistribution]
StandardDeviation[gDistribution]

Histogram[gDistribution]

Mathematica Version 2 - Sample a List of t's, sample a List of l's, and then calculate all values of g with a single command.

nEx = 10000;
lData = RandomVariate[lDistribution,nEx];
tData = RandomVariate[tDistribution,nEx];

gData = 4 π^2 lData/tData^2;

Mean[gData]
StandardDeviation[gData]

Histogram[gData]

or plot with a specified number of channels...

Histogram[gData,50]

You may also plot as a probability distribution function (PDF) instead,

Histogram[gData,50,"PDF"]

or plot the probability of being in each bin.

Histogram[gData,50,"Probability"]