You are on page 1of 19

S

A
G

L
A

E
ID O
L
N
A AR
C
V

A
O

A
S

R
P

A
A

T
S

A
2

M
0

,
4

O
M
S

E
T
N
B

IV

IT

WHAT IS A MONTE CARLO?


Q: If I gave you an unfair coin, how would you determine its
bias?
A: Flip it several times, find the ratio of heads to tails
What youve done is a Monte Carlo
Not exact, but can get as close as you want (Law of Large
Numbers, stay tuned)

WHAT IS A MONTE CARLO? AN EXAMPLE


In the spirit of the name Monte Carlo, how would you find the probability of getting
a full house with triple aces in Texas Holdem with 3 other players?
1. Calculate it from first principles of probability
2. Deal lots of random games and count the number that gave trip aces and a pair

Pros

Pros

Exact
Rigorous

Simple, easy to understand


Can be done quickly by a
computer

Cons

Cons

Difficult?
Time consuming

Not rigorous (probabilistic)


Not exact (approximate)

OUR MONTE CARLO IDEAL GASSES


How does pressure vary as a function of volume, number of
molecules (N, not n), and temperature in an ideal gas?
1. Calculate it from first principles of
mechanics/thermodynamics (statistical mechanics)
2. Simulate lots of particles moving and interacting
according to the assumptions of kinetic theory and the laws
of physics

ASSUMPTIONS OF KINETIC THEORY


1. Gasses consist of pointlike molecules with negligible volume
but significant mass
2. All molecules have the same mass
3. The number of particles is large (we can use statistics; the
Monte Carlo method is justified)
4. Molecules interact elastically (with each other, and with the
walls of the container)
Elastic = kinetic energy is conserved
5. Molecules are in random motion, the x, y, and z components
of their velocities follow normal distributions

http://quantumfreak.com/

NORMAL DISTRIBUTIONS (BELL CURVE)

There are more particles with velocity near the mean (, average)

Histogram the particle velocities, and they will look like the graph
below

Spread is determined by standard deviation ()

Probability density function (pdf):

Cumulative distribution function (cdf):

When we (randomly) choose the velocity of


our simulated particles, they must follow this
distribution (histogram must look like bell curve)
http://www.itl.nist.gov/div898/handbook/pmc/
section5/pmc51.htm

LAW OF LARGE NUMBERS

Sample mean vs population


mean

As n increases, the sample


mean approaches the
population mean

Aside: Central Limit Theorem:


Regardless of population
distribution, the histogram of
observed sample means follows
a normal distribution

INITIALIZATION

Define physical parameters


chamber size
number of particles
particle mass
temp

Define simulation parameters


length of simulation
size of timestep t

Randomly choose particle positions and velocities


Position: uniform distribution for each component
Velocity: normal distribution (bell curve) for each component: ,

Note: All the information about the state of the system is


entirely contained in the positions and velocities of the particles

INITIALIZATION - CODE
cham ber_size = .05 # m eters
a_tot = 24 * cham ber_size ** 2 # m ^ 2 (6 sides, each squares of side 2*cham ber_size)
num _particles = 100000
particle_m ass = 6.6335e-26 # kg, m ass of argon
tem p = 300 # kelvin
k = 1.3806503e-23 # boltzm ann constant, in m ^ 2 kg s^ -2
particle_pos = [[uniform (-cham ber_size, cham ber_size) for iin range(3)]
for iin range(num _particles)] # m eters
particle_vel= [[norm alvariate(0, sqrt(k*tem p/particle_m ass)) for iin range(3)]
for iin range(num _particles)] # m /s

particle_pos: [[x1, y1, z1],


[x2, y2, z2],
...
[xn, yn, zn]]

particle_vel: [[vx1, vy1, vz1],


[vx2, vy2, vz2],
...
[vxn, vyn, vzn]]
How do I access the x
coordinate of the 84th
particle?
How do I access the z
component of the 4th

SIMULATION: What Happens in t


Seconds?
1. Each particle moves a distance of (vx t) in the x direction,
(vy t) in the y direction, (vz t) in the z direction
Code: particle_pos[i][coord] + = particle_vel[i][coord] * delta_t

xf = xi + (vx, vy, vz)t


xi

SIMULATION: What Happens in t


Seconds?
2. Particles collide with walls, imparting momentum (impulse) to them
Q: What would happen in our simulation?
A: The particle would go through the wall! Fix this:

(xf,
yf)

(xf,
y f)

(xi,
y i)

xwall

xf = xwall (xf
xwall)
= 2*xwall xf
y'f = yf

SIMULATION: What Happens in t


Seconds?
2. Particles collide with walls, imparting momentum (impulse) to
them

Q: What is the momentum imparted to the wall by one


collision?
A: It is equal
(vxfto
, the change in momentum of the particle, ie 2
* m * vx

vyf)

(vxf,
vyf)

(vxi,
vyi)

vxf = -vxf =
-vxi
v'yf = vyf =
vyi

xwall

vx = -2vx
vy = 0

SIMULATION: What Happens in t


Seconds?
2. Particles collide with walls, imparting momentum (impulse)
to them
if particle_pos[i][coord] > cham ber_size:
# put it back in the cham ber
particle_pos[i][coord] = 2 * cham ber_size - particle_pos[i][coord]
# reverse its velocity in this direction
particle_vel[i][coord] = -particle_vel[i][coord]
# add the m om entum im parted to the w allof the cham ber
p_tot + = 2 * particle_m ass * abs(particle_vel[i][coord])

SIMULATION: What Happens in t


Seconds?
2. Particles collide with walls, imparting momentum (impulse)
to them
Furthermore, the sum of momentum imparted to the walls by all
the particles in one timestep is equal to the total impulse on the
walls in that timestep
This total impulse gives us the force on the walls, which gives us
the pressure (P=F/A, and we know the area because we chose
the size of the container!)

# calculate pressure from m om entum


f_tot = p_tot / delta_t
pressure = f_tot / a_tot

KINETIC ENERGY
v(T), Ideal Gas Law

Rearrangements

Combination (sub in kT)

RESULTS
Boyle's Law
4.50E-13
4.00E-13
3.50E-13
3.00E-13
2.50E-13

Pressure (Pa)

P = (4.13E-16)
(1/V)

2.00E-13
1.50E-13
1.00E-13
5.00E-14
0.00E+00
0

200

400

600

800

1000

1200

1/Volume (m^-3)

With num_particles = 100000, temp = 300K,


particle_mass = 3E-30kg
Compare with P = NkT (1/V) NkT = 4.14E-16

RESULTS
Gay-Lussac's Law
8.00E-13
7.00E-13
6.00E-13
5.00E-13

Pressure (Pa)

4.00E-13

P = (1.38E15)T

3.00E-13
2.00E-13
1.00E-13
0.00E+00
50

100

150

200

250

300

350

400

450

500

550

Temperature (K)

With num_particles = 100000, volume = .


001m3, particle_mass = 3E-30kg
Compare with P = (Nk/V)T Nk/V = 1.38E-15

RESULTS
Mass variation
8.00E-13
7.00E-13
6.00E-13
5.00E-13
4.00E-13

Pressure (Pa)

3.00E-13
2.00E-13
1.00E-13
1.00E-29

1.00E-28

1.00E-27

1.00E-26

1.00E-25

1.00E-24

0.00E+00
1.00E-23 1.00E-22

Mass of particles (kg)

With num_particles = 100000, volume = .


001m3, temp = 500K
Compare with P = (Nk/V)T Nk/V = 1.38E-15

THANK YOU!
Thanks for your attention
Please provide feedback, comments, questions, etc:
vyassa.baratham@stonybrook.edu