This Python script allows the user to simulate the probability of getting exactly d
and l
, and lastly verify the mathematical expressions using the interactive file I created in Desmos under Additional resources.
The condition for this Python script is that
Ensure you have the following Python libraries installed:
matplotlib
numpy
Open the script in a Python environment.
Modify the no_of_needles
, l
, and d
parameters as needed.
Run the script to visualize the needle dropping simulation and the resulting histogram of crossings.
no_of_needles
: Number of needles to drop during the simulation.
l
: Length of the needle.
d
: Distance between parallel lines.
- Parallel Lines Setup: Lines are drawn parallel at a distance
d
from each other. - Needle dropping loop: Random needles are dropped, and the script calculates the number of crossings for each needle.
- Visualization: The script generates the calculated probabilities which are showcased with a plot, providing insights into the distribution.
The needle is dropped as in the figure above, with a distributed
To derive the probabilities of getting exactly
We initialize the problem by working with a simpler case, and hopefully it will become clearer on how we can extrapolate the result. Firstly study the figure below
We are interested in finding out the probability of getting exactly
Similarly we can deduce that the the maximum angle
It's very easy to extend this argument for a total of
Note that we haven't included the right end in the range of
For calculating the probability of getting
Notice however that if we define
then
becomes a simply telescoping sum, meaning we end up with
I have also created a Desmos environment where I have tried to visualize the integrals for each