<jupyter_start><jupyter_text>Ex 1.3 - **Simulate** the Buffon’s experiment (see LSN_Lecture_00, supplementary material):  A needle of length $L$ is thrown at random onto a horizontal plane ruled with straight lines a distance $d$ (must be $d > L$, but do not use $d\gg L$ otherwise $P\ll 1$) apart. The probability $P$ that the needle will intersect one of these lines is: $P = 2L/\pi d$. This could be used to evaluate $\pi$ from throws of the needle: if the needle is thrown down $N_{thr}$ times and is observed to land on a line $N_{hit}$ of those times, we can make an estimate of $\pi$ from$$\pi = \frac{2L}{Pd} = \lim_{N_{thr} \to \infty}\frac{2LN_{thr}}{N_{hit}d}$$Make a picture of the estimation of $\pi$ and its uncertainty (Standard Deviation of the mean) with a large number of *throws* $M$ as a function of the number of blocks, $N$ (see below: Computing statistical uncertainties). If possible, do not use $\pi$ to evaluate $\pi$.<jupyter_code>import matplotlib 
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import figure
from time import time
start = time()
f = np.loadtxt("pies.txt")
x = np.arange(len(f))
x *= 10000
figure(figsize=(8,6), dpi=200)

plt.errorbar(x,f[:,0],yerr=f[:,1])
plt.axhline(3.1415926535, color='red', label="π")
plt.legend(loc="upper right")
plt.xlabel("# throw")
plt.ylabel("<π>")
plt.grid(True)
plt.show()
end = time()

print("Total computing time:", int((end-start)*100)/100., "sec.")<jupyter_output>Total computing time: 0.56 sec.
{'fraction_non_alphanumeric': 0.14390406395736177, 'fraction_numerical': 0.02664890073284477, 'mean_word_length': 4.9603174603174605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '238331', 'license': 'MIT', 'n_tokens_mistral': 537, 'n_tokens_neox': 500, 'n_words': 198, 'path': 'LSN_exercise_01/Ex_1.3/.ipynb_checkpoints/Es1.3-checkpoint.ipynb', 'repo_name': 'LeonardoAlchieri/LSN_exercises', 'size': '1501'}