+
Monte Carlo error propagation
Developed by Andy Rundquist  Published October 3, 2016
This set of exercises guides the student in exploring how to use a computer algebra system to determine the propagated error of a calculated parameter based on measured quantities with known uncertainties. This approach is based on the Monte Carlo approach.
As is [detailed very thoroughly here](http://www.av8n.com/physics/uncertainty.htm), there are many methods for doing error propagation. Probably the most common is the calculus approach which assumes that not only do all variables follow a normal distribution, but that any calculation does so as well. Note how the examples described here don't obey that latter issue. The link above carefully describes how the Monte Carlo method is the most accurate way of doing error propagation. From a numeric perspective, it's also the easiest (not counting the simple crankthreetimes). Certainly using a Computer Algebra System allows for coding up the calculus approach, but if the Monte Carlo approach is more accurate, why not do it and skip having to use a Computer Algebra System?
Subject Area  Mathematical/Numerical Methods 

Level  First Year 
Available Implementations  Mathematica, Python, and Easy Java Simulations 
Learning Objectives 
Students will be able to:
* Generate normally distributed random numbers (**Exercise 1**)
* Plot histograms. Calculate mean, median, and standard deviation for a distribution. Generate a new distribution from previously generated random numbers. (**Exercise 3**)
* Compare the analytical (calculus) approach to the Monte Carlo approach (**Exercises 2 and 3**)

Time to Complete  30 min 
These exercises are not tied to a specific programming language. Example implementations are provided under the Code tab, but the Exercises can be implemented in whatever platform you wish to use (e.g., Excel, Python, MATLAB, etc.).
1. Produce a large set of numbers that obey a normal distribution with a mean of 5.4 and a standard deviation of 0.2. Many computer programming languages have a weighted random number built in. You can also build your own using the Box Muller transformation that takes two uniformly distributed random numbers between 0 and 1 and returns two normally distributed random numbers with a mean of zero and a standard deviation of 1. These can then be transformed to match the requested mean and standard deviation.
Plot a histogram of the large data set, confirming that the peak and width are what you expected.
2. Determine the histogram for the speed example above by using the calculus error propagation approach.
a) Assuming that all values are distributed according to a normal distribution, the calculus approach is given by
$$\sigma_f=\sqrt{\left(\frac{\partial f}{\partial x}\sigma_x\right)^2+\left(\frac{\partial f}{\partial y}\sigma_y\right)^2}$$
Show that in the case of the speed calculation, this becomes :
$$\sigma_v=\frac{x}{t}\sqrt{\left(\frac{\sigma_x}{x}\right)^2+\left(\frac{\sigma_y}{y}\right)^2}$$
b) Using Eq. 2, determine the error for the speed example from Exercise 1. 3. Now use the Monte Carlo method. Generate several hundreds or thousands of values for both position and time according to their respective distributions. Calculate the speed that corresponds to each of these values, and plot a histogram of speeds. Compare with the results of exercise 2.
3. Produce several (hundreds or thousands) of both position and time estimates according to their respective distributions and calculate their associated speeds. Then plot the histogram of those speeds and compare with (2).
4. Determine the mean, median, and standard deviation of the histrogram for (3) and compare with 2.
5. Extend the Monte Carlo approach to lab data of your own.
Download Options
Share a Variation
Did you have to edit this material to fit your needs? Share your changes by
Creating a Variation
Credits and Licensing
Andy Rundquist, "Monte Carlo error propagation," Published in the PICUP Collection, October 2016.
The instructor materials are ©2016 Andy Rundquist.
The exercises are released under a Creative Commons AttributionNonCommercialShareAlike 4.0 license