0% found this document useful (0 votes)
175 views19 pages

Monte Carlo Methods

This document discusses Monte Carlo methods and radioactive decay simulation using a Monte Carlo approach. It provides details on: - Generating pseudo-random numbers on computers using algorithms with prime numbers and modulo arithmetic. - Simulating radioactive decay by giving each nucleus a random probability of decaying at each time step, and decreasing/increasing parent/daughter nuclei counts accordingly. - An example C++ program that takes input parameters, initializes random number generation, and runs the radioactive decay simulation over multiple time steps, outputting parent, daughter, and granddaughter nuclei counts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views19 pages

Monte Carlo Methods

This document discusses Monte Carlo methods and radioactive decay simulation using a Monte Carlo approach. It provides details on: - Generating pseudo-random numbers on computers using algorithms with prime numbers and modulo arithmetic. - Simulating radioactive decay by giving each nucleus a random probability of decaying at each time step, and decreasing/increasing parent/daughter nuclei counts accordingly. - An example C++ program that takes input parameters, initializes random number generation, and runs the radioactive decay simulation over multiple time steps, outputting parent, daughter, and granddaughter nuclei counts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Monte Carlo Methods

• 1953, Nicolaus Metropolis


• Monte Carlo method refers to any method that makes use of random
numbers
• Simulation of natural phenomena
• Simulation of experimental apparatus
• Numerical analysis
Random Numbers
• What is random number ? Is 3 ?
• There is no such thing as single random number
• Random number
• A set of numbers that have nothing to do with the other numbers in the
sequence
• In a uniform distribution of random numbers in the range [0,1] , every
number has the same chance of turning up.
• 0.00001 is just as likely as 0.5000
Random v. Pseudo-random
• Random numbers have no defined sequence or formulation. Thus, for
any n random numbers, each appears with equal probability.
• If we restrict ourselves to the set of 32-bit integers, then our numbers
will start to repeat after some very large n. The numbers thus clump
within this range and around these integers.
• Due to this limitation, computer algorithms are restricted to
generating what we call pseudo-random numbers.
How to generate random numbers ?
• Use some chaotic system (Balls in a barrel – Lotto)
• Use a process that is inherently random
• Radioactive decay
• Thermal noise
• Cosmic ray arrival
• Tables of a few million random numbers
• Hooking up a random machine to a computer.
Pseudo Random number generators
• The closest random number generator that can be obtained by computer
algorithm.
• Usually a uniform distribution in the range [0,1]
• Most pseudo random number generators have two things in common
• The use of large prime numbers
• The use of modulo arithmetic
• Algorithm generates integers between 0 and M, map to zero and one.

X n I n / M
An early example (John Von
Neumann,1946)
• To generate 10 digits of integer
• Start with one of 10 digits integers
• Square it and take middle 10 digits from answer
• Example: 57721566492 = 33317792380594909291
• The sequence appears to be random, but each number is determined from the
previous  not random.
• Serious problem : Small numbers (0 or 1) are lumped together, it can get itself to
a short loop. For example:
• 61002 = 37210000
• 21002 = 04410000
• 41002 = 16810000
• 51002 = 65610000
Properties of Pseudorandom
Numbers
• Uncorrelated Sequences
• The sequences of random numbers should be serially uncorrelated
• Long Period
• The generator should be of long period (ideally, the generator should not repeat;
practically, the repetition should occur only after the generation of a very large set of
random numbers).
• Uniformity
• The sequence of random numbers should be uniform, and unbiased. That is, equal
fractions of random numbers should fall into equal ``areas'' in space. Eg. if random
numbers on [0,1) are to be generated, it would be poor practice were more than half to
fall into [0, 0.1), presuming the sample size is sufficiently large.
• Efficiency
• The generator should be efficient. Low overhead for massively parallel computations.
Initializing with Seeds
• Most of the algorithms have some state that can be initialized. Many
times this is the last generated number (not thread safe).
• You can set this state using the routines initialization methods
• Why would you want to do this?
Initializing with Seeds
• Most of the algorithms have some state that can be initialized. Many
times this is the last generated number (not thread safe).
• You can set this state using the routines initialization methods.
• Why would you want to do this?
1. The default state always generates the same sequence of random numbers.
Not really random at all, particularly for a small set of calls. Solution: Call
the seed method with the lower-order bits of the system clock.
2. You need a deterministic process that is repeatable.
Monte-Carlo Techniques
• Sample Applications
• Integration
• System simulation
• Computer graphics - Rendering.
• Physical phenomena - radiation transport
• Simulation of Bingo game
• Communications - bit error rates
• VLSI designs - tolerance analysis
Radioactive Decay
• Discrete process with each atom having some finite probability of

• Sample : N nuclei which decay at a rate 𝜆 .


decay

• Decay rate :

• Probability P that a nucleus undergoes radioactive decay in time 𝑑𝑡


• Undecayed Nuclei at time t :
The Monte Carlo Approach
In a given time step, each nucleus is given the opportunity to decay with probability
p. So for a given nucleus, we choose a random number in the range 0 to 1. If the
number is less than the probability p, then it decays. Here decay simply means that
the total number of nuclei is decrease by one. Note that this happens every time
step .
Pseudo code

2. Input decay constant 𝜆,


• 1. Input initial number of parent nuclei , and daughter nuclei ,

3. Input the number of time steps 𝑛,


4. Input time step 𝑑𝑡,


5. Loop: t from 0 to 𝑛,


• 6. Loop: i from 0 to ,

8. If R< 𝜆∗𝑑𝑡 then =−1 & =+1


• 7. Generate a random number R,

10. Output , and 𝑁𝑔𝑑(in case daughter nuclei also decay) to a file,
• 9. In case daughter nuclei also decay add steps 5 to 8 for ,

• 11. Plot , and , each vs time for all t.
Problem
• Given a sample of 10000 radioactive nuclei each of which decays at rate p per
second, what is the number of parent & daughter nuclei in the sample after an
interval of 5 s, for first 20 s, if λ=0.02?
• Also calculate the number of nuclei, if the daughter nuclei also decay with λ=0.03.
Source #include<iostream>
Code #include<cmath>
#include<fstream>
using namespace std;
ofstream output("out.dat");
class RDCY
{
Class int i,p,d,gd,n;
Member functions float dcp,dcd,h,t,a,b,num,ran,l;
public:
Member variables float Rnd()
{
a=l*99;
b=a/10000;
num=int(b);
ran=b-num;
l=ran*10000;
return ran;
}
void getdata();
void cal();
};
void RDCY::getdata()
{
cout<<"enter the seed value"<<endl;
cin>>l;
cout<<"enter the no. of parent nuclei"<<endl;
Input Data through cin>>p;
cout<<"enter the no. of daughter nuclei"<<endl;
console cin>>d;
gd=0; //initial number of granddaughter nuclei
cout<<"enter the decay constant for parent nuclei"<<endl;
cin>>dcp;
cout<<"enter the decay constant for daughter nuclei"<<endl;
cin>>dcd;
cout<<"enter the time step"<<endl;
cin>>h;
t=0;
cout<<"enter the no. of time steps"<<endl;
cin>>n;
}
void RDCY::cal()
{
for(t=0;t<n;t=t+h)
{
output<<t<<"\t"<<p<<"\t"<<d<<"\t"<<gd<<endl;
for(int i=0;i<p;i++)
{
float x=Rnd();
Calculation of if(x<=dcp)
{
Radioactive Decay p=p-1;
d=d+1;
}
}
for(int i=0;i<d;i++)
{
float x=Rnd();
if(x<=dcd)
{
d=d-1;
gd=gd+1;
}
}
}
}
Function calling int main()
{
class RDCY R;
R.getdata();
R.cal();
return 0;
}
Output

You might also like