Monte Carlo changed
This commit is contained in:
@@ -0,0 +1,146 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "3635637b",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Practice Problem - Monte-Carlo Error Propagation"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "1e41e304",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Part 1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "895e84c4",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"You have likely encountered the concept of propagation of uncertainty before (see [the usual rules here](http://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas)). The idea is that given measurements with uncertainties, we can find the uncertainty on the final result of an equation.\n",
|
||||||
|
"\n",
|
||||||
|
"For example, let us consider the following equation:\n",
|
||||||
|
"\n",
|
||||||
|
"$$F = \\frac{G~M_1~M_2}{r^2}$$\n",
|
||||||
|
"\n",
|
||||||
|
"which gives the gravitational force between two masses $M_1$ and $M_2$ separated by a distance $r$.\n",
|
||||||
|
"\n",
|
||||||
|
"Let us now imagine that we have two masses:\n",
|
||||||
|
"\n",
|
||||||
|
"$$M_1=40\\times10^4\\pm0.05\\times10^4\\rm{kg}$$\n",
|
||||||
|
"\n",
|
||||||
|
"and\n",
|
||||||
|
"\n",
|
||||||
|
"$$M_2=30\\times10^4\\pm0.1\\times10^4\\rm{kg}$$\n",
|
||||||
|
"\n",
|
||||||
|
"separated by a distance:\n",
|
||||||
|
"\n",
|
||||||
|
"$$r=3.2\\pm0.01~\\rm{m}$$\n",
|
||||||
|
"\n",
|
||||||
|
"where the uncertaintes are the standard deviations of Gaussian distributions which could be e.g. measurement errors.\n",
|
||||||
|
"\n",
|
||||||
|
"We also know:\n",
|
||||||
|
"\n",
|
||||||
|
"$$G = 6.67384\\times10^{-11}~\\rm{m}^3~\\rm{kg}^{-1}~\\rm{s}^{-2}$$\n",
|
||||||
|
"\n",
|
||||||
|
"(exact value, no uncertainty)\n",
|
||||||
|
"\n",
|
||||||
|
"Use the [standard error propagation rules](http://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas) to determine the resulting force and uncertainty in your script (you can just derive the equation by hand and implement it in a single line in your code).\n",
|
||||||
|
"\n",
|
||||||
|
"Now, we can try using a **Monte-Carlo** technique instead. The idea behind Monte-Carlo techniques is to generate many possible solutions using random numbers and using these to look at the overall results. In the above case, you can propagate uncertainties with a Monte-Carlo method by doing the following:\n",
|
||||||
|
"\n",
|
||||||
|
"* randomly sample values of $M_1$, $M_2$, and $r$, 1000000 times, using the means and standard deviations given above\n",
|
||||||
|
"\n",
|
||||||
|
"* compute the gravitational force for each set of values\n",
|
||||||
|
"\n",
|
||||||
|
"You should do this with Numpy arrays, and **without any loops**. You should then get an array of 1000000 different values for the forces.\n",
|
||||||
|
"\n",
|
||||||
|
"Make a plot of the normalized histogram of these values of the force, and then overplot a Gaussian function with the mean and standard deviation derived with the standard error propagation rules. Make sure that you pick the range of x values in the plot wisely, so that the two distributions can be seen. Make sure there are also a sensible number of bins in the histogram so that you can compare the shape of the histogram and the Gaussian function. The two distributions should agree pretty well."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "6ed585ea",
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\n",
|
||||||
|
"# Your solution here\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "0334e752",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Part 2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "117bedb7",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now repeat the experiment above with the following values:\n",
|
||||||
|
"\n",
|
||||||
|
"$$M_1=40\\times10^4\\pm2\\times10^4\\rm{kg}$$\n",
|
||||||
|
"$$M_2=30\\times10^4\\pm10\\times10^4\\rm{kg}$$\n",
|
||||||
|
"$$r=3.2\\pm1.0~\\rm{m}$$\n",
|
||||||
|
"\n",
|
||||||
|
"and as above, produce a plot.\n",
|
||||||
|
"\n",
|
||||||
|
"In this case, which method do you think is more accurate? Why? What do you think are the advantages of using a Monte-Carlo technique?"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "7eaa28f9",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Solution"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "eb657c11",
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"\n",
|
||||||
|
"# your solution here\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"anaconda-cloud": {},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python [Root]",
|
||||||
|
"language": "python",
|
||||||
|
"name": "Python [Root]"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.5.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user