finished, try 1

parent 4bae37e7
...@@ -43,16 +43,16 @@ ...@@ -43,16 +43,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"2.0" "3.128911138923655"
] ]
}, },
"execution_count": 2, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
"N = 10000\n", "N = 10000\n",
"x = np.random.uniform(size=N, low=0, high=1)\n", "x = np.random.uniform(size=N, low=0, high=1)\n",
"theta = np.random.uniform(size=N, low=0, high=pi/2)\n", "theta = np.random.uniform(size=N, low=0, high=pi/2)\n",
"2/(sum(x+np.sin(theta))>1/N)" "2/(sum((x+np.sin(theta))>1)/N)"
] ]
}, },
{ {
...@@ -109,6 +109,33 @@ ...@@ -109,6 +109,33 @@
"ax.set_aspect('equal')" "ax.set_aspect('equal')"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is then straightforward to obtain a (not really good) approximation to $\\pi$ by counting how many times, on average, $X^2+Y^2$ is smaller than 1:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.112"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4*np.mean(accept)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
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