try 3 I think I have it now

parent 767aec72
{ {
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"# On the computation of $\\pi$\n" "# On the computation of $\\pi$\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"## Asking the maths library\n", "## Asking the maths library\n",
"My computer tells me that $\\pi$ is approximately" "My computer tells me that $\\pi$ is approximately"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "code",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"from math import *\n", "from math import *\n",
"print(pi)" "print(pi)"
] ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##Buffon's needle\n",
"Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the **approximation**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"np.random.seed(seed=42)\n",
"N = 10000\n",
"x = np.random.uniform(size=N, low=0, high=1)\n",
"theta = np.random.uniform(size=N, low=0, high=pi/2)\n",
"2/(sum(x+np.sin(theta))>1/N)"
]
} }
], ],
"metadata": { "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