\documentclass[aps,prl,twocolumn,showpacs,superscriptaddress]{revtex4-2}
\usepackage{graphicx}% Include figure files
\begin{document}

\title{Estimation of the constant $\pi$ using a statistical method}
\author{Cemal Yalab{\i}k}
\affiliation{Department of Physics, Bilkent University, Bilkent,
06800, Ankara, Turkey}
\date{\today}
\begin{abstract}
A statistical method was used to estimate the value of the constant $\pi$. An accuracy better than $\pm 0.0002$
was achieved from $10 \times 10^7$ samples.
\end{abstract}
\maketitle

\section{The method}
Random numbers for the $x$ and the $y$ coordinates of a point will be chosen randomly between zero and one:
\[0<x<1\qquad 0<y<1\; .\]
These numbers will be scattered in a total area of $1$. (See Figure \ref{circle}.) 
The area of the circle inside this quadrant is $\pi/4$.
The points will then fall into the circular region with a probability of $\pi/4$.
By counting the points that do fall into the circle and finding their ratio to total number of points
gives a statistical estimate for $\pi/4$.

\begin{figure}[h!]
% The natwidth and natheight values below are the original size of the jpg image.
% If you have problems with *.jpg images, use *.eps images, then you do not have to specify these values. 
%\includegraphics[width=0.3\textwidth,natwidth=371,natheight=352]{Report_fig.jpg}
\includegraphics[width=0.3\textwidth]{Report_fig.jpg}
\caption{\label{circle} The geometry of the setup. Random points are generated in the indicated square
within $0<x,y<1$.}
\end{figure}

\section{The computational results}
$N$ random points were selected, and the those coocrdinates which satisfy the condition
$x^2+y^2<1$ were counted. The estimate for the number $\pi$ is then 
\begin{equation}
 p=4n/N . \label{pi}
\end{equation}
This procedure was repeated 10 times, thus resulting in 10 values of $p_i$ according to 
Equation \ref{pi}. The average $\overline p$ of these 10 values is the estimate for $\pi$:
\[\overline p = \frac{1}{10}\sum_{i=1}^{10}p_i \qquad \qquad \overline {p^2} = \frac{1}{10}\sum_{i=1}^{10}p_i^2 \]
The standard deviation $\sigma$ of these 10 values were then used as a measure of the possible
error in the result:
\[ \sigma^2 = \frac{1}{9} \left ( \overline {p^2}-{\overline p}^2\right ) . \] 

\begin{table}
\begin{tabular}{|c|l|l|}
\hline 
$N$ & $\overline p$ & $\sigma/\sqrt{9}$ \\
\hline \hline 
$10^2$ &  $3.1\overline 2$ & 0.045 \\
$10^3$ &  $3.1\overline{38}$ & 0.011  \\
$10^4$ &  $3.14\overline{68}$ & 0.0058  \\
$10^5$ &  $3.14\overline{1} $& 0.0013  \\
$10^6$ &  $3.141\overline{8}$ & 0.00062 \\
$10^7$ &  $3.141\overline{7}$ & 0.00015 \\
\hline
\end{tabular}
\caption{The values for number of points $N$, the estimate $\overline p$, and the reliability of the result, $\sigma/\sqrt{9}$.
(The bar over the digits of $\overline p$ indicate uncertain values.)} \label{data_table}
\end{table}

Table \ref{data_table} shows the estimate for $\pi$ and possible error versus number $N$. 
A result of  $\pi \sim 3.141\overline{7}$ with an accuracy (70\% confidence) of $\pm 0.00015$ was obtained when using $10N=10^8$ points. 

\section{Appendix - the computer code}

The computer code was implemented in {\em Python}:
{\tiny
\begin{verbatim}
 
import numpy as np
from random import *

# Number of samples will be 100, 1000, ...
n=10;
for nn in range(1,5):
  n=10*n;

  sum=0;
  ssum=0;

# The procedure will be repeated 10 times 
  for ii in range(1,10):
    count=0;

    for i in range(1,n):
# generate the coordinates
      x=random();
      y=random();

# check if inside the circle:
      if x*x + y*y < 1 : 
        count=count+1;

# estimate for pi:
    p = 4*count/n;
# find average p:
    sum = sum  + p;
# find average of p*p
    ssum= ssum + p*p;
 
  aver = sum/10;
  sigma = np.sqrt(( ssum/10 -aver*aver )/9);
# write the result
  print ("For n , aver, sigma")
  print ( n, aver , sigma ) 

\end{verbatim}
}

\end{document}
