maths.pi_monte_carlo_estimation¶
Attributes¶
Classes¶
Functions¶
|
Generates an estimate of the mathematical constant PI. |
Module Contents¶
- class maths.pi_monte_carlo_estimation.Point(x: float, y: float)¶
- is_in_unit_circle() bool ¶
True, if the point lies in the unit circle False, otherwise
- classmethod random_unit_square()¶
Generates a point randomly drawn from the unit square [0, 1) x [0, 1).
- x¶
- y¶
- maths.pi_monte_carlo_estimation.estimate_pi(number_of_simulations: int) float ¶
Generates an estimate of the mathematical constant PI. See https://en.wikipedia.org/wiki/Monte_Carlo_method#Overview
The estimate is generated by Monte Carlo simulations. Let U be uniformly drawn from the unit square [0, 1) x [0, 1). The probability that U lies in the unit circle is:
P[U in unit circle] = 1/4 PI
and therefore
PI = 4 * P[U in unit circle]
We can get an estimate of the probability P[U in unit circle]. See https://en.wikipedia.org/wiki/Empirical_probability by:
Draw a point uniformly from the unit square.
- Repeat the first step n times and count the number of points in the unit
circle, which is called m.
An estimate of P[U in unit circle] is m/n
- maths.pi_monte_carlo_estimation.prompt = 'Please enter the desired number of Monte Carlo simulations: '¶