Anda di halaman 1dari 4

Monte Carlo estimations of e

Pirooz Mohazzabi Citation: Am. J. Phys. 66, 138 (1998); doi: 10.1119/1.18831 View online: http://dx.doi.org/10.1119/1.18831 View Table of Contents: http://ajp.aapt.org/resource/1/AJPIAS/v66/i2 Published by the American Association of Physics Teachers

Additional information on Am. J. Phys.


Journal Homepage: http://ajp.aapt.org/ Journal Information: http://ajp.aapt.org/about/about_the_journal Top downloads: http://ajp.aapt.org/most_downloaded Information for Authors: http://ajp.dickinson.edu/Contributors/contGenInfo.html

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

Monte Carlo estimations of e


Pirooz Mohazzabi
Department of Physics, University of Wisconsin-Parkside, Kenosha, Wisconsin 53141

Received 4 April 1997; accepted 2 July 1997 Three physical processes and the corresponding Monte Carlo algorithms are outlined, in which the number e , the base of the natural logarithm, can be obtained. The value of e is estimated in each case, and the three algorithms are compared. 1998 American Association of Physics Teachers.

I. INTRODUCTION The name Monte Carlo was for the rst time applied to a class of mathematical techniques by scientists working on the development of nuclear weapons in Los Alamos in the 1940s.1 The method consists of applications of devices of chance to randomly generate and sample the outcomes of an experiment. One of the oldest documented applications of this technique, suggested by Comte de Buffon2 in 1777 and now known as Buffons needle problem, can be found in many textbooks on probability.35 The experiment proceeds as follows. A needle of length l is thrown randomly onto a horizontal plane ruled with straight parallel lines a distance d ( d l ) apart. Buffon showed that the probability, p , of a needle intersecting a line is given by p 2l . d 1

called a derangement of the objects. It can be shown that the number of derangements of N objects is given by8,9 N d N !

1 1 1 1 1 N . 2! 3! 4! N!

He also carried out the actual needle experiment. Some years later, Laplace suggested that this technique should be used to evaluate .6 More historical background can be found in Refs. 1 and 5. Another simple Monte Carlo method for the estimation of is as follows.1 Consider a square and its inscribed circle. If we place a large number of points randomly inside the square, some will fall within the circle and some do not. Since the ratio of the area of the circle to that of the square is /4, four times the ratio of the points that fall inside the circle to the total number of points will give an estimate of . Another naturally occurring irrational number in mathematics that is perhaps as interesting as , is the base of the natural logarithm, e . Monte Carlo estimation of this number, however, has not received much attention, even though e has been used in the theory of probability for a long time.7 It seemed intriguing therefore to nd algorithms for estimating e using Monte Carlo simulations. Outlined in this article are three Monte Carlo algorithms for the estimation of e , along with actual values obtained through computer simulations. The three algorithms are then compared for reliability and demand on computer resources. It is believed that these techniques will be of interest to students as well as some teachers of mathematics and physics.

Also known as the hat-check problem, the derangement problem has many interesting applications. For example, N people check in N different objects hats. Later, the objects are returned to them randomly. The number of ways that no one ends up getting the right object is N d . The expression in the square brackets in Eq. 2 is a partial sum of the series for e 1 , and it can be shown that it is within 1/( N 1)! of e 1 . 9 Since the total number of permutations is N !, therefore, for reasonably large N , the probability of nding a derangement is e 1 . Apparently, this is the rst time that e has appeared in the theory of probability.10 One can obtain an approximation for e in the following way: A reasonably large number of objects, N , are chosen. The objects are then shufed a large number of times, and each time the result is checked for derangement. The total number of derangements, N d , is recorded. The ratio N / N d gives an estimate of e . III. THE DART METHOD Suppose that we randomly throw N darts at a dart board that has been divided into R equal size regions. In any one throw, the probability that the dart strikes a given region is clearly p 1/R . Being Bernoulli trials, the probability of nding n darts in a given region at the end of the process is given by the binomial distribution,11
n Nn P n CN , np q

where q 1 p , and C N n are the binomial coefcients. Therefore, the probability of nding an empty region is P 0 q N 1 p N. 4 If we can somehow make p equal to 1/N , then this equation will reduce to P 0 1


1 N

II. THE DERANGEMENT METHOD Consider a permutation of N objects 1,2,...,N , in which every member has moved i.e., no object is left in its original place. In other words, we are considering a permutation that has no xed point, P ( i ) i . Such a permutation is
138 Am. J. Phys. 66 2, February 1998

which, for large enough N , estimates e 1 . To this end, we note that for the binomial distribution the mean value of n is given by n Np . We can make the average occupancy of the regions, n , equal to unity by choosing the number of darts equal to the number of regions on the dart board ( N R ). With this condition, Np 1, and Eq. 5 will be true.
1998 American Association of Physics Teachers 138

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

Another version of the above situation is the raisin-bun problem:11 N raisin buns of equal size are baked from a batch of dough into which N raisins have been carefully mixed. Although the number of raisins varies from bun to bun, the average number of raisins per bun is 1. Then the probability that any given bun will contain no raisin will be given by Eq. 5. We also note that for p 1 and N 1, the binomial distribution is approximated by the Poisson distribution,11,12 P n

Table I. Monte Carlo estimations of e 2.718 281... by three different methods and their estimates of the probable error. The total CPU time of the program in each case is also given for comparison. Method Derangement Dart Salt shaker

em
2.7181 0.0004 2.7182 0.0002 2.7183 0.0010

CPU time s 1 969 186 32 896

nn
n!

e n.

number of particles is proportional to the mass of the salt, we have Nn mn , N m 13

n 1, the Poisson distribution reduces to


P n e , n!
1

With the number of darts equal to the number of regions,

which gives P (0) P (1) e 1 . With the above algorithm, an estimate for e can be obtained in the following way: A large number of darts, N , are thrown randomly at a board that has been divided into N equal size regions we assume that all darts land somewhere on the board. Either the number of empty cells, N 0 , or the number of cells with occupancy of one dart, N 1 , is recorded. The ratio N / N 0 or N / N 1 gives an estimate of e .

where m is the initial mass of the salt, and m n is that of the remaining salt after n iterations. One might think that e could be estimated experimentally from another closely related problem, that of the nuclear decay, in which the fraction of remaining unstable nuclei as a function of time is given by13 N e t, N0 14

IV. THE SALT-SHAKER METHOD Consider a horizontal sheet of paper of area A , containing a small hole of area a . A given amount of salt or sand, containing N particles, is shaken onto the paper randomly assuming all particles land somewhere on the paper. Each salt particle has a probability p a / A of going through the hole. Therefore, the number of particles remaining on the paper at the end of the process would be N 1 1 p N . 8 These particles are then collected, and randomly shaken onto the paper again. The number of salt particles that will not go through the hole in the second trial would be N 2 1 p N 1 1 p 2N .
3

where is the probability of decay per unit time known as the decay constant. This process, however, cannot be used to estimate the value of e , because one must rst know the value of for the nuclei under consideration. In order to determine , however, a natural logarithm, which is closely related to e , must be used, leading to a cyclic argument. V. COMPUTER SIMULATIONS The three algorithms described above were used to estimate the value of e by Monte Carlo simulations. All computations were performed on an Intel Pentium 150-MHz processor, using FORTRAN 77 source codes. The results are shown in Table I, along with the total CPU time for each simulation for comparison. The estimate of the probable error in each case is the standard deviation of the mean, m / N , where is the standard deviation of the individual estimates.14,15 In each case, the numerical values of the input parameters are chosen so that a balance is obtained between accuracy of the results and the CPU time. The details of each simulation are given below. A. The derangement method With N 10, the reciprocal of the expression in the square brackets of Eq. 2 reproduces e to six decimal places. Therefore, an ordered array of 10 numbers, x ( i ) i , i 1,2,3,...,10, is chosen. The array is then shufed 105 times, using a random number generator. After each step, the permutation is checked for derangement. The total number of derangements found, N d , is recorded. An estimate for e is obtained by N / N d . An average value and a standard deviation for these estimates are obtained by repeating the experiment 103 times. B. The dart method In the simulation, a dart board is divided into 105 equal size regions or cells. A dart is thrown randomly at the
Pirooz Mohazzabi 139

After the third trial the result would be N 3 (1 p ) N , and so on. Continuing this process, the number of remaining salt particles on the paper after n iterations would be N n 1 p nN , or, equivalently, Nn 1 p n. N 11 10

Now, if we choose the number of iterations to be n 1/p A / a , then we can write Eq. 11 as 1 Nn 1 N n

12

which approaches e 1 as n . Therefore, in such an experiment with a large number of iterations, an estimation for e can be obtained. Note that it is not necessary to actually count the number of salt particles in an experiment. Since the
139 Am. J. Phys., Vol. 66, No. 2, February 1998

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

board, and the cell where it hits is determined by generating an integer random number in the range of 1 to 105 . Clearly, the probability of the dart striking any given cell is 10 5 . A total of N 105 darts are thrown to establish n 1 . At the end of the process, the number of the empty cells, N 0 , is counted. The ratio N / N 0 is an estimate of e . Again, an average value and a standard deviation for these estimates are obtained by repeating the experiment 103 times. The rationale for using N 105 in this simulation is that with this number, Eq. 5 reproduces e to better than 1.36 10 5 or an accuracy of about 0.0005%. C. The salt-shaker method The experiment is simulated starting with 5 104 salt particles. Note that assuming cubic salt particles, 0.5 mm on a side, this corresponds to only 6.25 cm3 of salt. The salt is shaken randomly onto a large piece of horizontal paper, containing a small hole. The ratio of the area of the hole to that of the entire paper is 10 4 . We assume that all salt particles land somewhere on the paper. Each particle is checked for going through the hole, as its probability is simply 10 4 . The number of particles that do not go through the hole, N 1 , is determined, and the simulation is repeated beginning with this number. After the second trial, the number of particles that do not go through the hole, N 2 , is again determined, and so on. This process is iterated 104 times ( n 104 ), and the nal number of salt particles that have survived, N n , is determined. The ratio N / N n is an estimate for e . The entire experiment is repeated 100 times, and an average value and a standard deviation for the estimates of e are obtained. The rationale for using n 104 iterations is that with this number, Eq. 12 approximates e to better than 1.36 10 4 or an accuracy of about 0.005%. Higher iterations call for unreasonably extensive computer resources. VI. COMPARISON OF ALGORITHMS Comparing the values in Table I, we see that among the three algorithms, the dart method is by far the most efcient algorithm, in terms of both reliability judged by standard deviation of the mean and demand on computer resources judged by the CPU time. The least efcient algorithm, on the other hand, is the salt-shaker algorithm, with an estimated error of about ve times that of the dart method, and a CPU time of about 177 times higher. The reason for such a tremendously high difference among the three algorithms is as follows. The dart method involves only one parameter, i.e., the number of darts, N , which needs to be chosen very large to guarantee a reasonable estimate of e . The derangement method, on the other hand, involves two parameters, i.e., the number of objects in the array, N , and the number of permutations or shufings. The former needs to be only moderately large ten in our simulation, but the latter has to be very large to ensure sufcient convergence. This causes the derangement method to be less efcient than the dart method.

Finally, the salt-shaker algorithm involves two parameters, i.e., the number of particles, N , and the number of iterations, n , both of which have to be very large. This causes the computations to be exceedingly slow and, consequently, renders the algorithm very inefcient. VII. CONCLUSION In conclusion we see that the base of the natural logarithm, e , can be estimated by Monte Carlo simulations as described by the three algorithms in this article. There are differences, however, between simulations of e and , arising mainly from the fact that these numbers emerge from two different mathematical contexts; being of geometric origin, while e is of analytic origin and is closely related to the concept of limit. Consequently, unlike simulations of , simulations of e involve a limiting process. Thus, in the salt-shaker method, for example, the simulation estimates the right-hand side of Eq. 12 which, in this case, can also be calculated by multiplication, rather than e itself. As a result of these differences, the above simulational algorithms for the estimation of e are not as appealing as those for the estimation of . Nevertheless, these simulations are presented to demonstrate a connection between mathematics and physical reality, and not to claim invention of elegant Monte Carlo algorithms comparable to, for example, Buffons needle problem. ACKNOWLEDGMENT I would like to thank Professor Thomas A. Fournelle for a discussion of the derangement method, and for sharing with me his estimation of e using MATHEMATICA.
M. H. Kalos and P. A. Whitlock, Monte Carlo Methods Wiley, New York, 1986, Vol. 1, pp. 15. tique morale, in Supple ment a ` G. Comte de Buffon, Essai darithme lHistoire Naturelle de LImprimerie Royale, Paris, 1777, Vol. 4. 3 W. Feller, An Introduction to Probability Theory and Its Applications, Wiley, New York, 1971, Vol. II, 2nd ed., pp. 6162. 4 B. V. Gnedenko, The Theory of Probability, translated from the Russian by B. D. Seckler Chelsea, New York, 1962, pp. 4143. 5 J. V. Uspensky, Introduction to Mathematical Probability McGraw-Hill, New York, 1937, pp. 112115, 251255. 6 s, Marquis Pierre-Simon de Laplace, Theorie Analytique des Probabilite tes de Laplace de LAcade mie des Sciences, Paris, in Oeuvres Comple 1886, Vol. 7, Part 2, pp. 365366. 7 P. R. de Montmort, Essay danalyse sur les jeux de hazard Quillau, Paris, 1708. 8 V. Bryant, Aspects of Combinatorics Cambridge U.P., Cambridge, 1993, p. 47. 9 K. H. Rosen, Discrete Mathematics and Its Applications Random House, New York, 1988, pp. 269272. 10 F. N. David, Games, Gods and Gambling Grifn, London, 1962, p. 146. 11 Y. A. Rozanov, Probability Theory: A Concise Course, translated and edited by R. A. Silverman Dover, New York, 1969, revised ed., pp. 5458. 12 H. Gould and J. Tobochnik, An Introduction to Computer Simulation Methods Addison-Wesley, New York, 1996, 2nd ed., p. 191. 13 F. J. Blatt, Modern Physics McGraw-Hill, New York, 1992, p. 354. 14 Reference 12, pp. 370371. 15 P. R. Bevington and D. K. Robinson, Data Reduction and Error Analysis for the Physical Sciences McGraw-Hill, New York, 1992, 2nd ed., pp. 5556.
1 2

140

Am. J. Phys., Vol. 66, No. 2, February 1998

Pirooz Mohazzabi

140

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

Anda mungkin juga menyukai