<h2id="orgc15380a"><spanclass="section-number-2">3</span> Using a surface fraction argument</h2>
<divclass="outline-text-2"id="text-3">
<p>
A method that is easier to understand and does not make use of the <code>sin</code> function is based on the fact that if \(X \approx U(0,1)\) and \(Y \approx U(0,1)\), then \(P[X^2 + Y^2 \leq 1] = \pi/4\) (see <ahref="https://en.wikipedia.org/wiki/Monte_Carlo_method">“Monte Carlo method on Wikipedia”</a>). The following code uses this approach:
A method that is easier to understand and does not make use of the <code>sin</code> function is based on the fact that if \(X \sim U(0,1)\) and \(Y \sim U(0,1)\), then \(P[X^2 + Y^2 \leq 1] = \pi/4\) (see <ahref="https://en.wikipedia.org/wiki/Monte_Carlo_method">“Monte Carlo method” on Wikipedia</a>). The following code uses this approach:
It is then straightforward to obtain a (not really good) approximation to π by counting how many times, on average, \(X^2 + Y^2\) is smaller than 1:
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:
A method that is easier to understand and does not make use of the =sin= function is based on the fact that if $X \approx U(0,1)$ and $Y \approx U(0,1)$, then $P[X^2 + Y^2 \leq 1] = \pi/4$ (see [[https://en.wikipedia.org/wiki/Monte_Carlo_method]["Monte Carlo method on Wikipedia"]]). The following code uses this approach:
A method that is easier to understand and does not make use of the =sin= function is based on the fact that if $X \sim U(0,1)$ and $Y \sim U(0,1)$, then $P[X^2 + Y^2 \leq 1] = \pi/4$ (see [[https://en.wikipedia.org/wiki/Monte_Carlo_method]["Monte Carlo method" on Wikipedia]]). The following code uses this approach: