minor changes

parent 13b4177a
......@@ -4,20 +4,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# On the computation of $\\pi$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Asking the maths library"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# On the computation of $\\pi$\n",
"\n",
"## Asking the maths library\n",
"\n",
"My computer tells me that $\\pi$ is *approximatively*"
]
},
......@@ -82,13 +72,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using a surface fraction argument"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using a surface fraction argument\n",
"\n",
"A method that is easier to understand and does not make use of thesin function is based on thefact that if $X \\sim U(0,1)$ and $Y \\sim U(0,1)$, then $P[X^2 + Y^2 \\leq 1] = \\frac{\\pi}{4}$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method). The following code uses this approach:"
]
},
......@@ -113,12 +98,14 @@
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"\n",
"np.random.seed(seed=42)\n",
"N=1000\n",
"x=np.random.uniform(size=N, low=0, high=1)\n",
"y=np.random.uniform(size=N, low=0, high=1)\n",
"accept=(x*x+y*y)<=1\n",
"reject=np.logical_not(accept)\n",
"\n",
"fig, ax=plt.subplots(1)\n",
"ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)\n",
"ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n",
......@@ -151,13 +138,6 @@
"source": [
"4*np.mean(accept)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment