Stat Thermal Phys Python
Stat Thermal Phys Python
Using Python
Anders Malthe-Sørenssen1
Dag Kristian Dysthe1
1
Department of Physics, University of Oslo, Norway
This book was developed as a series of lecture notes for the course Fys2160
Statistical and thermal physics at the University of Oslo, Norway. The
motivation for the book project was to develop a text that integrates the
use of computational methods deeply into the exposition, examples and
exercises. In particular, the aim is to demonstrate the whole problem
solution process, from the initial complex physics problem, through
simplified models that have analytical solutions and to more complex and
realistic models that defy analytical approaches, but that can be addressed
using computational models. Our experience is that this approach more
closely reflects the real work processes found in research and industry,
and that the approach make the curriculum more open — there are
more processes and phenomena that can be addressed, and there are
many ways to do that. It also allows students to experience that various
approaches have various advantages and disadvantages.
A particular challenge when introducing programming and computa-
tional methods is to find a reasonable and productive way to include the
computer programs. Here, we have selected a particular programming
language, python, and used this exclusively throughout the book. How-
ever, there are two versions of this book, one using Python and one using
Matlab. Everything but the programs and the associated syntax-specific
comments are the same.
We have also found it useful to include simplifications, analytical and
computational methods in the same worked examples and exercises. This
provides the students with a complete worked example that also can be
v
vi
used as a basis for exploring new phenomena. The code can be found
both in the book and can be downloaded from the book website1 .
All the examples and some of the exercises in the book have been
compiled as iPython notebooks, and you can find and use the notebooks
at the book notebook site2 .
Since the contents of this course is considered an advanced course, the
tradition in most texts is to not include complete worked examples. We
have found this practice unfortunate, since worked examples are powerful
pedagogical tools, and research have shown that going through a worked
example before addressing exercises yourself will improve the learning
outcomes. You will therefore find some worked examples in this book,
and additional sets of worked examples in the worked example site3 .
Statistics is an essential part of statistical physics. We have therfore
included an introductory chapter on statistics. At the University of
Oslo this introduction to statistics served as an important part of the
overall learning outcomes of the bachelor degree, where all physics courses
provide introduction to specific statistical terms. In this text we introduce
basic probability theory, including most common probability densities
and distributions, basic combinatorics, expected values and variance
as well as estimators. We also introduce the concept of Monte Carlo
modelling, both in the basic introduction to statistics, but also as an
important tool to understand physics.
We have selected several computational approaches that are used
throughout the textbooks. We introduce the essentials of Molecular
Dynamics modeling, since this is used to gain insight into the irreversible
nature of systems with many particles and to provide basic estimates
for the properties of real gases, liquids, and solids. We also provide a
general introduction to Monte Carlo methods and use these methods
systematically throughout the text. We start from a general lattice-
based model that is then reused for many different systems. This also
strengthens a central learning outcome — that physics often is about
recognizing how a new model can be mapped onto a well known model
for which we already know the solution. In addition, we also introduce
various algorithmic models, which are stochastic or Monte Carlo type,
but not always following a Metropolis type algorithm. And we will use
continuum methods to address heat and particular transport in diffusion
or flow problems.
1
http://folk.uio.no/malthe/fys2160/index.html
2
http://folk.uio.no/malthe/fys2160/notebooks
3
http://folk.uio.no/malthe/fys2160/workedexamples
vii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.0.1 Thermodynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.0.2 The great success of statistical mechanics . . . . . . . . . . . 4
1.0.3 Integrated numerical methods . . . . . . . . . . . . . . . . . . . . . 4
1.0.4 Molecular dynamics modeling . . . . . . . . . . . . . . . . . . . . . 5
1.0.5 Learning Physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.0.6 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.0.7 Structure of this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.0.8 Key questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
ix
x Contents
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
List of Exercises
xix
xx List of Exercises
1
2 1 Introduction
also allow you to be more precise with both your observations of nature
and in your ability to predict and utlize nature. Thermal physics contains
many of the elements needed to innovate to address some of the key
questions that face us, and the Earth, now: How can we generate, store
and distribute energy efficiently and in environmentally sustainable ways?
How can we generate clean water and air? How can we generate energy
efficient homes, cities and societies?
Thermal physics is the physics of systems of many. It may therefore be
tempting to ask what the limits of thermal physics are. What happens
when we get better at engineering systems that are very, very small. Can
we then escape from some of the limitations of statistical physics? Is
the physics of nano-scale systems fundamentally different from that of
macroscopic systems? Is there a need for new physical concepts on the
meso-scale, on the scale between individual atoms and molecules and the
thermal physics scale of many atoms? These are questions and concepts
that are still under development, as we develop better computational
and experimental tools to address systems with thousands to billions of
atoms.
Many of the key concepts of thermal and statistical physics can also
be applied in completely different fields, but this should be done with
care and caution. If you have a background in statistics you may indeed
recoqnize many of the concepts introduced in this text, such as the strong
similarity between the partition function and the likelihood function.
Indeed, concepts from statistical physics, and particular algorithmic
modeling approaches, are being applied across fields, n areas such as life
science, epidemology, economics, sociology, finance, and marketing. This
illustrates that the concepts you learn in statistical physics are useful and
powerful, and that many of their applications are yet to be discovered.
The goal of this text is to provide you with a first introduction to
key elements of thermal and statistical physics for students with no
background in thermodynamics or statistical physics. The approach of
this book is to start from the microscopic and develop the thermodynamic
concepts from there. This means that we will start from an atomic
picture, similar to what you have already learned to master in your basic
courses in mechanics and quantuum mechanics and move slowly towards
thermodynamics. I believe this coupling between the microscopic and
the macroscopic to be conceptually important, indeed one of the great
achievements of physics, but it is fully possible to apply thermodynamic
principles without understanding the underlying microscopic foundations.
When we have motivated thermodynamics from statistical physics, we will
1 Introduction 3
1.0.1 Thermodynamics
Thermal and statistical physics is the study of macroscopic objects
with the aim of understanding and predicting their behavior from the
microscopic interactions between the particles making up the system.
In our study of thermal physics we will discover new laws that extend
beyond the laws of energy conservation or Newton’s laws that we already
know from mechanics, but these new laws are only valid for systems
with many particles. A wonderful result in statistical physics is that
many collective properties of macroscopic systems do not depend on the
microscopic details. For example, all liquids have common properties
that do not depend on the details of the interatomic interactions of the
atoms or molecules making up the liquid. The behavior is the same if
the liquid is made of metal, glass, water, polymers (macromolecules) or
liquid hydrogen! There are common properties of matter that simply
depends on the statistical behavior of systems of many particles, and
thermal and statistical physics is the study of these properties. Thermal
physics and thermodynamics contain the laws describing macroscopic
objects and statistical physics is the theoretical framework that allows
us to derive the laws of thermodynamics from our understanding of the
underlying microscopic interactions.
In thermodynamics we introduce new physical concepts such as tem-
perature, thermal energy (heat), and heat capacity. We introduce the
concepts needed to discuss thermodynamic processes and thermodynamic
equilibrium. We introduce the basic notions needed to characterize the
equilibrium chemical processes such as free energies and chemical po-
tentials and use these concepts also to discuss phase transitions and
mixtures, including solutions.
Macroscopic objects have their own laws and behaviors which we must
understand, learn, and preferrably develop a theoretical foundation for.
This is the aim of thermodynamics. Thermodynamics can be developed
as an axiomatic system, based on a few basic laws, but it can also be
developed from a microscopic model of a system — using statistical
mechanics.
4 1 Introduction
1.0.6 Prerequisites
An introductory course in thermal and statistical physics typically follows
courses in mechanics, electromagnetism, and quantuum physics. However,
this text does not require any significant knowledge of electromagnetism
— the few concepts needed, such as for electromagnetic waves, will be
1
http://lammps.org
1 Introduction 7
9
10 2 The Arrow of Time
0.015
a 0.01 b
0.005
0
-0.005
-0.01
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0.15
0.1
c
0.05
0.1
0.05
0.1
0.05
0
0 2 4 6 8 10 12 14 16 18 20
Fig. 2.1 The motion of a single ball bouncing on an elastic floor shown in a plot of z(t)
a Illustration of the experiment. b Ball modelled as a point particle. c Ball modelled as
two connected particles.
The total energy in the system has not changed. The motion is con-
servative and the change in energy is negligible. However, we can divide
the energy into two parts, the energy of the center of mass and the
internal energy in the form of motion relative the center of mass and of
internal compression or elongation of the springs. Fig. 2.1c shows the
center-of-mass energy, Ecm and the internal energy ∆E = ETOT − ecm as
a function of time. We see that initially all the energy is the in the center
of mass motion, but after a short while, energy is distributed between
the center of mass motion and the internal energy.
The initial point therefore seems to be a special point, whereas config-
urations further on seems more representative. We are not surprised as
the system bounces a bit up and down as time progresses, but we would
be very surprised if the system suddenly bounced so that all the energy
ended up in the center of mass motion, and no energy was in the internal
motion, corresponding to what would happen if we played a movie of
12 2 The Arrow of Time
z = zeros((N,nstep),float)
vz = zeros((N,nstep),float)
z[:,0] = d*(array(range(N)))/N+z0 # Initial positions
l = d/N # Distance between nodes
for i in range(nstep): # Calculate motion
dz = diff(z[:,i])-l
F = -k*append(0.0,dz) + k*append(dz,0.0) - m*g # Internode forces
F[0] = F[0] - kw*z[0,i]*(z[0,i]<0) # Bottom wall
a = F/m
vz[:,i+1] = vz[:,i] + a*dt
z[:,i+1] = z[:,i] + vz[:,i+1]*dt;
Notice the use of vectorized math to find all the differences zi+1 − zi
at once using ’diff’. The resulting motion is shown in Fig. 2.1c.
0.95
0.9
0
0.85
z /z
0.8
0.75
0.7
0 0.5 1 1.5 2 2.5
t /T
Let us see how much insight we can gain from the atomic hypothesis
and the motion of all the atoms in a system. Given the precise motion
of all the atoms, we should be able to understand the behavior of the
macroscopic system. However, as we shall see, it turns out not to be that
simple. Description or direct calculation does not always provide insights
by themselves. But we may be able to build understanding based on
description and calculation.
Here, we use a molecular dynamics simulation program to find the
motion of a set of atoms and then analyze the motion. You can read
more about these tools in chapter (3).
How do we determine the time development of a system of atoms? This
is a problem in quantum mechanics: The motion and interaction of atoms,
including the full motion of the electrons, needs to be determined from the
basic equations of quantum mechanics. However, it turns out that we can
learn very much without a quantuum mechanical approach. The atomic
hypothesis in itself combined with Newtonian mechanics and a simplified
description of the interactions between atoms provide valuable insights
as well as good predictions of the behavior of macroscopic systems.
2.2 Approach to equilibrium — molecular dynamics 15
How can we find the interactions between atoms? Again, we may use
quantuum mechanics to find the effective potential energy for a system of
many atoms. Here, we will start from a very simple model for atom-atom
interactions: We will assume that the energy only only depends on the
distance between pairs of atoms.
One of the simplest models for atom-atom interactions comes from a
description of the interactions between nobel-gas atoms, but is widely
used to model many types of atomic interactions. There are two main
contributions to the interaction between two noble-gas atoms:
• There is an attractive force due to a dipole-dipole interaction. The
potential for this interaction is proportional to (1/r)6 , where r is the
distance between the atoms. This interaction is called the van der
Waals interaction and we call the corresponding force the van der
Waals force.
• There is a repulsive force which is a QM effect due to the possibility
of overlapping electron orbitals as the two atoms are pushed together.
We use a power-law of the form (1/r)n to represent this interaction.
It is common to choose n = 12, which gives a good approximation to
the behavior of Argon.
The combined model is called the Lennard-Jones potential (see Fig. 2.3):
12 6 !
σ σ
U (r) = 4 − . (2.4)
r r
6
Fig. 2.3 Plot of the
4
Lennard-Jones potential
2
showing the repulsive part
U=00
0
(blue), the attractive van-
-2
der-Waals interaction (red)
-4
and the combined Lennard-
-6
Jones poential (black). 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.4
r=<
(Learn more about molecular dynamics and how to set up and analyze
simulations in Chap. 3).
The initial setup is shown in Fig. 2.4a. After 2000 timesteps (Fig. 2.4b)
the system has expanded to fill almost the whole area, but we can still see
that there are more atoms on the left side and the atoms still appear to
1
http://folk.uio.no/malthe/fys2160/in.gastwosection01.lmp
2.2 Approach to equilibrium — molecular dynamics 17
Fig. 2.4 Snap-shot from VMD of initial configuration of simulation of gas system (left)
and after 2000 timesteps (right).
python -i ~/pizza/src/pizza.py
jj = find(xit<halfsize)
nleft[it] = size(jj)
plot(t,nleft), xlabel(’t’), ylabel(’n’), show()
#end1
np.savetxt(’tmp.d’, (t,Npart[0,:]))
and the resulting plot that shows the number of particle on the left
is shown in Fig. 2.5. Now, this is interesting. We see that the system
clearly moves in a particular direction. But it is also clear that we
need more data to be really sure about what is happening. Let us
run the simulation for 50000 timesteps and replot the data. (Using
in.gastwosection20.lmps8 and nrleft02.py9 ). The resulting plot in Fig. 2.5
now much more convincingly shows what happens: We see that n(t)
converges towards an approximately constant value and then fluctuates
around this value.
250
200
150
n
100
50
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t x 10
4
From this plot it is also clear that time is not fully reversible. It looks
like we might move back and forth a bit in time, but if we go too far
back we clearly end up in a situation that is different – all the atoms
suddenly segrate. This seems unphysical. It is clearly not impossible –
since it did indeed happen and would happen if we were able to run the
system perfectly backwards in time. (You can achieve this numerically
by having a sufficiently small time-step in your simulation). However, it
seems to be unlikely, in the sense that even a tiny change in the positions
or velocities, such as that generated by rounding errors, would mean
8
http://folk.uio.no/malthe/fys2160/in.gastwosection20.lmps
9
http://folk.uio.no/malthe/fys2160/nrleft02.py
20 2 The Arrow of Time
that we would not be able to reverse the simulation. If you take the
50000 timestep simulation and reverse it, you will not get back to the
segregated system. Instead, the system will fluctuate around the average
value with no large excursion.
This arrow of time is central to our understanding of macrosopic
systems. And it is clearly a new law — a law in addition to conservation
of momentum or conservation of energy.
The atomic model directly illustrates the arrow of time, and we can
use molecular dynamics to directly measure the approach towards an
equilibrium situation: From the trajectories of all the atoms we can
measure a macroscopic quantity such as n(t). But we can gain even
more insight into the process by trying the extract the most important
part of the process — the part of the process that really introduced
the arrow of time — and leave out all the unnecessary details. We
do this by introducing a simplified model that only contains the most
important feature of the process — we introduce an algorithmic model
of the process. This method of defining a model which is as simple as
possible is a common method used in statistical physics, which we will
return to many times throughout this book.
How would such as simplified, algorithmic look like? What is the most
important features of the process? It is usually not easy to know what
the most essential feature are, and often you would need to experiment
and test many different model before you arrive at the simplest (or at
least a very simple) model that reproduces the main effects. However,
here we will simply pick the right model immediately, unfairly giving you
the impression that this is simple in practice. It is not.
right side.
22 2 The Arrow of Time
This means that we can formulate a simple rule for how the system
develops in time. At a time t, the state of the system is given by the
positions si (t) of all the N atoms. In the short time interval ∆t from
t to t + ∆t, each atom i has a probability p = R∆t to move from the
box it currently is in and into the other box10 , that it, each atom has a
probability p to change its state si into the opposite state.
discrete algorithm.
100
50
0 500 1000 1500 2000 2500 3000 3500 4000
t
n = zeros(nstep)
n[0] = NN # Initial number on left side
for i in range(1,nstep):
r = rand(1)
if (r<n[i-1]/NN):
n[i] = n[i-1] - 1 # Move atom from left to right
else:
n[i] = n[i-1] + 1 # Move atom from right to left
plot(range(0,nstep),n)
show()
The resulting behaviors for N = 20, 40, 60 and 80 are shown in Fig. 2.7.
We see that the fluctuations becomes smaller when N increases. This
means that the system stays closer to the equilibrium value for n —
corresponding to the average n over long times. The probability for a
large excursion becomes smaller when the number of particles N becomes
larger. This also means that when the number of particles is very small,
it is fully possible to have a fluctuation where all the particles are on the
left side (n = 1), but as N becomes larger, this becomes more and more
unlikely. This illustrates the principle of the physical law we are exploring
here: A behavoir far from the average becomes less and less probable
— not impossible, only improbable — as the number of atoms increase.
The physical laws for macroscopic systems are therefore a consequence of
the many number of atoms in a typical macroscopic system. In a liter of
gas (at room temperature and atmospheric pressure) there are typicall
1023 gas molecules. A very large number. And it is the largeness of this
number that ensures the regularity of the physical laws. With N = 1023
the fluctuations becomes very, very small indeed.
0.4
0.2
0.8 N = 40
0.6
n
0.4
0.2
0.8 N = 60
0.6
n
0.4
0.2
0.8 N = 80
0.6
n
0.4
0.2
0 50 100 150 200 250 300 350 400
t
2.3 Approach to equilibrium — algorithmic model 25
n=N
n(0) = 1/2 (red), n(0) =
0.4
1/2 (green).
0.2
0
0 100 200 300 400 500 600 700 800 900 1000
t
We could call this transition time the memory extent for the system:
The system remembers its initial conditions for some time interval τ0 ,
and after this time, it has reached the equilibrium state. We expect that
the behavior of the system does not depend on the initial state after this
transition time. This means that when the system reaches its equilibrium
state, the behavior does no longer depend on the initial condition — the
behavior is instead general, depending on the properties of the system
when it is in the equilibrium state.
(s1 , s2 , s3 , . . . , sN ) , (2.5)
2.5 Summary 27
2.5 Summary
2.6 Exercises
0.08
0.02
0 2 4 6 8 10 12 14 16 18
t=t0
0.14
0.12
0.1
zcm
0.08
0.06
0.04
0.02
0 2 4 6 8 10 12 14 16 18
t=t0
Exercise 2.2: Time development for gas with two atom types
A system consists of two types of atoms, A and B, in gas form in a
rectangular box. Initially, all the A atoms are on the left side of the
box and all the B atoms are on the right side. Which of the figures in
Fig. 2.10 represent realistic time developments of the system? Explain
your answer.
2.6 Exercises 29
n(t)=N
0.5
atom system. However,
only one of the figures are 01
from a realistic simulation. (b)
n(t)=N
0.5
10
(c)
n(t)=N
0.5
01
(d)
n(t)=N
0.5
0
0 100 200 300 400 500 600 700 800 900 1000
t
2.6.2 Problems
Exercise 2.6: Bouncing point masses
Discuss the difference between one bouncing point mass and a system
consisting of two bouncing point-particles connected by a spring. Calcu-
late the time development for a one-dimensional system and comment
on the behavior.
31
32 3 Getting started with Molecular Dynamics modeling
d
F (r) = − U (r) = 0 , (3.2)
dr
which occurs at
r
F (r) = 24 0 (σ/r)6 − 2 (σ/r)12 = 0 ⇒ = 21/6 . (3.3)
σ
We will use this potential to model the behavior of an Argon system.
However, the Lennard-Jones potential is often used not only as a model
for a noble gas, but as a fundamental model that reproduces behavior that
is representative for systems with many particles. Indeed, Lennard-Jones
models are often used as base building blocks in many interatomic poten-
tials, such as for the interaction between water molecules and methane
and many other systems where the interactions between molecules or
between molecules and atoms is simplified (coarse grained) into a single,
simple potential. Using the Lennard-Jones model you can model 102 to
106 atoms on your laptop and we can model 1010 -1011 atoms on large
supercomputers. However, if you are adventurous you may also model
other systems, such as water, graphene, or complex biological systems
using this or other potentials as we demonstrate in Sect. 3.5
L=4 b
of the cells are marked and
cell(1,2) cell(2,2) cell(3,2) cell(4,2)
indexed for illustration.
b b
L=4 b
This method has very good properties when it comes to energy conserva-
tion, and it does, of course, preserve momentum perfectly.
Using these notations, we can rewrite the equations of motion for the
Lennard-Jones system using the non-dimensional position and time,
r0i = ri /σ and t0 = t/τ :
d2
6 12
= 24 (σ/r ) 2 (σ/r ) (3.9)
X
2
m ri 0 ij − ij r /r
ij ij ,
dt2 j
to become
d2 0 X −6
r = 24 r − 2r −12
r 0
/r 02
. (3.10)
d(t0 )2 i j
ij ij ij ij
Notice that this equation is general. All the specifics of the system is
now part of the characteristic length, time and energy scales σ, τ , and 0 .
For Argon σ = 0.3405µm, and = 1.0318 · 10−2 eV, and for other atoms
you need to find the corresponding parameter values.
v = zeros(N,3);
bvec = [0 0 0; b/2 b/2 0; b/2 0 b/2; 0 b/2 b/2];
ip = 0;
% Generate positions
for ix = 0:L-1
for iy = 0:L-1
for iz = 0:L-1
r0 = b*[ix iy iz]; % Unit cell base position
for k = 1:4
ip = ip + 1; % Add particle
r(ip,:) = r0 + bvec(k,:);
end
end
end
end
% Generate velocities
for i = 1:ip
v(i,:) = v0*randn(1,3);
end
% Output to file
writelammps(’mymdinit.lammpstrj’,L*b,L*b,L*b,r,v);
Notice that we use the vectors bk to describe the four positions relative
to the origin, r0 of each cell:
bvec = [0 0 0; b/2 b/2 0; b/2 0 b/2; 0 b/2 b/2];
...
r0 = b*[ix iy iz]; % Unit cell base position
for k = 1:4
ip = ip + 1; % Add particle
r(ip,:) = r0 + bvec(k,:);
40 3 Getting started with Molecular Dynamics modeling
end
Also notice that we use a variable ip to keep track of the particle index
for the atom we are currently adding to the system. This is simpler than
calculating the particle number each time. That is, we can simply use
ip = ip + 1; % Add particle
to calculate the current particle number each time a new atom is added.
Finally, we add a random velocity vector, with a normal (Gaussian)
distribution of velocities with a standard deviation of v0 using the randm
function. This can be done using a loop or with a single, vectorized
command:
for i = 1:ip
v(i,:) = v0*randn(1,3);
end
#
or
v = v0*randn(ip,3);
where we only have included the first four of 500 atoms. This file can
then be used as a starting point for a simulation. The output from a
simulation will have a similar format, providing the state of the atomic
system which we can then analyze in details.
3.2 Simple implementation of a molecular dynamics simulator 41
There are several efficient packages that solves the equations of motion for
a molecular dynamics simulation. The packages allow us to model a wide
variety of systems, atoms and molecules, and are efficienty implemented
on various computing platforms, making use of modern hardware on
your laptop or desktop or state-of-the-art supercomputing fascilities. We
use a particular tool developed at Sandia National Laboratories called
LAMMPS2 .
mass 1 1.0
velocity all create 2.5 87287
The simulation is run from the command line in a Terminal. Notice that
the file in.myfirstmd must be in your current directory. I suggest creat-
ing a new directory for each simulation, copying the file in.myfirstmd
into the directory and modifying the file to set up your simulation, before
starting the simulation with:
Terminal
Fig. 3.4 (Left) Illustration of the initial hexagonal lattice generated in the simulation.
(Right) Illustration of the final positions of the atoms after 5000 timesteps.
(You can skip this at first reading, and return when you wonder
what the parameters actually do).
# 2d Lennard-Jones gas
This block defines the material properties of the atoms and defines
their initial velocities.
The mass command defines that atoms of type 1 will have a mass
of 1.0 relative to the mass of the Lennard-Jones model. This means
that all atoms have mass 1 in the Lennard-Jones units. This means
that the masses of all the atoms are the same as the mass m used
in the non-dimensionalization of the Lennard-Jones model.
The velocity command generates random velocities (using a
Gaussian distribution) so that the initial temperature for all atom
types in the system is 2.5 in the dimensionless Lennard-Jones units.
The last, strange integer number 87287 is the seed for the random
number generator used to generate the random numbers. As long as
you do not change the seed number you will always generate same
initial distribution of velocities for this simulation.
3.3 Running a molecular dynamics simulation 47
(v, meaning that the simulation box does not change during the
simulation), and constant energy (e). You may be surprised by the
constant energy part. Does the integration algorithm ensure that
the energy is constant. Yes, it does. However, there can be cases
where we want to add energy to a particular part of the system, and
in that case the basic interation algorithm still conserves energy,
but we add additional terms that may change the total energy of
the system.
dump 1 all custom 10 dump.lammpstrj id type x y z vx vy vz
thermo 100
run 5000
The results from the simulations can be analyzed using built-in tools
from LAMMPS. We demonstrate these tools by measuring the number
of particle on the left side of the box as a function of time, by extracting
that data from the simulation files.
We have illustrated the text-format output files from LAMMPS above.
The file may contain data from may timesteps, t. For each timestep,
there are a few initial lines describing the system, followed by a list of
properties for each atom. We have chosen the custom output form
dump 1 all custom 10 dump.lammpstrj id type x y z vx vy vz
We need the time values ti at each of the timesteps and the number of
time-steps, nt:
50 3 Getting started with Molecular Dynamics modeling
t = data.timestep;
nt = length(t);
The size of the simulation box is stored in the variable box, and we store
Lx /2 in the variable halfsize:
box = data.x_bound;
halfsize = 0.5*box(:,2);
Now, we loop through all the timesteps. For each timestep we extract
all the x-positions for all the atoms in a list xit. Next, we find a list
of all the atoms that are on the left side, that is, all the atoms with
an x-position smaller than Lx /2. This is done by the find command.
Finally, we count how many elements are in this list. This is the number
of atoms that are on the left side of the box. We store this number in the
array nleft for this timestep, and reloop to address the next timestep:
for it = 1:nt
xit = data.atom_data(:,3,it);
jj = find(xit<halfsize(it));
nleft(it) = length(jj);
end
in your terminal. The you are ready to analyze data from the simulation.
First, we read data from all the timesteps into Python:
from pylab import *
data = dump("dump.lammpstrj") # Read all timesteps
We need the time values ti at each of the timesteps and the number of
time-steps, nt:
t = data.time()
nt = size(t)
The size of the simulation box is found in the variable box, and we store
Lx /2 in the variable halfsize:
tmp_time,box,atoms,bonds,tris,lines = data.viz(0)
halfsize = 0.5*box[3] # Box size in x-dir
Now, we loop through all the timesteps. For each timestep we extract
all the x-positions for all the atoms in a list xit. Next, we find a list
of all the atoms that are on the left side, that is, all the atoms with
an x-position smaller than Lx /2. This is done by the find command.
Finally, we count how many elements are in this list. This is the number
of atoms that are on the left side of the box. We store this number in the
array nleft for this timestep, and reloop to address the next timestep:
#Get information about simulation box
tmp_time,box,atoms,bonds,tris,lines = data.viz(0)
halfsize = 0.5*box[3] # Box size in x-dir
for it in range(nt):
xit = array(data.vecs(it,"x"))
jj = find(xit<halfsize)
nleft[it] = size(jj)
52 3 Getting started with Molecular Dynamics modeling
3.4.3 Results
The resulting plot is shown in fig. 3.5. If you wonder why the number of
atoms on the left is varying, how it is varying, and how to describe how
it is varying — this indeed in the topic of this book so just read on!
3.5.1 Coarsening
Out first example is an extension of the first two-dimensional simulation
you performed above. What happens if we start the system with a
homogeneous distribution of atoms, but with a low initial energy? In
addition, we keep the average kinetic energy in the system approximately
constant. (This corresponds, as you will learn later, approximately to
keeping the temperature in the system constant):
units lj
dimension 2
boundary p p p
atom_style atomic
mass 1 1.0
velocity all create 0.05 87287
The resulting behavior shown in Fig. 3.6 is a phase separation: The system
separates into a liquid and a gas phase, demonstrating a phenomenon
called spinoidal decomposition. We will discuss the behavior of such
systems using both molecular dynamics models and algorithmic models
later.
Fig. 3.6 Snapshots from a simulation of a Lennard-Jones liquid, with a low initial density.
A slowening coarsening is observed.
54 3 Getting started with Molecular Dynamics modeling
3.7 Exercises
3.7.1 Problems
Exercise 3.1: Evolution of density
We will here study a 10 × 10 × 10 system of Argon atoms, as done above.
Initiate the system with all particles in the left 1/3 of the system. We
call the number of particles in the left, center and middle thirds of the
system n1 (t), n2 (t), and n3 (t) respectively.
a) How do you expect n1 , n2 , and n3 to develop in time?
b) Measure n1 (t), n2 (t), and n3 (t) and compare with your predictions.
3.7 Exercises 55
Abstract This chapter will introduce you to some of the most common
and useful tools from statistics, tools that you will need throughout
your career. We will learn about statistics motivated by an introductory
example — trying to understand the data you generated by running
a molecular dynamics simulations. This is a good starting point, since
statistics is about describing real data. The data from a realistic molecular
dynamics simulation can be quite overwhelming. The data-sets become
extremely big, so we need effective tools to pick out the most important
information. Here, we introduce the concept of probabilities, the basic
properties of probabilities, such as the rule of addition and the rule of
multiplication. We introduce probability distributions and densities. We
introduce the expected value and the variance and their estimators, the
average and the standard deviation. We introduce the biomial, normal and
exponential distribution. We demonstrate that the distribution of a sum
of independent variables usually are normally distributed, independently
of the details of the distribution of each event in the sum. Finally, we
use these tools to develop a simple theory for the number of particles on
the left side of a gas.
Statistics provides us with the tools to describe real data, whereas
probability theory provides us with the theoretical underpinning for
statistics. Here, we will start with a practical approach to probability
theory, based on the idea of frequencies of event, and use this to develop
the fundamental laws of probabilities. This approach suits a physicists
approach well and is also the most direct approach from a computational
perspective. Again, we will introduce both theory and the computational
57
58 4 Probability and Statistics
tools needed to test the theory and make accurate measurements also
for large data sets.
Probability theory is a classic field that has occupied many of the
great mathematicians and physicists throughout history. It has been
developed along with gambling, but this is just an unfortunate association.
Probability theory is the tool we need to address a world of real data
and unknown processes, and the tool we need to describe the behavior
of systems with many particles, where the physical laws no longer are
absolute, but only represent the overwhelmingly most probable outcome
of an experiment or an observation. However, we will start our venture
into statistical and probability motivated by observations and real data
— in our case the data from measuring the number of atoms on the left
side of a box filled with a gas.
We then use the script we developed in Sect. 3.4 to extract n(t), the
number of atoms in the left half of the system (x < Lx /2) as a function
of time t:
from pylab import *
data = dump("gasstat01.lammpstrj") # Read output states
t = data.time()
nt = size(t)
nleft = zeros(nt,float) # Store number of particles
# Get information about simulation box
tmp_time,box,atoms,bonds,tris,lines = data.viz(0)
halfsize = 0.5*box[3] # Box size in x-dir
for it in range(nt):
xit = array(data.vecs(it,"x"))
jj = find(xit<halfsize)
numx = size(jj)
nleft[it] = numx
plot(t,nleft), xlabel(’t’), ylabel(’n’), show()
np.savetxt(’ndata.d’,(t,nleft))
How can we understand what this data represents and what it tells
us about the gas? We will develop several measurement techniques to
characterize the data, and we will develop a model that may explain the
data and our analysis of the data. Such a model may not reproduce all
the features of the data exactly, but it should represent the main features
in a good way. What do we mean by that?
60 4 Probability and Statistics
230
220
210
200
n
190
180
170
0 1 2 3 4 5 0 200 400
t #104 N (n)
Fig. 4.1 Plot of the number of atoms on the left half (n) as a function of time (t) for 50000
timesteps for two runs with different random seeds for the initial velocity distribution.
We notice that the data has some randomness to it. If we did another
simulation, but with a different random seed for the initial velocities, we
would expect the behavior to be different — at least not identical — but
also to retain some of the features. This is illustrated in Fig. 4.1, where
two curves n(t) are illustrated. The curves have similar features, but are
clearly not identical.
What general features of n(t) should a model predict or explain? Since
the curves are not identical, our model will clearly not reproduce n(t) in
detail, but instead it should reproduce some of its general properties. For
example, we could characterize n(t) by how often it visits a particular
value of n: We count the number of times, N (x), when there are x atoms
on the left side, that is, how many times n(t) = x in a given time interval.
This is done automatically by a histogram:
histogram(m)
(We will explain this method in detail below). A plot of N (x) is shown
in Fig. 4.1, in the same figure as the data-set. This gives us a first
insight into the frequency of occurrence of the various values of n. And
we immediately observe that not all n-values occur equally frequently:
values close to n = 200 occur more frequently that values further away
from n = 200. Fortunately, there is a whole field of science dedicated to
studying frequencies of occurrence and histograms of frequencies — the
field of probability theory and statistics. This chapter therefore contains
a brief introduction to statistics and probability theory, before we develop
a model for the molecular dynamics data.
4.2 Probabilities 61
4.2 Probabilities
randint(0,6)
(Here, the first argument is the smallest random integer and the second
argument is the largest random integer, and an optional third argument is
the number of outcomes to produce). And we can use the same command
to generate a sequence of 4 such experiments by:
randint(0,6,4)+1
array([1, 4, 4, 2])
print edges
(Notice the range used in order to ensure there are 8 bins of size 1 each).
Here, the edges are the xj values giving the edges of the bins used. We
can find the centers of the bins and plot the results using:
x = (edges[1:]+edges[:-1])/2
print x
4.2 Probabilities 63
[ 1. 2. 3. 4. 5. 6. 7. 8.]
plot(x,Nx)
The resulting plot is shown in Fig. 4.2. We see that the frequencies are
approximately, but not exactly, the same for all the outcomes. How can
we interpret the frequency of occurrence?
0
0 1 2 3 4 5 6 7 8 9
x
F (x)
for M = 10, 100, 1000, and 0.2
10000 throws.
0.15
0.1
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
x
Both these results, and the histogram plots in Fig. 4.3, indicate that the
probability is a constant, the same, for all possible outcomes x. This is
what we would expect from a fair dice. Otherwise, we would know that
the dice preferred a particular outcome, and it would not be fair.
Theretical argument. We can also devise a theoretical argument for the
value of the probability P (x) for a throw of the die. From the definition
of probability, the probability to get i is
Ni
P (i) = , (4.3)
M
where M is the number of throws and i may be 1,2,3,4,5 or 6 — valid
in the limit when M becomes large. From this definition we see that
probabilities are normalized:
P
Ni M
P (i) = = =1, (4.4)
X
i
i
M M
when any two outcomes i cannot occur at the same time and the sum is
over all possible outcomes.
We can use this property to calculate the probability to throw a 1.
This follows from two characteristics of the experiments. First, the dice
66 4 Probability and Statistics
is fair, which means that P (i) are the same for all i, P (i) = const = p.
Second, we use the normalization condition:
6 6 6
1
P (i) = P =p =p·6=1 ⇒ p= (4.6)
X X X
,
i=1 i=1 i=1
6
This example uses a standard set of tricks that you may want to remember:
If all outcomes are equally probable we can assume they all have the
same probability p, and the probabilities are normalized.
We can also illustrate another basic principle of probabilities that also
serves as a useful trick: The probability of something not happening can
be found from the normalization condition. For example, what is the
probability of not throwing a one in a single throw?
Here, we use a trick and split all possible outcomes into P (one) and
P (not one). Since one of these two outcomes must occur, they must be
normalized, so that
where we know that P (one) = p = 1/6. We can therefore find P (not one)
from
1 5
P (not one) = 1 − P (one) = 1 − p = 1 − = , (4.8)
6 6
P (x) = 1 , (4.9)
X
when any two outcomes x cannot occur at the same time and the sum
is over all possible outcomes x. This is called the normalization
condition of probabilities.
4.2 Probabilities 67
This can be proven from the frequency definition and that the total
number of observations, x N (x) must be the same as the total number
P
of experiments, M :
X N (x) 1 X M
P (x) = = N (x) = =1. (4.10)
X
x x M M x M
Where the last term is zero if A and B are independent, because in that
case they cannot both occur at the same time.
We could call the event that we get a 1 in the first throw A and the event
that we get a 6 in the second throw B. We can then write the probability
for both to occur as P (A and B). This is usually written at P (A ∩ B),
using the intersection sign ∩ because the outcome is the intersection of
A and B, the set of outcomes that include both A and B.
Numerical approach. First, we estimate the probability for (A and B)
numerically: We draw two random numbers, n1 and n2 , many times, and
count how many times, N , we get a n1 = 1 and n2 = 6 at the same time.
First, we generate the numbers n1 and n2 :
n1 = randint(0,6,1000)+1
n2 = randint(0,6,1000)+1
We can find all the values that are equal to 1 or 6 using the equal to
operator
4.2 Probabilities 69
i1 = 1*(n1==1)
i2 = 1*(n2==6)
Where we have multiplied with one to ensure the result is an integer and
not True/False. Then we find how many times n1 = 1 and n2 = 1 at
the same time by summing i1 and i2. Where this sum is equal to 2,
both n1 = 1 and n2 = 6. We then simply have to count how many times
the sum is equal to 2 to find N , the number of times n1 = 1 and n2 = 6
at the same time, and the frequency, F = N/M , of this:
m = 1*(i1+i2)==2
N = sum(m)
F = N/1000.0
print p
0.034
i=1
throw, and only 1 of these give a 1. That is, the probability to get a 1
in the first throw is p1 = 1/6. Then, in the second throw, there are six
possible outcomes, but only one of them give a 6. Thus the probability
to get a 6 in the second throw is p2 = 1/6. What is the probability to
get both, that is a 1 in the first throw and a 6 in the second throw. The
total number of outcomes is 6 × 6 and the number of outcomes that give
n1 = 1 and n2 = 6 is 1 × 1. Hence, the probability for both is
1×1 11
p= = = p1 p2 . (4.16)
6×6 66
This indicates that the probability for (A and B) is the product of the
probability for each of the events — given that the events cannot occur
at the same time. (If they could occur at the same time, that is, that
they are not independent, then we could not find the total number of
outcomes by multiplying the number of outcomes in throw 1 and the
number of outcomes in throw 2).
Rule of multiplication. This rule is indeed a general law in statistics,
which we call the rule of multiplication:
We have now found that we can describe a random process by the proba-
bility for a given outcome. However, there are even simpler descriptions
that can be measured directly from the sequence of measurements, the
average and the standard deviation:
4.3.1 Average
For a sequence of outcomes ni , i = 1, . . . , M , the average of the
outcome is defined as the arithmetic average, n̄, of the outcomes:
M
1 X
n̄ = ni , (4.18)
M i=1
i=1
M x M x M x
where we have introduced the notation E(N ) for this asymptotic value
of the average. This is indeed what we will use as the definition of the
expected value:
The best way to estimate the expected value is to use the average as an
estimator for the expected value. It can be shown that the average may
be considered a best possible estimator for the expected value — using
a specific definition of the word best. (You will learn more about what
characterizes good estimators and how to find them in basic courses in
statistics, and in a textbook such as ).
We can prove this using the definition of the expected value in (4.21):
y x
x x
where the sum is over all the measurements M . For example, we can use
python to estimate the average of the sequence of die throws found in
Sect. 4.2.5 using using the formula in (4.27):
myavg = sum(m)/len(m)
print myavg
3.5044
3.5044
Notice that this estimated value is close, but not exactly equal to, the
theoretical value.
x x x
| {z }
=E(N )
x
| {z }
=1
Ok, so this did not work, since the result is always zero. Instead, we may
use the absolute value of the deviation:
This does not become zero. However, it is more usual to characterize the
deviation by the expected value of the square of the deviation:
E (N − E(N ))2 . (4.31)
4.3 Expected value and Variance 75
For a random variable with zero expected value, the deviation and the
variance is the same.
hN 2 i − (hN i)2
6 6
!2
= P (i)i − P (i)i
X X
2
i=1 i=1
(4.36)
1 7
2
= (12 + 22 + 32 + 42 + 52 + 62 ) −
6 2
91 49 35
= − = ,
6 4 12
This is again an exact result. We can estimate the standard deviation
directly from the 10000 dice throws directly using the formula in (4.32):
myavg = average(m)
mystd = sqrt(sum(m*m)/(len(m)-1.0)-myavg*myavg)
print mystd
1.7072142923487961
1.7072142923487961
Now, let us use what we have learned so far to develop a theory that
can describe the probability P (n) to observe a particular value n in the
molecular dynamics simulation of the gas/liquid system.
hand half, since the system is symmetric and we have no reason to prefer
the left to the right side. Hence we would expect there only to be two
possible outcomes for n, n = 0 and n = 1 with equal probability. This is
just like flipping a coin (throwing a 2-sided dice). From our discussions
above, we know that the probability for a fair coin to show the number n
corresponds to the probability of a fair, two-sided die to show the number
n:
P (n) = 1/2, n = 0, 1 , (4.37)
where we have already seen that this theory fits well with a numerical
simulation. However, this model is too simple to predict n(t) for a many-
particle gas. Let us instead address a two-atom system.
[[0 1]
[1 0]
[0 0]
78 4 Probability and Statistics
[1 1]
[1 0]]
[1 1 0 2 1]
tosses: n = n1 + n2 , where
Ni
3000
n1 = 0, 1 and n2 = 0, 1. 2000
1000
0
0 1 2
i
g(n) of (n1 , n2 )-states that give the same n-value, multiplied with the
probability, p, per state, where p = 1/M , and M = 22 is the total number
of (n1 , n2 )-states.
1
P (n) = g(n)p = M g(n) , (4.38)
2
where the multiplicity g(n) is read from the table above, and are
tabulated in the following table:
n g(n) P (n)
0 1 1/4
1 2 2/4
2 1 1/4
We can compare these results directly with the histogram in Fig. 4.4.
The histogram records how many experiments, Nn , that resulted in
outcome n, when the total number of experiments were M = 10000.
The probability P (n) is approximately equal to Nn /M , hence we must
compare Nn = P (n) M with the values in the histogram, as done with
the following code:
nn = array([0 1 2])
Pn = array([0.25, 0.5, 0.25])
Nn = Pn*M
plot(nn,Nn)
1 N! 1
!
N
P (n) = = . (4.40)
n 2N n!(N − n)! 2N
show()
hist(n,bins=20)
show()
The resulting histograms are shown in Fig. 4.5. Notice that the number
of counts in each bin goes down when the number of bins is increased.
These histograms only measure the number of outcomes in each bin,
where the bin may span over a size ∆n corresponding to many n-values.
However, we would like to estimate P (n) as Nn /M , where Nn is the
number of outcomes that are equal to n. This can be done either by
ensuring that the bin width is n, or we need to divide by the bin size
in order to find the estimate for the probability P (n) across the bin:
P (n) ' N (n, n + ∆n)/(M ∆n). Why do we need to divide by ∆n? If we
count N (n, n + ∆n), we have really counted
(4.43)
' P (n) + P (n + 1) + P (n + 2) + . . . + P (n + ∆n)
(4.44)
1
= ∆n (P (n) + P (n + 1) + P (n + 2) + . . . + P (n + ∆n))
∆n
(4.45)
= ∆n P (n + ∆n/2) . (4.46)
240 1500
220
1000
N (n )
n (t) 200
500
180
160 0
0 1 2 3 4 5 160 180 200 220 240
t 4 n
x 10
240
220
n (t)
200
180
160
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t x 10
5
2000 2000
N (n )
N (n )
1000 1000
0 0
160 180 200 220 240 160 180 200 220 240
n n
Fig. 4.5 Plot of n(t) from the simulation and ni from 5001 random microstates from
50,000 timesteps (top left) and 500,000 timesteps (middle). (Top right) Histogram of
n(t) for 50,000 timesteps with 10 and 20 bins. (Bottom left) Histogram of n(t) for 50,000
timesteps (blue) and for a simulation with 5001 random outcomes using the binomial
model (red). (Bottom right) Histogram of n(t) for 500,000 timesteps (blue) and for a
simulation with 5001 random outcomes using the binomial model (red).
We generate 5001 such values randomly and compare the two histograms:
ni = randint(0,2,(5001,400))
nt = sum(ni,axis=1)
84 4 Probability and Statistics
The resulting plot is shown in Fig. 4.5. Hmmm. This did not look
like a very good fit. What has gone wrong? It may be that the initial
correlations in the data were too strong, so that not all the atoms really
are active and can change places between each measurement from the
simulation. Let us increase the time interval between measurements of ni ,
but keep the number of observations the same. We rerun with the input
file in.gasstatistics029 resulting in gasstat02.lammpstrj10 , producing the
data file ndata02.d11 , which we plot using
from pylab import *
t,n=loadtxt(’ndata02.d’);
ni = floor(rand(5001,400)*2)
nt = sum(ni,axis=1)
hist(nt), hist(n), show()
The resulting sequence n(t) of n-values is shown in Fig. 4.5. We see that
the correlations in the n(t) signal are now less prominent, although there
are still some correlations present. However, the histograms in the bottom
right part of Fig. 4.5 now show much better correspondence, indicating
that the theory we have developed provides a good explanation of the
behavior. Indeed, the correspondence between observations and theory
is surprisingly good given the simplicity of the model. We may therefore
conclude that the model captures the most important features of the
behavior of n(t).
Comparison with theory — calculated probabilities. Now, let us also
compare directly with the probabilities we have calculated for n:
N!
P (n) = 2−N , (4.48)
n!(N − n)!
We use the scipy.stats.binom.pmf function to calculate P (n) as a
function of n. (This uses the scipy12 package). In order to compare
directly with the histogram, we notice that P (n) = Nn /M , and therefore
Nn = M P (n). We also choose many bins (301) to ensure that each value
of n falls into one and only one bin, so that P (n) = Nn /M , where Nn is
the number of outcomes in the bin that includes n. This is done by the
following script:
9
http://folk.uio.no/malthe/fys2160/in.gasstatistics02
10
http://folk.uio.no/malthe/fys2160/gasstat02.lammpstrj
11
http://folk.uio.no/malthe/fys2160/ndata02.d
12
http://www.scipy.org
4.5 The binomial distriubtion 85
The resulting plot is shown in Fig. 4.6. The correspondence is not spec-
tacular, but decent, showing that the theory we have developed gives
a reasonably good description of n(t) from the molecular dynamics
simulations.
250
200
150
N (n )
100
50
0
160 170 180 190 200 210 220 230 240
n
Fig. 4.6 Plot of the histogram for n(t) from the simulation and ni from a binomial
distribution.
The binomial distribution fits well to the observed data for the molecular
simulation. Indeed, the binomial distribution provides a good description
for any sum of independent events, such as the sum of several dice, the
results of many flips of a coin, or the behavior of the number of atoms in
a part of a gas.
In general, the binomial distribution describes the case where we have
a sequence of N identical, independent trials with discrete outcomes Xi ,
i = 1, . . . , N – often called a Bernoulli process. The simplest case is when
Xi is binary, such as either 0 or 1. We have looked at a fair coin, but
even when the coin is not fair, such as if the case if we have probability
p for Xi = 1 and q = 1 − p for Xi = 0, the results are described by the
binomial distribution.
86 4 Probability and Statistics
This formula reproduces our results from above for a fair dice with
p = q = 1 − p = 1/2.
and
N
zj = Xi,j , j = 1, . . . , M , (4.53)
X
i=1
This gives M outcomes zj , and we can then collect statistics about these
outcomes. We generate M outcomes zj of length N in the array z using
xi = randint(0,2,(M,N))
z = sum(xi,axis=1)
We have used 100 bins. This is more than the number of possible values,
which span from 0 to 80 for the case where N = 80 and over a smaller
range when N is smaller. This was done to ensure that each bin only
contains one possible outcome. Now, if we use 100 bins for the case when
N = 20, there are only 21 possible outcomes, and many of the bins will
be empty. We therefore only plot the values in the bins that contain at
least one outcome. This is done by the find function, which returns an
array with indicies for all the element where the histogram is non-zero.
The resulting plots of the estimated probabilities for N = 10, 20, 40, 80
are shown in Fig. 4.7.
0.25 0.25
N = 10
N = 20
0.2 N = 40 0.2
N = 80
0.15 0.15
P (n )
P (n )
0.1 0.1
0.05 0.05
0 0
0 20 40 60 80 −20 −10 0 10 20
n (n − ⟨n ⟩)
0.25 0.4
0.2
0.3
σ · P (n )
0.15
P (n )
0.2
0.1
0.1
0.05
0 0
−5 0 5 −5 0 5
( n − ⟨ n ⟩ ) /σ ( n − ⟨ n ⟩ ) /σ
Fig. 4.7 Plot of the P (n) as a function of n for N = 10, 20, 40, and 80.
n=0 n=0
n
N
!
d N (4.54)
=p pn q N −n
X
dp n=0 n
d
=p (p + q)N = pN (p + q)N −1 = N p ,
dp
Similarly, you can use the same approach to show that the deviation is:
The second term contains the factor N , which typically will be much
larger than the ln N term in the first factor. We will therefore often only
include the second N ln N − N term, but here we will also include the
smaller first factor.
Here, we will prove that when N becomes large, the binomial distri-
bution approaches that of a Gaussian or a Normal distribution
N! 1 −
((N/2)−n)2
P (N, n) = 2−N ' √ e 2(N/4) . (4.57)
n!(N − n)! 2πσ 2
We will provide you with two ways to approach this derivation, using
purely analytical techniques and using a combination of analytical and
symbolic methods.
− N + n + (N − n) = 0 , (4.66)
(4.73)
Now, let us simplify further by introducing n = n̄(1 − h) and (N − n) =
n̄(1 + h). Let us first simplify the −n ln N − (N − n) ln(N − n) terms:
− n ln n − (N − n) ln(N − n) (4.74)
= −n̄(1 + h) ln n̄(1 + h) − n̄(1 − h) ln n̄(1 − h) (4.75)
= −n̄(1 + h) (ln n̄ + ln(1 + h)) − n̄(1 − h) (ln n̄ + ln(1 − h)) (4.76)
= −2n̄ ln n̄ − n̄(1 + h) ln(1 + h) − n̄(1 − h) ln(1 − h) (4.77)
N N
= −2 ln − n̄(1 + h) ln(1 + h) − n̄(1 − h) ln(1 − h) (4.78)
2 2
= −N ln N + N ln 2 − n̄(1 + h) ln(1 + h) − n̄(1 − h) ln(1 − h) .
(4.79)
We can now put all this together into ln P (N, n), getting
1
ln P (N, n) = ln √ − 2n̄h2 , (4.83)
2πσ 2
(n − n̄)2
2
n − n̄
− 2n̄h2 = −2n̄ = −2 . (4.84)
n̄ n̄
We insert for n̄ = N p = (N/2) = 2(N/4) = 2σ 2 :
1 (n − n̄)2
ln P (N, n) = ln √ −2 , (4.85)
2πσ 2 2σ 2
1
e− 2 ( σ ) .
1 n−n̄ 2
P (N, n) = √ (4.88)
2πσ 2
We now use this result to understand the scaling we found to work in
fig. 4.7. We see that if we rewrite the equation as
1
P (N, n)σ = √ e− 2 ( σ ) ,
1 n−n 2
(4.89)
2π
we would expect all the data to fall onto a common, universal curve –
given as the Gaussian distribution – as we indeed observe in Fig. 4.7.
4.5 The binomial distriubtion 93
log(2**N*factorial(N)/(factorial(N/2))**2) + O(u**2)
log(2**N*factorial(N)/(factorial(N/2))**2) + ...
u**2*(-gamma(N/2 + 1)*polygamma(0, N/2 + 1)**2/factorial(N/2) - ...
gamma(N/2 + 1)*polygamma(1, N/2 + 1)/factorial(N/2) + ...
gamma(N/2 + 1)**2*polygamma(0, N/2 + 1)**2/(factorial(N/2))**2) + ...
O(u**3)
94 4 Probability and Statistics
log(2**N*factorial(N)/(factorial(N/2))**2) - ...
u**2*polygamma(1, N/2 + 1) + O(u**3)
That is more like it! Now, we use our mathematical insight to simplify
further. We realize that N is a large number and that N/2 + 1 ' N/2.
The polygamma is the derivative of the digamma function. We can look
up the digamma-function, Ψ (x), finding that it can be approximated as
N! u2
ln P = ln(1/2)N + ln − . (4.92)
(N/2)! (N/2)! (N/2)
This expression already shows us how P depends on u:
u2
− (N/2)
P (N, u) = C(N ) e . (4.93)
ln C(N ) = −N ln 2 + ln N ! − 2 ln(N/2)!
√
' −N ln 2 + ln 2πN + N ln N − N (4.95)
q
− 2 ln 2π(N/2) + (N/2) ln(N/2) − (N/2) .
This is again well suited for symbolic simplification. Notice the use of
sym(2) to ensure that python does not insert an approximate value for
log(2):
4.5 The binomial distriubtion 95
We now realize that our notation is confusing, and we should clean it up.
Let us introduce the notation that the random variable Z is the result
of a binomial experiment. The probability for the observed value of Z, z,
to be in the range from n to n + dn is then written as
where we call fZ (z) the probability density for the random variable
Z.
Notice that it is the probability density fZ (z) that is normalized, but
instead of summing we need to calculate the integral:
96 4 Probability and Statistics
∞ ∞ 1
Z Z
1 2
fZ (z)dz = √ e− 2 u du = 1 , (4.100)
−∞ −∞ 2π
where normalization is ensured by the prefactor.
Notice that fZ (z) is a function of n and σ and not of N anymore.
5 2 5 2 5 2
4 4 4
1 3 1 3 1 3
in the sequence. We still draw the numbers in sequence and consider the
sequence (1, 5, 3) different from (5, 3, 1). How many such sequences are
there when there are N numbers in the sequence and k different balls
in the bag? This corresponds to asking how many ways can you place
students at the various chairs in class or how many ways can ways can
we select runners for the first, second and third place in a marathon —
in all these cases the position in the sequence matters.
How many possible configurations are there of such a sequence. For
the first number, there are k possible values. However, the value that
occured in the first number, cannot occur as the second number. There
are therefore only k − 1 values available for the second number, k − 2
for the third number, etc. The number of ways to select a sequence of N
such numbers is therefore Ω = k (k − 1) (k − 2) . . . (k − (N − 1)), which
we also can write as Ω = k!/(k − N )!.
5 2 2 2
4 4
1 3 1 3 1 3
How many possible such sets are there? We know that there are
k!/(k − N )! ordered sequences. But if we count all the ordered sequences,
we count both (1, 5, 3) and (5, 3, 1) as two occurrences, even though they
are part of the same set. We have therefore counted way too many sets.
How many different sequences are there that results in the same set?
This corresponds to the number of ways we can order the N numbers
(1, 3, 5), that is the number of ordered sequences of N elements, which is
N !. We can therefore find the number of sets by dividing the number of
sequences by N !, giving us Ω = k!/(N ! (k − N )!).
5 2 2 2
4 4
1 3 1 3 1 3
The result we have found now for the Binomial distribution is general.
Indeed, the sum of any set of independent, random variables will always
follow a normal distribution, independently of the underlying distribution
of ench individual part of the sum. This is a fascinating result with wide
ramifications: The behavior of the sum is independent of the behavior of
the individual components. The collective behavior is general and not
dependent on the details. This is a general feature in statistical systems
— that behaviors are universal and independent of the details — and a
central part of physics is to discover what types of universal exist and
what universality class a given process belongs to. Here, we will look at
two types of universal behaviors: The normal distribution and extreme
value statistics.
In many cases it can be simpler to first calculate either FZ (z) or 1−FZ (z)
and then find the probability density fZ (z) through derivation.
We can therefore interpret fT (t) as the probability density for the waiting
time T , and we may interpret the exponential distribution as a waiting
time distribution with a rate r or a characteristic time τ = 1/r.
102 4 Probability and Statistics
First, let us find the histogram using bins that are 1 second in width.
We do this by choosing the number of bins used to correspond to the
largest value of T observed using
n,t=hist(tval,bins=max(tval))
where the variable n now contains the counts, Nt , and t contains points
representing the bins. Since the bins all have the same size, this is a
feature of the hist function, we can find the bin size dt from the first
two values of t:
dt = t[1]-t[0]
Notice that this is a vectorized command, which calculates the values for
Pt for all the values in n. Essentially, a command like this corresponds to
for i in range(len(n)):
Pt[i] = n[i]/(nsamp*dt)
We can then plot the calculated probability density and compare with
the theoretical values found above:
which is done by
theory = p*exp(-p*t)
which again is a vectorized command that calculates the values for theory
for all values in the t-array. The results are plotted by
plot(t,Pt,’o’,t,theory,’-’), show()
−3 −3
x 10 x 10
2 1
0.8
1.5
0.6
fT (t )
fT (t )
1
0.4
0.5
0.2
0 0
0 2000 4000 6000 8000 10000 0 2000 4000 6000 8000 10000
t [ h] t[s]
−2 −3
10 10
−4
10
−4
10
fT (t )
fT (t )
−5
10
−6
10
−6
10
−8 −7
10 10
0 2000 4000 6000 8000 10000 0 2000 4000 6000 8000 10000
t [ h] t[s]
Fig. 4.11 Plot of the measured probability denstiy fT (t) for the waiting time distribution
for a process occuring with a probabity p = 1/1000 per hour. (Left) Bin size correspoding
to the smallest possible resolution in t. (Right) With 100 bins.
theory = p*exp(-t*p)
plot(t,Pt,’o’,t,theory,’-’)
And the resulting plots are shown to the right in Fig. 4.11. The results are
now much clearer. And we can now also see that the theory fits perfectly.
The data is indeed well described by the exponential distribution.
N!
n N −n
λ λ
P (n) = 1− (4.119)
n!(N − n)! N N
N!
N n
λ λ
= n
λn 1 − 1− (4.120)
n!(N − n)!N N N
1 N!
N n
λ λ
= λn 1 − 1− , (4.121)
n! (N − n)!N n N N
where we notice that when N → ∞:
N!
N n
λ λ
→1 ⇒ 1− → e−λ ⇒ 1− →1.
(N − n)!N x N N
(4.122)
This gives
λn e−λ
P (n) = , (4.123)
n!
for the probability for the number n of event in an interval with an
average number of events λ, where the events are rare and independent.
The Poisson distribution describes processes where there are a large
number of possible events (trials), but where the probability of each event
is low. The distribution describes how many events occur in a given time
interval. This can for example be used to describe the number of photons
detected by a telescope or a camera in astronomy, the number of cars
arriving at a traffic light, the decay of radiactive nuclei, or the number
of mutations on a strand of DNA.
106 4 Probability and Statistics
4.9 Summary
a discrete set of outcomes and hZi = zfZ (z)dz for a continuous set
R
1)) i (zi − z̄ 2 )2 .
P
4.10 Exercises
n̄n e−n̄
P (N, n) = , (4.126)
n!
when N approaches infinity and p 1.
c) From the result above, find the average number of heads, n̄ and the
variance
(n −¯ ¯)n2 . (4.130)
Now, let us consider a strip consisting of N squares as illustrated in
fig. 4.12. The squares are electrically conductive with probability p. Two
conducting squares next to each other provide a conductive path.
1 2 N
1 2 N
1 2 N
13
http://folk.uio.no/malthe/fys2160/in-gasexer010
14
http://folk.uio.no/malthe/fys2160/gasexer010.lammpstrj
A thermodynamical example
5
113
114 5 A thermodynamical example
1000
800
600
600 700 800 900 1000 1100 1200 1300 1400 1500
K
P V = N mvx2 . (5.6)
We recognize this from the ideal gas law, which we could measure, which
gives P V = N kT . Therefore we have related temperature to the velocity
of a particle:
1 1
kT = . (5.7)
2 mvx2
We find similar results in the y and z direction, so that in total we have
3
K = kT . (5.8)
2
particles only have kinetic energy and no (internal) potential energy due
to interparticle interactions. The total number of quadradic terms in the
energy sum is therefore 3N — there are three quadratic terms for each
particles. The equipartition principle therefore tells us that
3
U = N kT , (5.10)
2
If there are more degrees of freedom, such as from rotation or vibrations
of molecules, these must also be included by including f , the number of
degrees of freedom into the expression, and the expression for the energy
of the gas becomes
f
U = N kT , (5.11)
2
where f is:
• f = 3 if the only degree of freedom per particle are motion along the
three orthogonal directions.
• f = 5 if we include rotation in a diatomic gas. (Two new degrees of
freedom to describe rotation).
• f = 7 if we also include vibration in a diatomic gas. (Two additional
degrees of freedom to describe vibration).
Simplified model for a solid — ideal solid. In the simplest model for a
solid, each particle in the solid can move in three directions. A solid with
N atoms therefore have 6 degrees of freedom for each atom, three degrees
of freedom for their positions relative to their equililibrium positions and
three degrees of freedom for their velocities. This gives: 3
U = 3N kT , (5.12)
for a solid.
Clickers - Equipartition
5.2 Summary
5.3 Exercises
Micro- and Macro-states
6
We have seen that a gas develops towards a state where the number of
particles is uniform throughout the gas. We measured the number of
particles on the left side of the gas, and found that the system naturally
evolves towards a state with a uniform distribution. While the number of
particles in one half of the gas is fluctuating, the fluctuations becomes very
small compared with the number of particles, and the number of particles
increases. The behavior we observed for the gas is not a special case, but
a very general behavior in all systems with many particles — the system
will develop towards an equilibrium state. So far, we have only analyze
the number of particles — or the density — in a part of a system. In
this chapter we will extend this analysis to address thermal fluctuations,
fluctuations in energy, mechanical fluctuations, fluctuations in volume,
and density fluctuations, fluctuations in the number of particles in a
system.
Our plan is to follow the same strategy as we introduced for the gas:
We will study an isolated system — in molecular dynamics the number
of particles, the total energy and the volume is constant, which means
that the system is completely isolated. To understand what happens
inside this isolated system we will divide the system in two, and study
how the energy, the volume or the number of particles are distributed
between the two halves, just like we have done for the gas system.
Already for the gas, we saw that the system evolved towards an
equilibrium state, which corresponded to the most probable value for n,
and that the development was irreversible when we started from a state
that was far from the equilibrium state. Here, we will develop a better
121
122 6 Micro- and Macro-states
6
6 7 8 9 10 11 12
5 6 7 8 9 10 11
4
4 5 6 7 8 9 10
N (n)
n2
3 4 5 6 7 8 9
2
2 3 4 5 6 7 8
1 2 3 4 5 6 7
0
1 2 3 4 5 6 0 5 10 15
n1 n
Fig. 6.1 Left Illustration of the microstates of two dice. The microstates that are part of
the same macrostate n = n1 + n2 are given the same color. Right Plot of the histogram
of the number of microstates for each macrostate n for two dice.
N
n= (6.2)
X
ni ,
i=1
We found that the probability distribution for n was given by the binomial
distribution
P (N, n) = Ω(N, n)2−N , (6.3)
where the multiplicity Ω(N, n) represents the number of microstates
that give the value n for n. We call this the number of microstates in
macrostate n.
Sharpness of the multiplicity. The multiplicity for the number of par-
ticles on the left side of an ideal gas was given as
!
N
Ω(N, n) = . (6.4)
n
We also found that this probability, and hence also the multiplicity, was
very sharp around its average value. Indeed, the average value n̄ and the
standard deviation σn are given as
s
N N
n̄ = , σn = . (6.5)
2 4
From this result we see that the standard deviation becomes very small
compared with the average:
√
σn N
= = N −1/2 , (6.6)
n̄ N
which means that for a litre of gas at room temperature and atmosphere
pressure, where N is of the order of 1023 we see that the standard deviation
is 10−10 of the average value, which is well beyond the resolution of most
measurement methods. This means that for all practical purposes the
number of particles n is a constant.
Most probable macrostate. For the ideal gas system, we expect the
system to cycle through all possible microstates: They are all equally
probable. However, we also found that the initial state where all the
atoms were on the left hand side did not appear spontaneously. Why? In
principle, all values of n are possible. In practice, there are most states
near the average value of n. So many more states that if we move a few
standard deviations away from the average, which is 10−11 of the average
value, the probability to find such a state becomes negligible. This is the
126 6 Micro- and Macro-states
reason why we find the return to the intial state comic — it is extremely
unlike to happen.
The development of the system away from n = N , where we started the
simulation previously, towards n = N/2 is therefore effectively irreversible,
because there are so many more states near n̄ = N/2 than near n = N or
n = 0. This also means that the system develops towards a macrostate
where the number of particles per volume (the number density) is the
same on each side (if the two sides are equally large). The system develops
towards a homogeneous density.
Fluctuations in particle number. When we study the number of par-
ticles on the left side of the gas, we are addressing the variations, of
the fluctuations, in the number of particles inside the system. Alterna-
tively, we could say that there are fluctuations in the number of particles
per unit volume, since the volume does not change, that is, there are
fluctuations in the density of the gas.
These fluctuations are related to transport of particles: If the number
of particles on the left side changes by ∆n: n(t + ∆t) = n(t) − ∆n,
the number on the right hand side increases by the same amount: The
particles ∆n are transported from the left hand side to the right hand
side. This can occur because the systems are open to particle transport:
There is no wall between the two halves.
Other fluctuations. Ok, we have a good description of the fluctuations
of the number of particles, or the density, inside an isolated gas. However,
we may be interested in variations in other macroscopic properties as
well. For example. if the two halves of the system can transfer energy
between each other, what are the fluctuations in energy in the two halves
of the system? However, if we want to address fluctuations in energy, we
would like to single out this fluctuation alone. We would therefore like to
have a system where the number of particles on each side of the system
is the same — identically the same — but where the total energy can be
distributed in many ways between the two parts of the isolated system.
This is the motivation to start working with other model system such as
solids, where the particles do not move around significantly, but energy
is free to flow throughout the system. We will therefore first address the
fluctuations of energy in a simplified solid — in the Einstein crystal.
6.2 Behavior of a solid — Observations 127
Fig. 6.2 Visualization of a solid of Argon atoms modelled using the Lennard-Jones
potential at two different times. The colors indicate the velocities in the x-direction.
For a solid, the atoms are approximately fixed in space, but still vibrating.
For this system energy is free to flow, but particles will remain in place.
The solid is therefore well suited to study fluctuations and transport of
energy.
Running a molecular dynamics simulation of a solid. Let us first start
from a molecular model of a solid. We can address the behavior of a
solid using the same model we used for the Argon system, but with
smaller initial velocities and a smaller volume so that we ensure that the
system is in its solid phase. You find reasonable input parameters for a
simulation in in.solidstat021 :
# 2d Lennard-Jones solid
units lj
dimension 2
atom_style atomic
lattice hex 1.05
region box block 0 20 0 10 -0.1 0.1
create_box 1 box
create_atoms 1 box
mass 1 1.0
velocity all create 0.5 87287
pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5
neighbor 0.3 bin
neigh_modify every 20 delay 0 check no
fix 1 all nve
dump 1 all custom 100 solidstat02.lammpstrj id type x y z vx vy vz
thermo 100
run 500000
1
http://folk.uio.no/malthe/fys2160/in.solidstat02
128 6 Micro- and Macro-states
The resulting atomic configuration is shown in Fig. 6.2. The atoms are
organized in a regular lattice, a triangular lattice, which corresponds
to the (equilibrium) crystal structure of the two-dimensional system.
(It should here be noted that a two-dimensional system is somewhat
unphysical, but it is simple to visualize. You can easily run all simulations
in 3d without changing any of the general aspects of the results).
Measuring energy in the solid. Based on these simulations, we can
measure the kinetic energy of the particles on the left side of the model.
This does not represent the total energy for a crystal, since the potential
energy part is non-negligible. But it does give a picture similar to what
we had for the gas simulations. We read the data from the simulations
into python, find all the particles on the left side, find the sum of the
kinetic energies of all these particles, and plot the result using the script
solidplotkt02.py2 :
from pylab import *
d = dump("solidstat02.lammpstrj") # Read output states
t = d.time()
n = size(t)
Ktot = zeros(n,float) # Kinetic energy
# Get information about simulation box
tmp_time,box,atoms,bonds,tris,lines = d.viz(0)
halfsize = 0.5*box[3] # Box size in x-dir
# Loop over all timesteps
for i in range(n):
x = array(d.vecs(t[i],"x"))
vx = array(d.vecs(t[i],"vx"))
vy = array(d.vecs(t[i],"vy"))
# Find list of all atoms in left half
jj = find(x<halfsize)
k = sum(0.5*(vx[jj]*vx[jj]+vy[jj]*vy[jj]))
Ktot[i] = k
plot(t,Ktot),xlabel(’t’),ylabel(’n(t)’),show()
65 400
60
300
55
N (K)
K(t)
50 200
45
100
40
35 0
0 1 2 3 4 5 30 40 50 60 70
t 5 K
#10
Fig. 6.3 Left Plot of the kinetic energy of the left-half of the Argon solid. Right Histogram
of the kinetic energy K for the Argon system.
300
200
0 100 200 300 400 500 600 700 800 900 1000
t
The resulting plot of K(t) is shown in Fig. 6.4. Again, we see that the
system approaches a stationary state, corresponding to an equilibrium
state, after a short transient. The system has a clear direction of time.
What characterizes the equilibrium state? To answer this we need to
develop a theory for the behavior of the solid.
Let us now build a simplified model of the solid, inspired by the model for
the ideal gas. Fig. 6.5 illustrates atomic arrangements in a solid, liquid
and gas system. In the simulated solid, and in a real crystal where all
the atoms are spaced regularly on a lattice, the atoms are fixed into a
position on a lattice through the interactions with the other atoms in the
crystal. The lattice configuration is a stable configuration as long as none
of the atoms gain enough energy to break out of the local potential well
they are situated in. A reasonable description of such a system would be
that each atom vibrates around the minimum in an energy landscape,
where the potential energy is due to the interactions with the other atoms.
For simplicity, we can assume that the atoms do not directly interact,
they only interact through their average potential field, but the potential
does not vary as the atom vibrates. In this simplified picture, which is
our theoretical approximation to the system, each atom in the lattice is
affected by a local potential, and we can describe the vibrations around
the minimum of this potential by the lowest-order approximation, as
illustrated in Fig. 6.5, where each atom is affected by a set of springs,
and therefore acts as if it affected by a spring force. This corresponds to
the most basic vibration system — the harmonic oscillator.
6.3 Behavior of a solid — Theory 131
Fig. 6.5 Snapshots from simulations of a solid, a liquid, and a gas using the molecular
dynamics model. Illustrations of the corresponding model systems.
where k is the “spring constant” and x is the deviation from the equilib-
rium position.
Quantized harmonic oscillator. From quantum mechanics we know
that the energies of such a system is quantized, with possible values
= hν n . (6.8)
q q
3 3
2 2
1 1
0 0
i=1 i=2 i=3 i=4 i=1 i=2 i=3 i=4
(0,2,0,0) (0,1,0,1)
| OO | | | O | | O
Fig. 6.6 Illustration of the Einstein crystal model.
(N − 1 + q)!
!
N −1+q
Ω(N, q) = = , (6.9)
q q!(N − 1)!
Question
Clickers: Einstein crystal 1
A, and similarly for system B. However, we will also assume that the
whole system (A and B together) is isolated so that the total energy, the
total volume and the total number of particles is constant — this was
also the underlying assumption for the molecular dynamics simulations.
Multiplicity of macrostate qA , qB = q − qA . The total system therefore
consists of two Einstein crystals sharing the total energy q so that
q = qA + qB . The macrostate of this system is the energy qA in system A.
This is similar to the gas system, where the macrostate was the number
of particles on the left side. Our plan is now to find the probability of
a macrostate by counting the number of microstates for macrostate qA
and divide by the total number of microstates. But how can we find the
multiplicity of macrostate qA of the whole system?
A B
qA + qB = q
NA + NB = N
Question
Clickers - Einstein crystal 2
The resulting number of microstates are show in Fig. 6.8 and in the
following table. We notice that the the multiplicity Ω = ΩA ΩB has a
maximum for qA = q/2 = 5. But how can we use the multiplicities to
find the probability of a macrostate?
6.3 Behavior of a solid — Theory 137
+
1
NA = NB = 5 and q =
qA + qB = 10. 0.5
0
0 1 2 3 4 5 6 7 8 9 10
qA
qA qB ΩA ΩB Ωtot
0 10 1 1001 1001
1 9 5 715 3575
2 8 15 495 7425
3 7 35 330 11550
4 6 70 210 14700
5 5 126 126 15876
6 4 210 70 14700
7 3 330 35 11550
8 2 495 15 7425
9 1 715 5 3575
10 0 1001 1 1001
the atoms had both specific positions in the crystal and they interacted
with their neighbors. How could we extend the Einstein crystal model
to include both simplified interactions and the relative positions of the
atoms, so that we can model energy flow without including the full
dynamics.
Global dynamics in the Einstein crystal. We can make a small mod-
ification to the Einstein crystal model to include some of these effects.
The system consists of two parts, A and B, so that each atom/oscillator
belongs to either A or B. As a first approximation, we introduce simplified
interaction between the oscillators, by allowing energy to be randomly
moved from one oscillator to another oscillator, while conserving the
total energy. This means that we go from one microstate s1 to another
microstate s2 with the same energy. Hence both these microstates are
possible microstates for the system, and they are both equally probable,
since all microstates are equally probable.
We introduce the following algorithm to imitate the random transmis-
sion of energy in the system:
• Select an oscillator (particle) at random, i1 . Let us attempt energy
transport from this oscillator.
• Select another oscillator (particle) at random, i2 . This oscillator may
receive energy from n1 .
• We transfer one unit of energy from i1 to i2 , if oscillator i1 has at
least one unit of energy.
We can implement this algorithm using the following steps: (i) Generate
an initial state of the Einstein crystal with energy qA in part A and
energy qB in part B, (ii) Perform one step of the algorithm, (iii) Measure
the new energy qA (and qB = q − qA ), (iv) Continue with step (ii).
We generate the initial state by placing each of the qA energy units in
part A at random oscillators in part A and similarly for part B. This is
implemented in the following program, which also plots both the state
and the energy qA of the system:
NA = 100, NB = 100 # Nr of oscillators
qA = 300, qB = 0 # Initial energy
q = qA + qB # Total energy
N = NA + NB # Total oscillators
state = zeros(N,float) # Microstate of the system
# state[0:NA-1] is part A, state[NA:NA+NB-1] is part B
ion() # Interactive plotting ON
# Generate initial, random state
placeA = randint(0,NA,(qA,1))
140 6 Micro- and Macro-states
for ip in range(len(placeA)):
i = placeA[ip], state[i] = state[i] + 1
placeB = randint(0,NB,(qB,1))
for ip in range(len(placeB)):
i = placeB[ip], state[i] = state[i] + 1
# Simulate state development
nstep = 100000
EA = zeros(nstep,float), EB = zeros(nstep,float)
for istep in range(nstep):
i1 = randint(0,N) # Select rand osc. i1
if (state[i1]>0): # Does it have any energy ?
i2 = randint(0,N) # Select rand osc. i2
state[i2] = state[i2] + 1 # Transfer
state[i1] = state[i1] - 1 # energy
# Output and display result dynamically
subplot(2,1,1)
plot(r_[0:NA-1],state[0:NA-1],’b’,r_[0:NB-1]+NA,state[NA:NA+NB-1],’r’)
xlabel(’i’); ylabel(’n_i’); draw()
subplot(2,1,2) # Avg energy in each system
EA[istep] = sum(state[0:NA-1])/NA, EB[istep] = q - EA[istep]
plot(r_[0:istep],EA[0:istep],’-r’,r_[0:istep],EB[0:istep],’-b’);
xlabel(’t’); ylabel(’q_A/N_A , q_B/N_B’), draw()
Fig. 6.9 shows the resulting dynamics. In this case all the energy starts on
the left hand side and is gradually transferred to an uniform distribution
— as expected.
10 3
5 2.5
ni
q A /N A , q B /N B
2
0
0 20 40 60 80 100 120 140 160 180 200
i 1.5
10 1
5 0.5
ni
0
0 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
0 20 40 60 80 100 120 140 160 180 200
t
i
10
200
5
ni
150
0
0 20 40 60 80 100 120 140 160 180 200
100
i
QA
20
10 50
ni
0 0
0 20 40 60 80 100 120 140 160 180 200 0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
i t
Fig. 6.9 Illustration of the time development of two Einstein crystals in thermal contact.
+A +B
+A +B
NA = NB = 10, q = 200 b 0.4 0.4
NA = NB = 50, q = 1000.
0.2 0.2
Notice that the multiplicity
becomes sharper for larger 0
0 0.2 0.4 0.6 0.8 1
0
0 0.2 0.4 0.6 0.8 1
systems. qA =q qA =q
ln x! ' x ln x − x . (6.15)
Now we assume that the number of units of energy is very large compared
to the number of oscillators: q N , which corresponds to assuming that
we are in the classical limit where the quantum resolution into discrete
energy levels are not important. We can then simplify ln(q + N ) through:
144 6 Micro- and Macro-states
N N
ln(q + N ) = ln q 1 + = ln q + ln 1 + ' ln q , (6.20)
q q
where we have used the approximation ln(1 + x) ' 0, which is valid when
x 1. Plugging this back into the relation for ln Ω gets rid of the q ln q
terms, giving
ln Ω ' (q + N ) ln q − N ln N − q ln q (6.21)
q
= q ln q + N ln q − N ln N − q ln q = N ln . (6.22)
N
The multiplicity is then
N
q
Ω'e N ln(q/N )
= (q N ) , (6.23)
N
This is the multiplicity of the Einstein crystal. We will see further
on that this is a very useful expression since we can use it to calculate
macroscopic properties of the Einstein crystal. Now, we will use this
formula to show that the multiplicity function is indeed very sharp.
Sharpness of the multiplicity function. Armed with this appoximation
for the multiplicity, we are ready to find an approximate expression
for the multiplicity and probability of a macrostate for an Einstein
crystal divided into two parts, A and B, that are in thermal contact. The
multiplicity for the two-part system is
NA NB
qA qB
Ω = ΩA (NA , qA ) ΩB (NB , qB ) = (6.24)
NA NB
For simplicity, let us address the case where NA = NB . The multiplicity
is then N N
qA q qA qB N
ΩA ΩB = = . (6.25)
N N N2
We saw in Fig. 6.10 that the multiplicity is sharp around qA = q/2,
we therefore express both qA and qB as small deviations from q/2 by
introducing
q q
qA = + x , q B = − x , (6.26)
2 2
where x is a number much smaller than q (but it is still rather large).
We insert this expression back into the multiplicity, getting
6.3 Behavior of a solid — Theory 145
N N
qA qB q q
Ω = ΩA ΩB = =N −2N
+x −x (6.27)
N2 2 2
" #N
2
q
=N −2N
−x 2
. (6.28)
2
Where 2x/q 1 and we can therefore use the approximation ln(1+u) ' u
(when u 1):
#N
2x
"
2 2 2
q q
ln −x 2
' N ln −N . (6.32)
2 2 q
(6.33)
This is the multiplicity for the macrostate qA = q/2 + x, and the probabil-
ity for this macrostate is simply the multiplicity multiplied by a constant.
The probability P (qA ) is therefore a similar function
2
x√
−
P (qA ) = ΩA ΩB /ΩT OT = Pmax e q/(2 N )
, (6.34)
number. However, for realistic systems N = 1022 , which means that the
multiplicity has fallen to 1/e after a deviation x = q/(2 1011 ), which is
very small compared with the value of q. If the full graph, that is with
the full range of possible qA values from 0 to q, spanned from here to the
Moon, the multiplicity of a system with would have fallen to 1/e over a
distance of 3.86 108 m/(2 1011 ) = 19mm. This also means that it is very
unlikely to observe a value of qA which is far away from q/2. The relative
variations of qA are extremely small in realistic systems — in practice
these fluctuations are not measureable at all.
We call the limit when there are no measureable fluctuations away
from the most likely macrostate the thermodynamic limit.
Comparison of exact and approximate results. We can test this ap-
proximation by comparing it with directly calculated values of the multi-
plicity. Fig. 6.11a shows plots of the multiplicity Ω(qA ; N, q)/Ωmax for
N = 10, 20, 40, 80 and q = 10 N . Fig, 6.11a shows direct plots of the
multiplicity rescaled by its maximum value. Otherwise the systems with
larger N and q would completely dominate the plot. The multiplicities
have a clear maximum value and decay approximately symmetrically
from each side of the maximum. The qA value that gives maximum
multiplicity increases as we increase N and q. We expect the maximum
to be at qA = q/2. Indeed, in Fig. 6.11b we see that if we plot Ωmax as a
function of qA − q/2, the distributions are centered around zero. However,
the widths of the distributions are also changing when we change q and
N . How wide is the distrubution compared to the average or typical
value of qA ? This is shown in Fig. 6.11, which shows Ωmax as a function
of (qA − q/2)/(q/2). Here, it is clear that the multiplicity becomes more
and more narrowly distributed as N and q increases — the multiplicity
is becoming sharper, and deviations from the average value for qA are
becoming less and less likely.
How good is the approximation we found in (6.33)? First, we replot
the multiplicities according to the
√ theory in (6.33): We plot Ω/Ωmax
as a function of (qA − (q/2))/(2 N ) in Fig. 6.11d. Yes! All the curves
now fall onto the same curve, corresponding to the Gaussian form in
(6.33). We call such a plot a data-collapse, and we often use such plots to
demonstrate/validate our theories. Now, we can even compare with the
√
Gaussian curve, we plot exp (qA − q/2)/(2 N ) in the same plot in
Fig. 6.11d, and indeed the theoretical curve fits nicely with the observed
curve — the approximation we have developed seems sound.
6.4 The ideal gas — Theory 147
1 1
N=10
N=20
+ 0.5 0.5
+
N=40
N=80
0 0
0 500 1000 1500 2000 -1000 -500 0 500 1000
qA qA ! q=2
1 1
0.5 0.5
+
+
0 0
-1 -0.5 0 0.5 1 -100 -50 0 p 50 100
(qA ! q=2)=(q=2) (qA ! q=2)= N
The main observations and conclusions we have made so far are valid
for most systems in thermal contact or for fluctuations in parts within
the system. The multiplicity function will typically be very sharp for
large systems, meaning that the system will only have a reasonable
probability to be in a very small fraction of the macrostates. Here, we
will demonstrate in detail that this is also the case for an ideal gas — a
simplified model of a gas.
Ideal gas. An ideal gas consists of N atoms (or molecules) in a box
of size L × L× as illustrated in Fig. 6.12. We assume that if the gas is
thin, that is if the particles typically are far from each other, they do
not interact much, except when they collide. As a first approximation,
we will assume that the particles do not interact at all. This is our
gas model, called an ideal gas, consisting of a set of particles moving
inside a box without interactions. However, we do assume an implicit
interaction — the atoms may exchange energy, but in such a way that
the total energy of the system is conserved. In addition to this, we will
encounter a two quantum mechanical features. First, if the particles are
Fermions, then two particles cannot be in the same energy state. We will
see what consequences this has further on. Second, the particle cannot
be discerned, and therefore we cannot discern two states where we only
148 6 Micro- and Macro-states
have exchanged two atoms. This will have consequences for how many
states there are for the system.
To describe the ideal gas, we will start from a single particle, then
discuss two particles, before finally moving to a system of N particles.
Our goal is to find the multiplicity of the ideal gas and to show that the
multiplicity function indeed is sharp also for the ideal gas.
L L
L L
L L
Fig. 6.12 (Left) Illustration of a molecular dynamics simulation of a thin gas. Right
Illustration of the ideal gas model consisting of N non-interacting, identical particles in a
L × L × L box.
h2 h2 2
( nx , nz , nz ) = n · n = n + n2
+ n2
, (6.35)
8mL2 8mL2 x y z
where m is the mass of the particle, L is the length of the box and
n = (nx , nz , nz ) is related to the momentum
h
p= n. (6.36)
2L
Each of the numbers nx , ny , nz represents state for the motion in the
x, y, and z-direction respectively, and they are all positive integers. We
can illustrate the possible states in a three-dimensional space with nx ,
ny , nz along the axes as illustrated in Fig. 6.13. Each point such as
(1, 1, 1) or (2, 3, 2) represent a state for system. In the n space there is a
constant density of states corresponding to one state per unit volume.
(Each 1 × 1 × 1 volume has one state). We also see that because the
energy depends on n2 , E = (h2 /8mL2 ) n2 , all states that have the same
distance to the origin in n-space have the same energy.
(a) nz (b)
ny
ny
n
nx nx
How can we use this to count the number of states in an ideal gas with
a given total energy E, but with only one particle, N = 1? In this case,
all the states with the same energy is on a the surface of sphere with
radius n in n-space. What is this radius? It is found from the relation
between n and E for the system consisting of a single particle in three
dimensions:
h2 2 2L √
E= n ⇒ n= 2mE (6.37)
8mL 2 h
150 6 Micro- and Macro-states
How can we count the corresponding number of states with this energy?
We need to find the surface area of the corresponding sphere in n-space,
remembering to include only 1/8 of this surface since we only address
positive n-values. This is simple for the 3d system. The surface area is
4πn2 , so that the number of states is:
1 1 8mL2 4πL2 4π
Ω1 = 4πn2 = 4π 2 E = E = 2 v 2/3 E . (6.38)
8 8 h h2 h
We notice that this result is a function of of E and V as it should, and
a function of N , but N = 1 here. How can we generalize this result to
more particles?
We can use the same approach as for a single particle two find the number
of states with this energy. The density of states in the 3N -dimensional n-
space is still 1: There is one state for each 1×1×. . .×1 (3N times) volume.
4
We can therefore estimate the number of states by estimating the “area”
of a sphere with radius n in 3N dimesions. (We must also remember to
only include positive values for all the ni in n = (n1 , n2 , n3 , . . . , n3N ) ).
The general formula for the surface area of a d-dimensional sphere is:
2π d/2
A= rd−1 . (6.41)
d
2 −1 !
1 2π 3N/2 2L
3N −1
Ωdisting = (2mE)1/2 , (6.42)
23N
3N
−1 ! h
2
1 1 1 2π 3N/2 2L
3N −1
Ω = Ωindisting = Ωdisting = (2mE)1/2 .
N! N ! 23N 3N − 1 !
h
2
(6.43)
We can simplify this expression by using that for very large N , 3N − 1 '
3N . However, in the first few examples, we will only be interested in the
V and E depedence of this expression, which is simple:
Ω = f (N )V N E 3N/2 . (6.44)
This is Gaussian form for the multiplicity function, just like we found
for the Einstein crystal. This means that also for the ideal gas, the
multiplicity function is very sharp. Just as we found for the Einstein √
crystal, the width of the multiplicity function is proportional to N
while the average value is proportional to E which √ is proportional to N ,
hence the relative value of the width goes like 1/ N . For realistic values
of N , such as N = 1020 , this relative width becomes a very small number,
typically 10−10 , which means that we cannot discern the actual value of
the energy EA in the ideal gas from its average value E/2 unless we can
measure EA to a precision of 10−10 , which is practically impossible.
This means that it is very unlikely to find the system in a state that is
significantly different from E/2, where the multiplicity is at its maximum.
If the system started away from this value, for example by having much
more energy in part A than in part B, the system would evolve towards
the most probable macrostate, where EA = E/2. This is an example of
a general principle, the second law of thermodynamics.
We have found that for the two models system we have addressed, the
ideal gas and the ideal (Einstein) crystal, the most likely macrostate is
very sharp and any fluctuation away from the most likely macrostate is
extremely unlikely. If we start from a microstate that corresponds to a
macrostate that is away from the most likely macrostate the system will
develop toward the most likely macrostate, and therefore toward a state
with higher multiplicity — simply from the laws of probability.
This is what we call the second law of thermodynamics: The
multiplicity of a system increases. What characterizes the state it evolves
towards? The system evolves towards the macrostate with the largest
multiplicity, and this state corresponds to the stationary state or the
equilibrium state of the system.
Characteristics of the equilibrium state. What characterizes this equi-
librium state — the state with maximum multiplicity? Let us find the
maximum of the multiplicity for two Einstein crystals in contact. The
multiplicity of a macrostate with energy qA is
6.5 Thermal equilibrium, Entropy and Temperature 155
S = SA + SB when Ω = ΩA · ΩB . (6.59)
0
0 50 100 150 200
qA
Entropy and equilibrium. We can use the plot of ST OT (qA ) and SA (qA )
in Fig. 6.15 to better understand the condition for equilibrium. Equi-
librium occurs at the qA -value where the entropy (and therefore the
5
We have here chosen NA and NB not to be equal so that the position of the maximum
is not at the center of the figure. This makes the arguments clearer.
158 6 Micro- and Macro-states
∂S(NA , qA ) ∂S(NB , qB )
> , (6.64)
∂ qA ∂ qB
in this point. A small increase in qA by ∆q: qA → qA + ∆q, therefore
results in an increase in the total entropy of the system
∂SA ∂SB ∂SA ∂SB
∆ST OT = ∆SA + ∆SB = ∆qA + ∆qB = − ∆q
∂qA ∂qB ∂qA ∂qB
(6.65)
since ∆qA = ∆q and ∆qB = −∆qA = −∆q since qB = q − qA and q is a
constant when the small amount ∆q of energy is transferred from part B
to part A. Since the entropy must increase as the system evolves towards
equilibrium, we see that a small transfer of energy from part B to part
A will occur when qA is smaller than the equilibrium value.
Test your understanding: See if you can formulate a similar argument when qA is
larger than the equilibrium value.
It is first when the two slopes are equal that the system is in equilibrium.
What does the slope of SA tell us? It tells us how much the entropy (or
multiplicity) changes when we add a small amount of energy. It tells us
which way the system will develop, because it will develop toward larger
6.5 Thermal equilibrium, Entropy and Temperature 159
entropy (multiplicity). For qA < q̄A the system will gain more entropy
(multiplicity) by increasing qA and decreasing qB . Since the system, most
likely, develops towards larger entropy (multiplicity) it will develop this
way. Not always, but most probably.
Macroscopic.
• Entropy: S = kB ln Ω(N, V, E)
• An isolated system develops towards larger entropy
• In equilibrium, an isolated sytem is in the macrostate with maximum
entropy
• Temperature: (1/T ) = (∂S/∂E)N,V
Clickers: Thermal 01
6.5 Thermal equilibrium, Entropy and Temperature 161
S = N k ln E − N k ln( N ) + N k . (6.69)
And the temperature is:
1 ∂S Nk
= = , (6.70)
T ∂E E
which gives
E = N kT . (6.71)
This is what we would expect from the equipartition theorem, since
N is the number of oscillators, and each oscillator has two degerees of
freedom, hence, in equilibrium the energy is kT per oscillator and N kT
in total.
From this we can also predict the heat capacity. The heat capacity
is the amount of thermal energy, heat, which we need to transfer to a
system in order to increase its temperature by one unit (Kelvin), which
is given as the derivative of the energy with respect to temperature:
∂E ∂
CV = = (N kT ) = N k . (6.72)
∂T N,V ∂T
We call this the heat capacity at constant volume, since we keep both the
volume and the number of particles constant when we take the partial
derivative.
162 6 Micro- and Macro-states
1 1 2π 3N/2 2L
3N −1
Ω= (2mE)1/2 . (6.73)
N ! 23N 3N − 1 !
h
2
1 1 2π 3N/2 2L
3N
Ω' (2mE)1/2 . (6.74)
N ! 23N 3N !
h
2
4πmE 5
3/2 !
V
S = N kB ln + . (6.77)
N 3N h2 2
We can use this to find the energy E of the ideal gas, by finding the
temperature:
1 ∂S
= . (6.78)
T ∂E N,V
Since N and V are constants in this derivative, we only need to include
the terms that include the energy:
3
S(N, V, E) = g(N, V ) + N k ln E 3/2 = g(N, V ) + N k ln E , (6.79)
2
where g(N, V ) contains all the factors that do not depend on E. It is
now easy to find the temperature:
1 ∂S 3 1
= = Nk , (6.80)
T ∂E N,V 2 E
which gives
3
E = N kT . (6.81)
2
Again, this corresponds to the equipartition principle. The ideal gas
has N atoms, and each atom has three degrees of freedom: classically
this corresponds to three independent directions for the velocities, and
quantum-mechanically this corresponds to the three independent quan-
tum number nx , ny , nz we used to characterize the states of the ideal gas.
Each degree of freedom contributes with kT /2, which gives 3N kT /2 for
the whole gas of N gas atoms.
and the gas is allowed to fill the entire volume, while the total energy
and the total number of particles is conserved since the whole system
is isolated. The change (increase, as always) in entropy in this case by
going from a volume V1 to a volume V2 is:
V2
∆S = N k (ln V2 − ln V1 ) = N k ln . (6.82)
V1
In this case, the expansion of the system was isoenergetic — done at
constant energy of the whole system. However, since for an ideal gas,
the energy and the temperature are related by E = (3/2)N kT , we see
that when the number of particles is constant, having a constant energy
corresponds to having a constant temperature. In this particular case,
the change in entropy we have found therefore also corresponds to an
isothermal expansion — an expasion done at constant temperature. (Iso
here means at the same or constant).
In this case, the process is clearly also irreversible because the entropy
of the isolated system increases during the processes. Indeed, we would
be very surprised if we placed the dividing wall back into the system, and
all the gas particles spontaneously concentrated in the initial volume, V1 ,
by itself. Such a process in an isolated system would be violating the
second law of thermodynamics, because entropy would decrease, and also
appears to violate our basic intuitions about valid or probable processes
in the world.
(a) (b)
V1 V2
Fig. 6.16 Illustration of an expansion of an ideal gas while the gas is in an isolated box.
The system is isolated, and the gas expands from V1 to V2 after the internal wall was
removed from the system.
gases are inside a common, isolated system, so that their total number
of particles, energy and volumes are conserved. Then an internal barrier
between the two gases is removed, so that gas A can move into the volume
originally occupied by gas B and vice versa as illustrated in Fig. 6.17. If
the two gases are not interacting, and the two gases are not the same,
we can consider each process independently. First gas A expands into
twice its volume, leading to an entropy change
VA,2
∆SA = NA k ln , (6.83)
VA,1
and similarly for gas B:
VB,2
∆SB = NB k ln , (6.84)
VB,1
If NA = NB = N and V2 = 2V1 for both A and B, we get
(a) (b)
V V 2V
Fig. 6.17 Illustration of the mixing of two gases A and B, each with initial volume V .
We see that the two ratios 2V /2N = V /N and 2E/2N = E/N , and that
the total entropy therefore is
4πmE 5
3/2 !
V
S(2N, 2V, 2E) = 2N k ln + = 2S(N, V, E) .
N 3N h2 2
(6.88)
Sackur-Tetrode’s equation therefore correctly predicts that there is no
change in entropy when we remove such an internal barrier between two
identical gases. However, in order for this to be the case, it was essential
to include the N !-term in the multiplicity, because it is this term that
ends up as the N in the V /N term. Without the N !-term, we would
instead have
4πmE 3
3/2 ! !
S(N, V, E) = N k ln V + . (6.89)
3N h2 2
6.6 The laws of thermodynamics 167
and the entropy of a double system, S(2N, 2V, 2E), would be:
4πm2E 3
3/2 ! !
S(2N, 2V, 2E) = 2N k ln 2V + (6.90)
3N 2h2 2
The difference between 2S(N, V, E) and S(2N, 2V, 2E) would then be
2N k ln 2, which is the entropy of mixing. The Sackur-Tetrode equation
is therefore carefully made to ensure that this does not occur. This issue
was first raised by Gibbs, and is called Gibbs paradox.
We notice that the entropy scales in a simple way when we change
all the variables with a factor b: S(bN, bV, bE) = bS(N, V, E). We call
quantities that scale in such as simple way extensive quantities.
We now have the basis for the two first laws of thermodynamics, and we
have both a microscopic and a macroscopic interpretation of the laws of
thermodynamics.
In the microscopic view, we know that a system with constant N , V ,
and E has constant energy. This is indeed how we have set the system
up. On an atomic scale, the total energy is the sum of the kinetic and
potential energies of all the atoms in the system. and this energy is
conserved. This corresponds to the first law of thermodynamics –
the conservation of energy.
In the microscopic view, we characterize a system by the multiplicity
Ω(N, V, E), which we have been able to calculate for simple systems such
as the ideal gas and the ideal crystal. We have also found two basic laws:
• The system develops in time to the macrostate with the maximum
multiplicity
• In equilibrium, the system in the macrostate with the maximum
multiplicity
We have found that we can characterize a system by its microstates. We
assume that all microstates are equally probable. There are much more
microstates for some macrostates, and these most likely macrostates will
be the most likely observed macrostates in the system. Indeed, for realistic
system sizes — i.e. N = 1020 — deviations from the maximum values of
the macrostates are extremely unlikely. The standard deviation of the
distribution of macrostates is about 10−10 of the value at the maximum.
168 6 Micro- and Macro-states
∆E = W + Q , (6.91)
S = k ln Ω(N, V, E) . (6.92)
The two microscopic laws that (i) the system evolves towards larger mul-
tiplicity and (ii) that in equilibrium the system has maximum multiplicity
therefore corresponds to
This follows from the equation for thermal equilibrium - and tempera-
ture: If TA = TB and TB = TC then, indeed, TA = TC .
In addition, we will later also introduce a third law of thermodynamics,
which allows us to set an absolute scale for the entropy.
Clickers: Thermal02
∆S = ∆SA + ∆SB
∂SA ∂SB
= ∆EA + ∆EB
∂EA NA ∂EB NB (6.93)
∂SA ∂SB
= (−∆E) + ∆E
∂EA NA ∂EB NB
We can now use the general relation between temperature and the
derivative of the entropy for each of the two systems:
1 ∂SA 1 ∂SB
= , = . (6.94)
TA ∂EA NA TB ∂EB NB
Q = T dS . (6.98)
EA + EB = E
V A + V B= V
NA , N B
is zero. This occurs only if the pressure in each of the parts are the same,
since the force from part A on the piston is FA = pA AA , where FA is
the force and pA is the pressure, and similarly for part B, FB = pB AB .
Here, the areas on each side of the piston are the same, so that the
pressures also must be the same. Equilibrium would therefore require
equal pressures.
What are the equilibrium condition from a thermodynamical per-
spective? We know from the second law of thermodynamics, that an
isolated system — the whole system including both part A and B — is
in equilibrium when the entropy of the whole system is maximum. The
total entropy is the sum of the entropies of each subsystem:
where we now insert that dEB = −dEA and dVB = −dVA (from EA +
EB = E = const. and VA + VB = V = const.), getting:
!
∂SA ∂SB
dS = − dEA (6.104)
∂EA NA ,VA ∂EB NB ,VB
!
∂SA ∂SB
+ − dVA = 0 . (6.105)
∂VA NA ,EA ∂VB NB ,EB
For this to be true for any small dEA and dVA , we get the two conditions:
∂SA ∂SB ∂SA ∂SB
= , = .
∂EA NA ,VA ∂EB NB ,VB ∂VA NA ,EA ∂VB NB ,EB
(6.106)
The first condition is the same condition we found for a purely thermal
contact: The temperatures in the two parts must be the same in equilib-
rium. We guess that the second term is related to the pressures in the two
parts. But how is it related to the pressure? We can gain some insight
into this by looking at the units of this expression: dS/dV . We notice
that entropy has dimensions J/K=Nm/K, V has dimensions m3 , and
pressure has dimensions N/m2 . The derivative of S with respect to V
therefore has dimensions (N m / K ) / m3 , that is ( N / m2 ) / K. We must
therefore multiply (dS/dV ) by a temperature to get dimension pressure.
Since T is the same in both systems in equilibrium we can multiply with
T , getting to a definition of pressure:
This is not the only way to define pressure. We could for example also
have included a multiplicative or an additive constant, but we will see
below that this definition of pressure does reproduce the correct ideal
gas law and other know features of the systems we are interested in.
Clickers: Thermodynamics 04
174 6 Micro- and Macro-states
-3
-3.5
-4
-4.5
-5
-5.5
-6
-6.5
1
EA 0.8 1
0.6 0.8
0.4 0.6
0.4
0.2
0.2
VA 0 0
Fig. 6.19 a Illustration of the entropy as a function of EA and VA . The maximum of the
entropy occurs where the derivatives with respect to both EA and to VA are zero. b Plot
of the entropy, S = SA + SB , as a function of EA and VA for two ideal gases in thermal
and mechanical contact.
4πmE 5
3/2 !
V
S = N k ln + . (6.108)
N 3N h2 2
S = N k ln V + f (N, E) . (6.109)
which corresponds to
pV = N kT , (6.111)
which indeed is the ideal gas law. This also shows we should not in-
clude any other factors in the definition of the pressure in (6.107) — it
reproduces the correct ideal gas law at it is.
Clickers: Thermal 03
6.8 The thermodynamic identity 175
T dS = dE + p dV − µ dN . (6.115)
(We have not yet allowed N to vary or introduced the chemical potential
µ, but we write the equation in this form for completeness. When N is
constant, dN = 0, and the last term disappears).
T dS = dE + p |{z}
dV −µ |{z}
dN (6.116)
dV =0 dN =0
dS 1
= . (6.117)
dE T
which gives us:
∂S 1
= . (6.118)
∂E N,V T
Similarly, we find the derivative of S with respect to V when E and N
are constants? In this case, dE = 0 and dN = 0, which we insert into
the thermodynamic identity in (6.115), getting
T dS = |{z}
dE +p dV − µ |{z}
dN (6.119)
dE=0 dN =0
dS p
= . (6.120)
dV T
which gives us:
∂S p
= . (6.121)
∂V N,E T
This is a very useful technique, which we will use again and again in
various disguised throughout this text. Learn and practice it, and you
will only have to remember a very few definitions and laws in order to
master all of thermodynamics.
Clickers: Thermal 04
T dS = dE + p dV − µ dN , (6.122)
dE = T dS − p dV , (6.123)
6.8 The thermodynamic identity 177
dE = Q + W , (6.124)
We have now seen that two systems that are in thermal contact, that is
they are allowed to exchange energy, are in equilibrium when the temper-
atures are the same. If the two systems also are in mechanical contact,
that is they are allowed to exchange volume, they are in equilibrium
when also the pressures are the same. What if we also allow the two
systems to exchange particles — what is the equilibrium condition then?
Two systems that are allowed to exchange particles are said to be in
diffusive contact. We divide an isolated system into two parts, A and B,
so that the total energy, volume and particle number is conserved:
which gives
!
∂SA ∂SB
dS = − dEA (6.130)
∂EA NA ,VA ∂EB NB ,VB
!
∂SA ∂SB
+ − dVA (6.131)
∂VA NA ,EA ∂VB NB ,EB
!
∂SA ∂SB
+ − dNA = 0 , (6.132)
∂NA EA ,VA ∂NB EB ,VB
the most entropy by adding particles. Hence, when we use minus this
value we ensure that particles flow from high to low chemical potential.
dE = µ dN , (6.141)
S = N k ln E − N k ln(N ) + N k . (6.143)
∂S
µ = −T
∂N E,V
= −T (k ln E + k − k ln(N ) − k)
(6.144)
= −T (k ln E − k ln N )
E
= −kT ln .
N
4πmE 5
3/2 !
V
S = Nk +
N 3h2 N 2
(6.145)
4πmE 5
3/2 !
= N k ln V − ln N 5/2
+ .
3h2 2
4πmE 5 5 1
3/2 !
= −T k ln V − ln N 5/2
+ − T Nk
3h2 2 2N
(6.146)
4πmE
3/2 !
V
= −T k ln
N 3N h2
2πmkT
3/2 !
V
= −T k ln
N h2
where we have inserted that E = (3/2)N kT for the ideal gas. We see that
the chemical potential depends on the density: Increasing the density
(N/V ) while keeping T constant would mean that (V /N ) becomes smaller,
so that the chemical potential becomes larger — the system becomes
more willing to give away particles.
Question
Clickers: Heat capacities
182 6 Micro- and Macro-states
from the simulation. Typically, we will not find the temperature from
the entropy, but instead we will measure the temperature directly from
the average kinetic energy per particle (or degree of freedom) in the
system. We will provide many examples of the use of molecular dynamics
simulations throughout this book — hopefully these examples will provide
you with ideas and inspiration for your own use of similar methods if
you need them in your future work.
Z = sum(n,axis=0)
hist(Z), show()
and plot the resulting distribution of probabilties found from the his-
togram in Fig. 6.20. Notice that the histogram counts the number of
results, N (zi ), in intervals from zi to zi + ∆zi . If the bin size ∆zi is
non-zero, we need to divide by the bin size as well as the number of
samples to estimate the probability P (zi ) (see Sect. 4.4.4 for a discussion
of bin sizes and probabilities). Fig. 6.20 shows that the distributions
P (z) approaches a continuous distribution as the number of samples M
increases. Indeed, when M = 104 the distribution already appears to
give a good representation of the distribution, even though only a very
small fraction of the number of microstates have been probed. However,
since most of the randomly selected microstates will be in the region
with the most probably macrostates, we still get good estimates for the
probabilities of the most probable macrostates. On the other hand, the
results for the very unlikely macrostates will be poor, since there will be
few if any data points in this range of Z values.
Stochastic model for the Einstein crystal. We can apply a similar
approach to sample the microstates of the Einstein crystal, and then
use these sampled microstates to calculate the energy qA of part A of
the crystal and qB of part B, similar to what we did previously. Let us
assume that there are NA oscillators in part A and NB in part B, so that
there are N oscillators in total, and that the total energy of the system is
q. How can we generate a random microstate? We have q units of energy
and N oscillators to distribute this energy randomly onto. We do this
by placing each unit of energy in a randomly selected oscillator. That is,
for each unit of energy, we select an oscillator at random, and increase
the energy of this oscillator by one unit. When this has been done for all
q energy units, we have generated a microstate, (n1 , n2 , . . . , nN ), where
ni is the number of energy units in oscillator i. The total energy is then
q = i ni . We choose part A to be the first NA oscillators, that is, part
P
The resulting distribution for P (qA ) is shown in Fig. 6.20 for various values
of M . We see that the distribution approaches a smooth function for
P (qA ) when M is very small compared to the total number of microstates
(which is the multiplicity of the Einstein crystal — a very huge number
as we know).
Notice that for this particular case, we know the exact solution to
the problem. However, in other situations you may not know the exact
solution, and this form for Stochastic sampling may be an efficient way
to learn about the probability for a macrostate in the system. Notice
that it may not always be this simple to generate a state with a given
total energy, and we may instead have to depend on a Monte Carlo type
model for the system.
0.02
Fig. 6.20 Plot of the esti-
M=10 2
mated probability density
N (qA )=(M "qA )
0.015 M=10 3
P (qA ) for the energy qA M=10 4
0.01 M=10 5
in the left half of an Ein-
stein crystal for various 0.005
sample sizes M . System
0
with N = 200, q = 2000, 920 940 960 980 1000 1020 1040 1060 1080 1100
qA
NA = NB = N/2.
Stochastic model for the Ideal gas. We have already develop a stochas-
tic model for the number of particles in a part of an ideal gas. A microstate
of the gas may be the position of all the particles, or simply whether
particle i is on the left side (ni = 1) or not (ni = 0). The microstate
186 6 Micro- and Macro-states
of the system would then be a list of the positions of all the particles,
(n1 , n2 , . . . , nN ), and the number of particles on the left side is n = i ni .
P
20 20 20
40 40 40
20 40 60 80 20 40 60 80 20 40 60 80
3000
qA
2900
2800
0 1 2 3 4 5 6 7 8 9 10
t #104
Fig. 6.21 Illustration of the time development of two two-dimensional Einstein crystals
in thermal contact.
6.11 Summary
• The macrostates for the two Einstein crystals do not have the same
number of microstates — some of the macrostates have vastly more
number of microstates that others.
• A system develops towards the most probably macrostate
• The number of microstates for a given macrostate is called the multi-
plicity of the macrostate
• The multiplicity of an isolated system is Ω(N, V, E).
• The entropy of an isolated system is defined as S = k ln Ω(N, V, E)
• The temperature of an isolated system is (1/T ) = (∂S/∂E)N,V
• The pressure of an isolated system is p = T (∂S/∂V )E,N
• The chemical potential of an isolated system is µ = −T (∂S/∂N )E,V
• The first law of thermodynamics states that ∆E = Q + W
• The second law of thermodynamics states that the entropy of an
isolated system must increase of be constant in any process. In equi-
librium the entropy is at a maximum.
• The thermodynamic identity is T dS = dE + p dV − µ dN
• The heat capacity of a system at constant volume is CV = (∂E/∂T )V
6.12 Exercises
Here, we will assume that each step can be either to the left, Xi = −1,
or to the right, Xi = +1, with equal probability.
The microstate for such a walker will correspond to specifying each of
the steps, Xi , whereas a macrostate will refer to the position ZN after
N steps.
a) Write down all the microstates for a N = 4 steps random walk.
190 6 Micro- and Macro-states
b) Show that !
∂2S
<0, (6.149)
∂E 2 N
and discuss what this means.
193
194 7 The canonical system
Let us start from a simple example system that we master well — the
harmonic oscillator. We will address the motion of a single oscillator in
contact with a large reservoir so that the temperature of the oscillator
is constant. The reservoir will consist of a huge amount of oscillators in
contact with the single oscillator. This is a system we now are proficient
in discussing and solving — we can therefore use our experience with
the harmonic oscillator system to gain insight into the canonical system.
system there is one state per energy. The probability to find system A in
state qA is
Ω(qA , NA ) Ω(qB , NB )
P (qA ) = , (7.1)
ΩT
where qA can range from 0 to q, and Ω(qA , NA ) is the multiplicity of an
Einstein crystal with NA oscillators and qA energy, and is given by
!
q A + NA − 1
Ω(qA , NA ) = . (7.2)
qA
The total multiplicity ΩT is the sum of all the multiplicities for different
values of qA .
Calculation of probabilities. The probabilities P (qA ) are plotted using
the following program. The resulting plot in Fig. 7.2a shows that the
probability falls off very rapidly as qA increases.
# Einstein solid NA - NB probability
from pylab import *
from scipy.misc import comb
NA = 1
NB = 199
q = 200
N = NA + NB
# Find multiplicity of all macrostates
omegaA = zeros(q+1)
qAvalue = zeros(q+1)
omegaB = zeros(q+1)
omegaTOT = zeros(q+1)
# Loop through all macrostates and find multiplicity
for istate in range(0,q):
qA = istate
qAvalue[istate] = qA
omegaA[istate] = comb(qA+NA-1,qA)
qB = q - qA
omegaB[istate] = comb(qB+NB-1,qB)
omegaTOT[istate] = omegaA(istate)*omegaB(istate)
PA = omegaTOT/sum(omegaTOT)
plot(qAvalue[j],PA[j],’-o’)
xlabel(’q_A’), ylabel(’log_{10}P(q_A)’), show()
0.8 0
0.6 -5
log10 [P (qA )]
P (qA )
0.4 -10
0.2 -15
0 -20
0 10 20 30 0 10 20 30
qA qA
0 0
-5 -5
log10 [P (qA )]
log10 [P (qA )]
-10 q=100 -10
q=200
q=300
-15 q=400 -15
q=500
-20 -20
0 10 20 30 0 0.1 0.2 0.3
qA qA =q
Fig. 7.2 Probability P (qA , NA = 1) for the Einstein oscillator with q = 200, N = 200.
∗
P (qA ) = Ce−qA /q , (7.3)
where C and q ∗ are constants. How can we test if the measured distri-
bution has this form? We notice (and this is a common trick that it is
useful for you to learn) that if we take the logarithm of (7.1.1), we get:
qA
ln P (qA ) = ln C − , (7.4)
q∗
which is a linear function of qA . This means that if we plot ln P along
the y-axis and qA along the x-axis, we expect the plot to be linear if the
functional form in (7.1.1) is correct. Fig. 7.2b shows the resulting plot.
Indeed, the curve is approximately linear — our theory formulated in
(7.1.1) seems to be reasonable!
Effect of temperature. Maybe our theory becomes better if we increase
q and therefore the number of possible values for qA ? We try this by
plotting curves for P (qA ) for several values of q using the following
program:
7.1 Boltzmann statistics in the Einstein crystal 197
The resulting curves for ln P (qA ) are shown in Fig. 7.2c. Hmmm.
Interesting. The slope of the curves, and therefore the q ∗ value, apparently
depends on the total energy q in the system. How is this dependence?
We could measure the slope and plot it as a function of q to find out that
it appears that q ∗ appears to be proportional to q. And we can again
check this hypothesis by plotting ln P (qA ) as a function of qA /q. If q ∗ is
proportional to q we would then expect all the curves for various q-values
to fall onto a common curve. The resulting plot in Fig. 7.2d shows that
this is approximately the case. You can convince yourself that this is
indeed the case, and that the approximation becomes better for larger
N - and q-values, by redoing the plot for larger values of N and q.
Now, we have shown how P (qA ) depends on the total energy q in the
system. But if we think of the system as a single oscillator – oscillator
198 7 The canonical system
where C and c are constants. Now, let us see if we can make a theory for
this behavior.
ES ER = E0 - ES
VS VR
NS NR
where the sum is for normalization of the probability (to ensure the sum
of probabilities of all possible states is 1 — the system must be in one of
the possible states).
Probability of state i. Since the system S is in state i the multiplicity
of this state is 1: We have specified the state so it is only one way it
can be in this state. (Note that state here is not the same as the energy,
because several states can have the same energy and still be separate
states. It is therefore important to remember that we here consider states
and not only the energy.)
What is the multiplicity of the reservoir? For a given microstate i of the
system S, the reservoir R can be in many microstates. The multiplicity of
the macrostate where system R has energy E0 − i is Ω(E0 − i ), where
E0 is the total energy of the system. The probability of the reservoir is
therefore
ΩS ΩR
P (i) = P = C (1 ΩR ) , (7.7)
i ΩS ΩR
To simplify the algebra we work with the logarithm of the probability:
∂ ln ΩR (E)
ln ΩR (E0 − i ) = ln ΩR (E0 ) + (−i ) + O(2i ) , (7.9)
∂E V,N
and therefore
Z = Z(N, V, T ) = e−i /kT , (7.14)
X
energies of a system, and not over all the states. However, energies may
be degenerated — there can be several states that have the same energy
— and in this case you need to include one term in the partition function
sum for each of the states in the system. Alternatively, you can introduce
the degeneracy g() of a system, the number of states of energy , and
then sum over all possible energies instead
i i
where the sum is over all states i of the system S. Since we have an
expression for P (i) we can simplify this expression to:
1 −i /kT
Ē = (7.22)
X
i e .
i
Z
The trick is now to recognize that the sum is the derivative of a sum
which is simpler to calculate:
d X −βi dZ
i e−βi = − =− (7.24)
X
e .
i
dβ i dβ
This provides us with a coupling between the microscopic and the macro-
scopic descriptions of the system:
The system may be in two states with energies 0 and 1 . What is the
internal energy and the heat capacity of this system?
(a) (b)
S ΔE R
ε1 ε1
ε1
ε0 ε0 ε0
TS TR
where the sum is over all the states. In this case, all the states corresponds
to all the energies.
xlabel(’kT/\epsilon’), ylabel(’C_V/\epsilon’)
show()
U /0
0.5
Plot of heat capacity as a
function of temperature.
0
0 0.5 1 1.5 2 2.5 3
k T /0
−3
x 10
1.5
1
C V /0
0.5
0
0 0.5 1 1.5 2 2.5 3
k T /0
Heat capacity. Similarly, we can express the heat capacity as the deriva-
tive of Ē with respect to β:
1 1 ∂2Z 1
! " 2 #
∂ Ē ∂ Ē ∂β ∂Z
CV = = = 2 2
− 2 , (7.34)
∂T ∂β ∂T kT Z ∂β Z ∂β
1 ∂2Z
E¯2 = 2i e−βi = (7.36)
X
,
i
Z ∂β 2
Now, we expect both the energy and the heat capacity (which is the
derivative of energy with temperature) to be extensive properties —
properties that are proportional to the number of particles N . This means
that the relative fluctuation in E is given as
√
∆E N
∝ ∝ (N )−1/2 . (7.39)
Ē N
In the limit of realistic N , typically on the order of 1020 – we see
that the relative error is 10−10 , which is generally not measurable. The
thermodynamic properties are therefore sharp.
i = 0 + i ∆ , (7.40)
i = i ∆ , i = 0, 1, 2, . . . . (7.41)
208 7 The canonical system
i=0
i n=0
subplot(2,1,2)
CV = diff(E)/diff(x)
xx = 0.5*(x[1:]+x[0:-1])
plot(xx,CV)
xlabel(’T/\theta_E’), ylabel(’C_V/\epsilon’)
show()
U /0
T . a Plot of the energy E
0.5
as as function of T . b Plot
of the heat capacity as a 0
function of temperature. 0 0.5 1 1.5
T /θ E
1
C V /0
0.5
0
0 0.5 1 1.5
T /θ E
(I leave it for you to find an analytic expression for the heat capacity.)
Harmonic oscillators in diatomic gases. It is interesting to notice the
behavior of the heat capacity for a single harmonic oscillator. This would
be the contribution to the heat capacity for the vibration of a diatomic
molecule. Notice that when T TE there is no contribution from the
oscillations, whereas when T TE (or about at TE ), there is a contibu-
tion from the oscillations. This allows us to sketch the expected effects of
oscillations on the behavior of a diatomic ideal gas — where the behav-
ior goes from 3/2N kT to 5/2N kT at around TE for the corresponding
oscillation. A nice prediction.
(S1 , S2 , . . . , SN ) = −S1 µB − S2 µB − . . . − SN µB =
X
−Sj µB .
j
(7.51)
Partition function. The possible states of the system are then possible
values for (S1 , S2 , . . . , SN ), to find the partition function we must there-
fore sum over all possible values for S1 , all possible values for S2 , and so
on:
7.2 The partition function and Boltzmann statistics 211
= −(S1 )/kT
e−(S2 )/kT . . . e−(SN )/kT (7.55)
X X X
e
S1 =±1 S2 =±1 SN =±1
| {z }| {z } | {z }
=Z1 =Z1 =Z1
= Z1 Z1 . . . Z1 (7.56)
= Z1N . (7.57)
Where we have introduced Z1 as the partition function for one spin, which
we found in (7.49), and ZN as the partition function for N non-interacting
spins.
Energy of N -spin system. This means that the energy, E, which de-
pends on ln Z, simply will have a factor N in front:
∂ ∂ ∂
ĒN = − ln ZN = − ln Z1N == −N ln Z1 = N Ē1 . (7.58)
∂β ∂β ∂β
However, the use of this argument depends critically on the assumption
that the spins do not interact. What happens if they do? We will address
this in the next example.
(i,j) i
where the sum (i, j) is over all i and for each i the sum is also over all
the neighbors, j, of i. The neighbors of a spin i is illustrated in Fig. 7.8.
This model is called the Ising model for a paramagnet. Notice that the
energy now contains cross-terms S1 S2 , so we cannot use the exact same
technique as before to find the partition function.
Let us look at the energy of the Ising system. We see that the energy
contribution from the spin-spin interaction is low (−J) if the two spins
are pointing in the same direction, and it is high (+J) if the two spins are
pointing in opposite directions. This spin interaction will therefore lead
7.2 The partition function and Boltzmann statistics 213
to a situation where all the spins point in the same direction — given
by the extenal field — in the lowest energy configuration. However, as
temperature increases, fluctuations will arise, and it is not so clear what
happens.
How can we find the partition function for this system? It turns out it
is possible to find the partition function for a one-dimensional system.
Solution in one dimension. For a one-dimensional Ising model with no
external magnetic field, the energy of a state (S1 , S2 , . . . , SN ) is
(S1 , S2 , . . . , SN ) = −J (S1 S2 + S2 S3 + S3 S4 + . . . + SN −1 SN ) .
(7.60)
The partition function can therefore be written as
Z= (7.61)
X X X
... eJβS1 S2 eJβS2 S3 . . . eJβSN −1 SN .
S1 =±1 S2 =±1 SN =±1
There is an old trick to calculate this particular sum. We notice that the
sum over SN is the same if SN −1 = 1 or is SN −1 = −1:
SN =±1
Now, when this sum is calculated, we can repeat this argument with the
sum over SN −1 , and so on, until we reach S2 . The final sum over S1 will
then only yield a factor 2. The partition function is therefore
Yang [2]. However, the mathematical methods needed are non-trivial and
will not be introduced here. Instead, we will approximate the partition
function and the equilibrium behavior of the system using approximate
solutions. We will address methods to find approximate, statistical solu-
tions in the canonical system in Sect. 7.10, and we will also address the
Ising model in detail there.
We will use both methods, choosing the method that is most adapted to
the problem.
i = (1, 2, 2, 3, 3, 3, 4, 4, 4, 4) (7.66)
i s
i s
where the sum over i is over all the states, and the sum over s is over all
the energies.
The average energy is therefore:
i
∂β
where β = 1/(kT ). We will now use this relation as a basis for the
coupling between the microscopic and the macroscopic.
216 7 The canonical system
E = E(S, V, N ) , (7.73)
which has exactly the right form! This is the quantity we were looking
for. It is an energy, since it has units energy, and it is a function of T , V ,
and N . We call this quantity F , Helmholtz free energy:
free energy, because, as we saw above, we can then find all quantities
of interest from partial derivatives of F . We know that Helmholtz free
energy, F , is
F = E − TS , (7.80)
We already know E, but we do not know S — yet. However, we know
that dF = −SdT − pdV + µdN and therefore we know that
∂F
S= , (7.81)
∂T V,N
∆S ≥ 0 . (7.88)
increases with time, and that the total entropy is maximal at equilibrium.
This is indeed what characterizes the equilibrium state in the system.
Do we have similar principles for the canonical system? Does the
entropy increase for a canonical system? Does the energy increase? Or is
there some other principle that we do not yet know? We can study this in
the Einstein crystal. We make a system consisting of two parts, a small
part A, which is the system, and a large part B, which is the reservoir. We
can make a system with NA = 10 and NB = 990. This should ensure that
system B is so large that the temperature in this system does not change
– it is constant and equal to the reservoir temperature TB = TR . The
total energy is q = qA + qB . We can simulate the dynamics of this system
using the monte-carlo method we developed previously. This would allow
us to simulate the time dynamics of the system as it develops through a
sequence of microstates. This is done by the following program:
# MC for a two part Einstein crystal
from pylab import *
NA = 10
NB = 990
qA = 300
qB = 9700
q = qA + qB # Total energy
N = NA + NB
nstep = 1000000
nbetween = 1000
state = zeros(N,float)
# Generate initial, random state
placeA = randint(0,NA,qA)
for ip in range(len(placeA)):
i = placeA[ip]
state[i] = state[i] + 1
placeB = randint(0,NB,qB)+NA
for ip in range(len(placeB)):
i = placeB[ip]
state[i] = state[i] +
# Simulate state development
EA = zeros(nstep,float)
EB = zeros(nstep,float)
TBSA = zeros(nstep,float)
TB = zeros(nstep,float)
for istep in range(nstep):
i1 = randiint(0,N) # Select oscillator at random
if (state[i1]>0): # Check if it has energy
i2 = randint(0,N) # Then find other oscillator
state[i2] = state[i2] + 1
state[i1] = state[i1] - 1
# Calculate T_B S_A
EA[istep] = sum(state[:NA-1])
EB[istep] = sum(state[NA:])
7.3 Thermodynamics in the canonical ensemble 221
qA = EA[istep]
qB = EB[istep]
omegaA = comb(NA+qA-1,qA)
TB[istep] = qB/NB
TBSA[istep] = TB[istep]*log(omegaA)
if (mod(istep,nbetween)==0):
subplot(4,1,1) # State
bar((1:NA),state(1:NA),’b’), hold(’on’)
bar((NA+1:N),state(NA+1:end),’r’), hold(’off’)
a = axis(); a(2) = N; axis(a);
xlabel(’i’); ylabel(’n_i’);
subplot(4,1,2) # Avg energy in each system
plot((1:istep),EA(1:istep)/NA,’-r’,...
(1:istep),EB(1:istep)/NB,’-b’);
drawnow, xlabel(’t’); ylabel(’q_A/N_A , q_B/N_B’)
subplot(4,1,3) # Plot T_B
plot((1:istep),EB(1:istep)/NB,’-b’)
xlabel(’t’); ylabel(’T_B’); drawnow
subplot(4,1,4)
plot((1:istep),EA(1:istep),’-r’,...
(1:istep),TBSA(1:istep),’-b’,...
(1:istep),EA(1:istep)-TBSA(1:istep),’-k’)
xlabel(’t’); ylabel(’E’);
legend(’E_A’,’T_B*S_A’,’E_A-T_B*S_A’);
drawnow
well, as evident from the plot of EB /NB alone, but these fluctuations are
small.
fFIGURE:[fig-partfunc/einsteincanonicalmc00, height=400 width=600
frac=1.0] Time development of the energies in two systems A with
NA = 10 and B with NB = 990 in thermal contact.
The energy in system A clearly decreases with time in this system.
What about the entropy? We can measure the entropy in system A
through the formula SA = k ln ΩA (qA , NA ), which we have developed
previously. Now, qA will change with time, and therefore as will SA .
This measurement was implemented in the program above. Fig. 7.9
shows both the energy and the entropy for system A. We see that the
entropy in system A decreases in time an approaches an approximately
stationary value. We expect the fluctuations to become smaller for larger
systems and the entropy to become sharp. These observations suggest
that in equilibrium – which is what we reach after a long time – the
system has reached a minimum in entropy and a minimum in energy.
Hmmm. That was surprising – the entropy is decreasing in this system.
(Convince yourself that this is not unphysical and that the second law of
thermodynamics still is valid).
Let us try the same simulation, but from a different starting point –
the case where system A initially has less energy than the average energy,
qA = 0 and qB = 10000. We expect the same equilibrium state in this
system as in the previous since the number of oscillators is the same and
the total energy in the system is the same. How does it develop in time?
Fig. 7.9 shows that the entropy, SA (t), and energy, qA (t), of system A
in this case both increase, and then reach a stationary value which is a
maximum of both entropy and energy? Hmmm. Now it is not easy to see
what kind of rule would determine the behavior of the system: Should
the entropy be a maximum or a minimum? Should the entropy increase
or decrease?
It is time to revisit the theory and develop a better theoretical under-
standing of this process. We know that the whole system, system A and
system B, is thermally isolated and therefore described as a microcanoni-
cal system with E, V , and N constant. For this system, the energy is
constant EA + EB = E and the total entropy must be increasing:
400 150
E A /∆ϵ
E A /∆ϵ
100
200
50
0 0
0 2 4 6 8 10 0 1 2 3 4 5
t x 10
5 t 5
x 10
40 40
35
S A /k
S A /k
20
30
25 0
0 2 4 6 8 10 0 1 2 3 4 5
t x 10
5 t 5
x 10
( E A − T B S A ) //∆ϵ
( E A − T B S A ) /∆ϵ
−50 0
−100
−100
−150
−200 −200
0 2 4 6 8 10 0 1 2 3 4 5
t x 10
5 t 5
x 10
Fig. 7.9 Time development of the energies and entropies for an Einstein system with
NA = 10 and NB = 990 for two different initial distributions of energy. In the left figures
the system start with qA = 300, qB = 9700 and in the right figures the system start with
qA = 0 and qB = 10000.
∆EA
∆S = ∆SA − ≥0. (7.91)
TB
We rearrange, getting
∆(EA − TA SA ) ≥ 0 , (7.96)
S = SR + SS
= SR (E − ES ) + SS (ES )
(7.99)
∂SR
' SR (E) − ES + SS (ES ) .
∂UR V,N
∂SR 1
= , (7.100)
∂ER V,N T
(i, j, n) = i + j + n , (7.104)
Z= e−(i +j +n )/kT = e−i /kT e−j /kT e−n /kT .
XXX XXX
i j n i j n
(7.105)
This can be further simplified by realizing that the i-terms do not vary
when we sum over j and n, and they can therefore be placed outside
those sums. Similarly, the j-terms do not vary when we sum over n, and
they can therefore be placed outside the sum over n, giving:
Z= e−i /kT e−j /kT e−n /kT = Ztrans Zrot Zvib . (7.106)
X X X
i j n
| {z }| {z }| {z }
Ztrans Zrot Zvib
i j
= −β1,i
e−β2,j
X X
e
i j
(7.108)
| {z }| {z }
Z1 Z2
= Z1 Z2 .
but if the particles are indistinguishable, these two states are the same,
and should only be included once in the sum. We should therefore divide
the sum by 2:
1
Z = Z1 Z2 , (7.111)
2
This is almost correct. But the sum also includes terms where the state
of both particles are the same, but only one such term is included in the
sum:
e−β(2,i +1,i ) , (7.112)
and I have also divided this part of the sum by two. Since these terms
not have been double counted, we should not divide these parts of the
sum by two. However, the error we make by dividing the whole sum by
7.4 Composite systems 229
two will be small as long as there are few of such states — and there are
very few of these states compared with the other states. We therefore
use the approximation:
1
Z ' Z1 Z2 (indistinguishable/identical) (7.113)
2
when the two particles are indistinguishable, and the exact result
Z = Z1 Z2 (distinguishable/different) (7.114)
Z = Z1 Z2 . . . ZN . (7.115)
Z1N
ZN = (indistinguishable particles) (7.117)
N!
230 7 The canonical system
particle in a box. The box has sides L and volume V . From quantum
mechanics we know that the possible states of a particle in a box are
described by the quantum numbers nx , ny , nz , representing the states of
motion in the x-, y-, and z-directions. The energy for the state (nx , ny , nz )
is
h2 2
n = n + n2
+ n2
= a n 2
+ n2
+ n2
, (7.120)
8mL2 x y z x y z
nx ny nz nx ny nz
(7.121)
We recognize this as the sum over three identical degrees of freedom for
motion along the x-, y-, and z-direction, and we can separate these sums
just as we did for composite systems:
2 2 2 2 2 2
Z1,trans = e−anx e−any e−anz = e−anx e−any e−anz .
XXX X X X
nx ny nz nx ny nz
| {z }| {z } | {z }
Z1,x Z1,y Z1,z
(7.122)
where each of the sums are identical and equal to ξ
∞
2
Z1,trans = ξ 3 , ξ = e−anx . (7.123)
X
nx =0
2πmkT
3/2 3/2
m
nQ = = . (7.126)
2π~2 β h2
232 7 The canonical system
∂ ln Z1,trans 3
3/2
∂ m
Ē1,trans =− =− ln V = kT . (7.128)
∂β ∂β 2π~2 β 2
This is in correspondence with the equipartition principle, because the
particle has only one degree of freedom for each direction of motion, hence
three degrees of freedom in total. The energy per particle due to the
translational motion is therefore (3/2) kT according to the equipartition
principle.
If we want to include more aspects of the gas, this would appear as
additional terms in the partition function for the individual particle. For
example, for a diatomic gas we would then also include partition function
for rotation and vibration:
These terms will also be included in the energy of a single particle and
therefore also in the heat capacity of a single particle in the gas. Let us
now use this result to find the partition function for a gas of N particles.
Ideal gas of N particles in a box. The particles in an ideal gas are
indistinguishable, hence the partition function for the N -particle gas is
Z1N 1
ZN = = (Z1,trans Z1,rot Z1,vib ) . (7.130)
N! N!
From this we find either the energy directly, or Helmholtz free energi,
which we then use to find the entropy and the pressure of the gas. We
start with the energy:
∂ ln ZN ∂ ln Z1
ĒN = =N (7.131)
∂β ∂β
∂
=N (ln Z1,trans + ln Z1,vib + ln Z1,rot ) (7.132)
∂β
= N E1,trans + N E1,vib + N E1,rot . (7.133)
7.4 Composite systems 233
Let us find the behavior for a monatomic gas with only translational
degrees of freedom. We insert Z1,trans = nQ /n, getting
Which we recognize as the equation of state for the ideal gas. Similarly,
the entropy is
∂F ∂ V
S=− =− N kT ln nQ (T ) + 1 (7.139)
∂T V,N ∂T N
V ∂
= N k ln nQ (T ) + 1 + N kT ln nQ (T )
N ∂T
(7.140)
V ∂
= N k ln nQ (T ) + 1 + N kT ln T 3/2 (7.141)
N ∂T
V 5
= N k ln nQ (T ) + (7.142)
N 2
V 2πmkT 3/2 5
!
= N k ln + . (7.143)
N h2 2
1 k N −n
= ln . (7.151)
T ∆ n
To find the number of vacancies as a function of temperature, we
invert the expression for the temperature
1 k n
=− ln , (7.152)
T ∆ N − n
which gives:
n ∆
= e− kT , (7.153)
N −n
which we can solve for n, getting:
∆
n = e− kT (N − n) , (7.154)
∆
∆
n 1 + e− kT = N e− kT , (7.155)
∆
n e− kT
= ∆ . (7.156)
N 1 + e− kT
Canonical approach. Let us see how we can address this same system as
a canonical system. We assume that the crystal of N atoms is in thermal
equilibrium with a large reservoir so that it has a constant temperature
T . In this case, we do not specify the number of vacancies n for the
system, since this would correspond to specifying the total energy of the
system. To find the thermodynamic behavior of this system we find the
partition function and use this to find the (average) energy of the system.
The partition function is given as the sum over all the possible states i
of the system. To describe the state we need to decribe the energy i for
each of the N lattice sites in the system. The energy of the lattice site i is
i = −Z if an atom occupies the lattice at this site and i = −z if the
site is empty and the atom is on the surface. (Here, we assume that the
number of atoms on the surface is so small, that we can assume that we
can describe each site independently of the others. Otherwise, we would
need to include the interactions of an atom with all the surrounding
atoms in detail). Notice that the number of atoms, N , is not changed, it
is only where teh atoms are placed that change. Each lattice site i can
therefore be in one of two possible states, and the sum over all possible
states must therefore be a sum over all possible lattice sites, i1 = 0, 1,
i2 = 0, 1, i3 = 0, 1, . . ., iN = 0, 1:
7.4 Composite systems 237
1 X
1 1
Z= e−(i1 +i2 +...+iN )/kT (7.157)
X X
...
i1 =0 i2 =0 iN =0
This sum can be split into a product of sums since there are no interactions
between the energies in the various sites (this is our assumption):
1 1 1
Z= −i1 /kT −i2 /kT
e−iN /kT (7.158)
X X X
e e ...
i1 =0 i2 =0 iN =0
N
1
= e−i1 /kT (7.159)
X
i1 =0
This is indeed the general result we found above: For a system of indepen-
dent components, the partition function is the product of the partition
functions for each of the components. Here, the total partition function
is the partition function for each of the N lattice positions. We find the
single-site partition function
Z1 = ez/kT + eZ/kT = eZ/kT 1 + e−∆/kT (7.160)
d ln ZN d ∆e−∆/kT
E=− =N βZ + ln 1 + e−∆β = −N Z +
dβ dβ 1 + e−∆/kT
(7.161)
We can use this to find the number n of vacancies, through E = −N Z +
n∆, giving
e−∆/kT
n= . (7.162)
1 + e−∆/kT
Which is exactly the same result as we found for the microcanonical
system.
Full model.
to the right or to the left. The number of monomers folded to the right is
NR and the number folded to the left is NL = N − NR . If one end of the
polymer is placed at x = 0, the other end will be at a position x = L:
dE = Q + W , (7.164)
dE = T dS + f dL ⇒ T dS = dE − f dL , (7.165)
Helmholtz free energy. We can now find Helmholtz free energy from
N! N!
F = −kT ln Z = −kT ln − = N ∆−−kT ln
NR !(N − NR )! kT NR !(N − NR )!
(7.170)
We apply Stirling’s approximation, ln(x!) = x ln x − x, to find an expres-
sion we can take the derivative of
F = N ∆ − kT (N ln N − NR ln NR − (N − NR ) ln(N − NR )) .
(7.171)
The force f on the polymer. We find the force f from Helmholtz free
energy
∂F ∂F ∂NR
f= = , (7.172)
∂L T,N ∂NR T,N ∂L
where
240 7 The canonical system
∂NR d 1
= ((1/2) (N + (L/∆l))) = . (7.173)
∂L dL 2∆l
and
∂F ∂
= (N ∆ − kT (N ln N − NR ln NR − (N − NR ) ln(N −(7.174)
NR )))
∂NR T,N ∂NR
= −kT (−(NR /NR ) − ln NR + ln(N − NR ) + 1) (7.175)
NR
= +kT ln . (7.176)
N − NR
We can now replace NR with NR = (1/2) (N + (L/∆l), giving
kT NR
f= ln (7.177)
2∆l N − NR
kT (N + L/∆l)/2
= ln (7.178)
2∆l (N − L/∆l)/2
kT (N + L/∆l)
= ln (7.179)
2∆l (N − L/∆l)
kT (1 + L/N ∆l)
= ln (7.180)
2∆l (1 − L/N ∆l)
This force is a purely entropic force. The force is due to the forced
uncurling of the polymer.
Discuss how we now can interpret the meaning of kT and how we can
use this to analyze the behavior of systems qualitatively.
We use these differential forms to find what are the variables describing
the system. Here is it S, V , and N , since these are the varibles for dE.
And we can also use this identity to read out the partial derivatives of E:
∂E ∂E ∂E
=T , = −P , =µ. (7.182)
∂S V,N ∂V S,N ∂N S,V
∂A ∂A ∂A
dA = dT + dV + dN . (7.183)
∂T V,N ∂V T,N ∂N T,V
How can we create such a function and what would the partial deriva-
tives be? Fortunately, there is a general theory in the form of Legendre
transforms that allow us to transform a function E(S, V, N ) into a new
function A(T, V, N ), where T is the partial derivative of E with respect
to S. This transform is called the Legendre transform. In general, if we
have a function f = f (x, y, z) and we want to replace x with its partial
derivative conjugate, t:
∂f
t= . (7.184)
∂x y,z
This is achieved by the Legendre transform:
dF = d(E − T S)
= dE − T dS − SdT = dE − (dE + pdV − µdN ) − SdT (7.187)
= −SdT − pdV + µdN ,
which indeed shows that the dependent variables – the variables occuring
in the differentials on the right hand side, dT , dV , and dN – are indeed
T , V , and N as we wanted.
Now, we are ready to examine other possible combinations of state
variables. What if we want to study a system where the volume is no
longer constant – so that we want to replace V with its partial derivative
conjugate. What is the conjugate of V ? It is −p:
∂E
−p= . (7.188)
∂V V,N
7.6 Transformation between ensembles 243
This potential is called the enthalpy of the system. Let us check that it
has the correct dependent variables by finding the differential for H:
dH = d(E + pV )
= dE + pdV + V dp
(7.190)
= (T dS − pdV + µdN ) + pdV + V dp
= T dS + V dp + µdN .
Φ = F − µN , (7.192)
generate the energy E, but in addition we need to make room for the
volume V of the system, which requires work done by the system on
the environment, and this work is pV . The energy needed to create the
system is therefore H = E + pV , the enthalpy of the system.
For a system in equilibrium with a heat bath with temperature T and
in an atmosphere/environment with pressure p, we need to generate the
energy E and we need to do a work pV to make room for the system,
but since we are in equilibrium with a heat bath, we get a thermal
energy of T S from the reservoir. The total energy needed is therefore
G = E − T S + pV , which is the Gibbs free energy of the system.
We therefore see that the free energies are the energies needed to
generate a system in various conditions. Tables of free energies are
therefore useful tools to determine the energy needed to create various
systems or to go from one system to another system through chemical
reactions or physical transformations, as demonstrated by the following
examples.
∆G = ∆H − T ∆S , (7.195)
∆H = −286kJ . (7.196)
If we assume that the reaction occurs at room temperature and at one atm
pressure, what is the enthalpy and Gibbs free energy for this reaction?
How can we find ∆H and ∆G for such compound processes? In the
tables in Schroder, and in other sources, the values for ∆H and ∆G
for each compound, such as for glucose, is the enthalpy or Gibbs free
energy when the compound is made from each component in its most
elemental, stable form. For glucose, we assume that it is made from C
(graphite), O2 and H2 . We can therefore find the ∆H or ∆G for the
reaction, by first converting each compound into their elemental forms
and the converting from the elemental forms and into the new compound
– the result of the chemical reaction. We can therefore find what it would
take to turn the left side into its basic components, which is the negative
of what it would take to create the left side from its basic compents. We
246 7 The canonical system
call the enthalpy and Gibbs free energy of the left side ∆HL and ∆GL
respectively – the energies needed to create the left side. Similarly, ∆HR
and ∆GR are the energies needed to create the right side from its basic
components:
Gibbs free energy is negative, meaning that this is the energy available
for mechanical work done by the muscle on the environment.
We see that the magnitude of Gibbs free energy is larger than the
magnitude of the enthalpy. What does this imply? Since ∆G = ∆H −
T S = ∆H − Q, where Q is the heat transferred into the muscle from the
environment due to the energy in the thermal bath, we see that in this
case:
which is the heat dumped from the environment to the muscle (to help
it do work at the same temperature).
7.7 Equipartition and velocity distributions 247
(q) = cq 2 , (7.205)
Z= (7.206)
X
e−βcq 2 ,
q
much smaller than kT , which is not true for quantum systems at low
energies.
where v = (vx2 + vy2 + vz2 )1/2 is the speed. This distribution is given in the
vx , vy , vz -space. What if we instead wanted to know the probability for
v to be in some interval from v to v + dv. Then we need to know what
volume in v-space this corresponds to: It corresponds to a spherical shell
from v to v + dv, which has a volume 4πv 2 dv when dv is small. Hence
the probability to find the velocity in the range from v to v + dv is
2 /2kT
P (v)dv = C 3 e−mv 4πv 2 dv , (7.217)
Fig. 7.11 illustrates both the distribution of vx , the velocity along the
x-axis, and the distribution of v, the speed of the particle.
1 1
P (vx )=Pmax
P (v)=Pmax
0.5 0.5
0 0
-5 0 5 0 1 2 3 4 5
$
vx =v v=v $
Fig. 7.11 a Probability density for the velocity vx along the x axis for a particle in
p gas. b Probability density for the speed v of a particle in an ideal gas. Here,
an ideal
v ∗ = kT /m.
Average velocity. Notice that the average velocity, v, is zero, while the
average speed, v, is non-zero. This is because the distributions for vx ,
vy , and vz are symmetric around zero, while the distribution for the
magnitude, v, of the velocity of course is zero when v < 0. The average
velocity is Z ∞ 2
hvx i = Ce−mvx /2kT vx dvx = 0 , (7.220)
−∞
We could also ask for the probability for a molecule to move with at least
twice the average velocity, that is P (v ≥ 2va ), where we have written
va = hvi to simplify the notation. This is estimated by summing up all
the probabilities for v ≥ 2va , that is, by integrating P (v) from 2va to
infinity:
∞ ∞ 3/2 Z ∞
m
Z Z
2 /2kT
P (v ≥ 2va ) = P (v) dv = 4π v 2 e−mv dv .
va va 2πkT va
p (7.223)
We change variable to simplify the exponent, introducing u = v m/2kT ,
du = m/2kT dv, and
p
q q q q
ua = va m/2kT = 2 8kT /πm m/2kT = 2 4/π ' 2.26 . (7.224)
2kT
3/2 3/2 Z ∞
m
2
P (v ≥ 2va ) = 4π x2 e−x dx . (7.225)
2πkT m ua
Ē = s P (s) , (7.226)
X
s s
ds
P (s)ds = P (s) dV = −P̄ dV , (7.228)
X X
s s dV
s s s
(7.231)
where we have used that
s s
and
S = −k P (s) ln P (s) , (7.235)
X
which is a general expression for the entropy. This relation also holds
in the microcanonical ensemble, since then Ps = 1/Ω for all states and
therefore we find S = k ln Ω after summing.
This integral can be interpreted as the integral under the curve f (x) from
x0 to x1 . We know how to solve it numerically by various integration
methods, but we can also use a stochastic (Monte Carlo) algorithm to
estimate the area.
Hit or miss algorithm. For example, we can use a “hit or miss” algorithm:
To estimate the integral we choose a box from y = 0 to some y1 > f (x)
for all x on the interval. We then select N points randomly in the interval
x0 to x1 and y0 = 0 to y1 . We can then estimate the integral by the
fraction of points falling below the curve f (x) multiplied by the area of
the box:
Nbelow
y' (y1 − y0 ) (x1 − x0 ) . (7.237)
N
254 7 The canonical system
This function, and N = 1000 random points, are illustrated in Fig. 7.12.
In this figure we also show the estimates integral I as a function of the
number of steps i used to estimate the integral. This was found using
the following simple implementation of the hit or miss algorithm. Notice
that we first use the symbolic package to find the exact solution for
comparison.
# Symbolic solution
from pylab import *
from pylab import plot as plt
from sympy import *
u = symbols(’u’)
f = (sin(10*u)+cos(50*u))**2
g=integrate(f)
fint = float(g.subs(u,1))
# Convert to Python function
fun = lambdify(u,f,"numpy")
# Plot f(x)
xx = linspace(0,1,1000)
yy = fun(xx);
plt(xx,yy);
hold(’on’)
# Calculate integral using hit and miss
fmax = 4.0 # Upper limit of f(x) for x (0,1)
N = 1000
hit = 0.
intest = zeros((N,1),float)
for i in range(1,N):
x = rand(1); y = rand(1)*fmax
if (y<fun(x)):
hit = hit + 1
intest[i] = hit/i*fmax
plt(array(range(0,N)),intest,’-r’)
xlabel(’i’);ylabel(’I’);
Hit and miss in high dimensions. Why would we calculate the integral
in this way? It seems very inefficient. This is true for a one dimensional
function. However, for integrals in high dimensions, ordinary integration
method does not scale well as the number of dimensions increase, but the
stochastic method introduced here is also efficient in high dimensions.
7.10 Simulations of a canonical system 255
4 1.2
1
3
0.8
2 0.6
y
I
0.4
1
0.2
0 0
0 0.2 0.4 0.6 0.8 1 0 200 400 600 800 1000
x i
Fig. 7.12 a Plot of the function f (x) and the points used to estimate the integral. The
color indicates if the point is below f (x) or not. b Plot of the estimated integral I as a
function of the number of iterations i used for the iteration.
Notice that we do not use this very simple algorithm for real integration.
Instead, there are more sophisticated methods that give a more rapid
approach to the correct answer. We will not introduce these here for
integration, but instead demonstrate examples of more advanced methods,
such as importance sampling, for simulations of a canonical system.
M
1 X
Ē ' Ei e−Eij /kT . (7.239)
Z j=1 j
= (7.243)
X X
Si −JSj − H ,
i j:i
where the sum over j : i are over all the neighbors of site i. We can then
implement the Metropolis algorithm to generate a sequence states for
the Ising system by selecting a spin, and then find the probability for
flipping this spin to be either up or down, and the flip the spin according
to these probabilities:
• Choose a random site i
• Find the energy of this site if Si = 1 and if Si = −1, E+ and E− .
• Set the spin up with probability exp(−βE+ )/C and down with prob-
ability exp(−βE− )/C with C = exp(−βE+ ) + exp(−βE− ).
• Repeat.
ams 5: Illustrate this algorithm with a figure.
How do we find the energy of the site? We calculate it from the energy
function. We therefore need to know mi = j Sj for the neighbors of site
P
sub2ind(sizespins,posx,mod(posy+1-1,N)+1) ...
sub2ind(sizespins,posx,mod(posy-1-1,N)+1)];
sumneigh = sum(spins(neighbors));
thisspin = spins(posx,posy);
DeltaE = -JdivkT*thisspin*sumneigh - HdivkT*thisspin;
change = (rand(1,1)<exp(DeltaE))*(-2)+1;
spins(posx,posy) = spins(posx,posy)*change;
imagesc(spins); axis square; drawnow;
end
imagesc(spins); axis square; drawnow;
end
S t e p = 10 S t e p = 20 S t e p = 40
S t e p = 80 S t e p = 160 S t e p = 320
i i
7.11 Summary
7.12 Exercises
relative to the oxygen atom as well as the flexing of the angle between
the two OH bonds — this angle vibrates around the average angle of
104◦ with a typical frequency of ω = 3.0 1012 s−1 . You may assume that
this vibration can be modelled as a harmonic oscillator with energy levels
(n) = ~ω(n + 1/2).
a) Find the partition function Z for T = 300 K. (It is sufficient only to
include the first three terms in the sum).
b) What is the probability for the water molecule to be in flexing states
n = 0, 1, 2 ?
c) Compare this with the vibrational states for the OH bond, for which
ω ' 3.4 1013 s−1 . Comment on the results.
100
10-1
3.1 3.2 3.3 3.4 3.5 3.6
103 =T
e) Show that a good partition function for the two-dimensional case will
be
Z = Z2D (exp (−z,0 /kT ))N , (7.250)
where Z2D is the partition function found for the two-dimensional system
above, and z,0 is the ground state for motion in the z-direction.
f) Find the energy using the partition function in (7.250).
respectively.
a) Show that for an ideal gas Cp − CV = N k.
where the sum is over all the states i of the system and P (si ) is the
probability for state i with outcome si .
a) Show that this formula corresponds to Boltzmann’s formula S/k =
ln Ω for the microcanonical system where the probability for all accessible
states are the same, P = 1/Ω.
b) Show that this formula also corresponds to the entropy for a Canonical
system in thermal equilibrium at temperature T , where the probability
for a state s with energy s is P (s) = (1/Z)e−s /kT .
7.13 Projects 269
7.13 Projects
Thermodynamics and Heat engines
8
271
272 8 Thermodynamics and Heat engines
8.1 Thermodynamics
f (P, V, N, T ) = 0 , (8.1)
where f () is some function. For the ideal gas, we know this function —
we know the equation of state:
P V − N kT = 0 . (8.2)
We will develop many similar equations of state for other systems through-
out this text.
State variables are path independent. It is important to notice that
any state variable depends on the state of the system, but not on how
the system got to this state. If we say that the energy E(S, V, N ) is a
state variable, we know that it is always the same for the same set of
values for S, V , and N , independent of how the system got there. This
is different for the work performed on a system or the thermal enegy
transfered to a system. These depend on how the system moves from
one state to another state, and are therefore not state variables.
Processes. Changes in the state of the system occur through processes,
which correspond to changes in the state variables of the system. We
can sketch such changes in various ways, as illustrated in Fig. 8.1. We
can describe the state of a system in P, V -space, as we will often do
for machines. The state of the system is then given by a pair P, V of
coordinates. (We have then typically assumed that N is constant). Or we
can describe the system in S, T space. A process is then a path from one
state to anther state in the system, as shown as lines in the sketch. The
two processes R1 and R2 which take the system from state 1 (P1 , V1 ) to
state 2 (P2 , V2 ) are shown in the figure. If we want to determine the work
done on the system in each of these processes we need to calculate the
integrals over the curves of P dV , so that the work for the two processes
are: Z Z
WR−1 = P dV , WR−2 = P dV , (8.3)
R1 R2
and these two work integrals are generally not equal. (For the given figure
they are clearly different, since the integrals correspond to the areas under
the P (V ) curves for the two processes). Also notice that a process does not
need to be described as function P (V ), but is more generally described
as a curve that may not have a one-to-one correspondence between P
and V or other state variables.
Reversible and irreversible processes. Processes may be reversible
or irreversible. A reverisible processes is just that: A process that can
274 8 Thermodynamics and Heat engines
R2
P2
2
V1 V2 V
be reversed. This must, for example, mean that the entropy change in
the process must be zero. For a reversible process there cannot be any
friction forces, since such forces would ensure that we do not return to
the same state if we reverse a process.
Quasi-static processes. Often, we want to specify processes where the
system is always very — infinitesimally — close to equilibrium. We
call such processes quasi-static processes. All reversible processes are
necessarily quasi-static. We must always be very close to equilibrium for
a process to be reversible. However, there can be quasi-static processes
that are not reversible, for example, processes where the internal friction
in the system is non-negligible.
8.2 Engines
V1 V2 V
P
2
TL TH TH TH
1 2 2 3
1
T=TH
3
T=TL 4 TH TL TL TL
V1 V2 V 3 4 4 1
Fig. 8.3 Illustration of an engine as a sequence of processes in a P -V -diagram.
P 2 P 2 P 2
3 3 Wnet 3
1 1 1
4 4 4
W2,3 W3,4 -W1,2 -W4,1
V V V
Fig. 8.4 Illustration of work done by the system on the environment for a complete cycle
of a machine.
The net heat is the sum of all the heats transferred in each subprocess.
The added heat corresponds to the sum of the positive heats (Q > 0).
We can apply the first law to a complete cycle. In this case, the change
in energy is zero, since the energy at the beginning and end of the cycle
must be the same since the energy is a state variable. Hence, the net
work must correspond to the net het added to the system: Wnet = Qnet
and ∆Enet = 0.
What is the efficiency, e, of this machine? It is reasonable to call the
efficiency how much work you get out for each unit of heat you put into
the system:
Wnet
e= . (8.6)
Qadd
We can calculate the efficiency of the machine we have described, by
inserting the values we have found for work and heat. We notice that the
added heat corresponds to the heat added in process 1 → 2 and 2 → 3,
280 8 Thermodynamics and Heat engines
• The heat source and heat sink are so large that their temperatures do
not change in this process.
We have so far defined the work done on the system as positive, but for
an engine we are usually more interested in the work done by the system.
We will therefore use the common convention QH , QL and W all are
positive. In this notation, the first law of thermodynamics is
∆E = QH − QL − W , (8.8)
where W is the net work done in a complete cycle, QH are all the heats
that are added to the system – this may occur in more than one of the
processs – and QL are all the heats that are removed from the system –
again this may occur in more than one processes. Notice that we have
changed the sign in front of the work, because the work W is now the
work done by the system on the environment. For a complete cycle, the
change in E must be zero, because E is a state variable and therefore
will be the same in the first and the last point in the cycle, because these
are the same states. The first law of thermodynamics for this system is
therefore
W = QH − QL , (8.9)
the net work W is equal to the net thermal energy (heat) added during
a complete cycle.
What is the efficiency of such as machine: It is what we get out (net
work) divided by what we put in (heat in QH ):
W
e= . (8.10)
QH
Ok. But what is the maximum efficiency we can get? It is limited by the
laws of thermodynamics. From the first law of thermodynamics, we see
that QH = W + QL . The efficiency is therefore:
QH − QL QL
e= =1− . (8.11)
QH QH
We can use the second law to relate QL and QH . From the second law
we know that
QH QL
dS = dSH + dSL = − + ≥0, (8.12)
TH TL
which gives:
282 8 Thermodynamics and Heat engines
QL TL
≥ . (8.13)
QH TH
and therefore
QL TL
e=1− ≤1− . (8.14)
QH TH
(Notice that we have here assumed that the heat is deposited to the low
temperature and taken from the high temperature). When the cycle is
reversible, we know that the equality holds, and in this case the efficiency
is:
TL
e=1− . (8.15)
TH
This is the maximum efficiency of an engine. A reversible engine of this
type is called a Carnot engine. Notice that this means that all engines
that operate between the same two temperatures (and that are reversible)
have the same efficiency – independent of how they are constructed.
However, in practice, no real engine reaches the theoretical efficiency,
and differences in the actual implementation is therefore important -
typical engines reach about 30-40% of the theoretical limit, often even
less.
T=TH
Q4,1=0
2
4
Q2,3=0
T=TL
3
N kT
p= (8.16)
V
for this curve.
Since the temperature is constant, and the energy U for an ideal gas
is linear in temperature, we know that dU = 0 for this process, hence
Q = W . The heat transferred is therefore given by the work:
V2 V2 1 V2
Z Z
W = pdV = N kT dV = N kT ln , (8.17)
V1 V1 V V1
(Notice, that you would have found the same by using that the heat is
Q = T dS for this process and that the entropy is S = N k ln V + f (N, U ),
which would give the same result for the heat).
We can draw the curve from 1 to 2 in a pV diagram, and notice that
the work is the area under the curve from 1 to 2.
Adiabatic expansion (2 → 3). Now, the gas is disconnected from the
bath at TH and thermally isolated - so that the work is given as the change
in internal energy of the system. The work done in this process is simple
to find from dU = Q + W , where now Q = 0, and therefore dU = W ,
where U = (3/2)N kT for a monatomic ideal gas and ((f + 3)/2)N kT
for a general ideal gas. The work is therefore simply
3
W23 = N k (TH − TL ) . (8.18)
2
What does the curve P (V ) look like for this process?
8.3 The Carnot cycle 285
QH = QL + W , (8.31)
which gives
QL 1
COP = = . (8.32)
QH − QL QH /QL − 1
8.5 Realistic model for Stirling Engine 287
What are the limits for the efficiency of a refridgerator? The second law
gives us:
QH QL QH TH
≥ ⇒ ≥ . (8.33)
TH TL QL TL
(Notice that the inequality is in reverse compare to before because the
entropy is flowing in the opposite direction). This gives:
1 TL
COP ≤ = . (8.34)
TH /TL − 1 TH − TL
The coefficient may be higher than 1 - indeed it will usually be. For
example, for a kitchen fridge we may have TH = 298K and TL =
255K, which gives COP = 5.9. Notice that COP goes to infinity as the
temperature difference goes to zero! Also notice that we can make a
Carnot cycle refrigerator - but this is not how things are done in practice
since the cycle would take too long time. We will address a few more
realistic processes in the following.
We can gain more insight into how real engines work by developing a
realistic model for a Stirling engine. Here, we will work on a model engine
used in teh 2.670 class at MIT, inspired by a report by M. Byl in 2002.
The Stirling engine we will model is sketched in fig. 8.7. This engine
consist of two connected chambers. One chamber on the left, where the
displacement piston is working. The volume of the gas in this chamber
remains constant throughout the process, but the portion that is in
contact with the hot temperature, TH , and the portion that is in contact
with the cold region, TL , varies in time. We will assume that the whole
gas has the same temperature T (t). This means that the temperature
will vary in time, but we assume that the temperature in the gas is the
same everywhere along the machine.
Let us start with a quantitative description of this machine. We will
assume that there is a constant transport of heat from the surrounding
reservoirs into the machine. There is a transfer of heat into the machine
in the hot region and a transfer of heat out of the machine in the cold
region. We will apply a simple law for heat conduction to estimate the
rate at which thermal energy is transferred to the gas. The heat transfer
from outside to inside the piston is proportional to the difference in
288 8 Thermodynamics and Heat engines
y(t) x(t)
T T T θ(t)
TH TL TL
Fig. 8.7 Illustration of a realistic Stirling engine using air as the gas medium.
with a proper choice of origin for θ. The position, y(t), of the displacer
cylinder should move with a phase difference of π/2, so that
where ymax is the maximum extension of the piston. If we know x(t) and
y(t), we can find the surface areas AH and AL for the thermal conduction.
At the hot end, the area AH only depends on the maximum possible
area, corresponding to the ymax multiplied with the circumference of the
8.5 Realistic model for Stirling Engine 289
where AH,max = A0 is the total surface area of the part of the large
cylinder that contains gas.
For the cold end we need to include the heat transfer from the large
cylinder and the transfer for the small cylinder:
where A1 (x) = A1,max x(t)/xmax is the area of contact for the small
cylinder to the right in the figure.
This means that in a short time interval ∆t, the change in (internal)
energy E of the gas in the system is
∆E = Q + W , (8.40)
d2 θ dθ
2
= F R cos θ − b . (8.46)
dt dt
We now have two equations, describing θ and E. In addition, we need
to be able to calculate T , V and P in the system. We can find V from
geometric considerations. The volume in the displacement cylinder is
constant, Vc , but the volume in the work cylinder depends on x:
V (t) = Vc + Ap x , (8.47)
where Ap x is the volume of the gas in the work piston. We can now find
the temperature through
E
E = CV T ⇒ T = , (8.48)
CV
where CV = cV m is the heat capacity for the gas in the cylinder. And
we find the pressure using the ideal gas law:
N kT 2E
P = = , (8.49)
V 5V
where we have used that E = (5/2)N kT for the gas at realistic tempera-
tures.
This completes the set of equations needed to determine the behavior
of the machine. We can now model the machine by integrating the
equations of motion for θ and the time development of E to find the
behavior of the machine in a P (V ) diagram.
First, we need to know the values of the parameters for a realistic
machine. We will use TH = 600K, TL = 300K, R = 1.25cm (radius
of flywheel), A0 = 40cm2 (surface area of active area of displacement
cylinder), Ap = 1.9cm2 (surface area of piston), A1,max /xmax = 4.9cm
(perimeter of the work piston cylinder), Vc = 40cm3 (volume of gas in
displacement cylinder), I = 4kg· cm2 , b = 0.7·10−3 N/s (damping constant
representing viscous processes), P0 = 105 Pa (trykk i omgivelsene), CV =
8.5 Realistic model for Stirling Engine 291
2.5 600
2
500
x [ c m]
T [K]
1.5
400
1
300
0.5
0 200
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
t [ s] t [ s]
2 2
1.8 1.8
1.6 1.6
P [ at m]
P [ at m]
1.4 1.4
1.2 1.2
1 1
0.8 0.8
40 41 42 43 44 45 2 3 4 5 6
3 T [K]
V [cm ] x 10
8
Fig. 8.8 Plots of the temporal behavior of the model Stirling engine.
W = dE − Q = dE − d(T S) = dF (8.50)
W 0 = dF + d(pV ) = dG , (8.52)
8.7 Summary
8.8 Exercises
the gas.
d) Calculate the numerical value for the speed of sound in air at 300 K
by using M ' 29 g/mol.
e) The speed of sound is closely connected to the average velocity, vavg ,
of molecules in a gas. Try to express vavg by R, T , and M and compare
with the speed of sound.
f) Discuss the difference between a sound wave that (hypothetically)
propagated as an isothermal process and one that propagated as an
isentropic process. How can you change the parameters of gas in order
to get a more isothermal process during sound propagation?
Adiabatic
A
p2 C
V2 V1 V
(V1 /V2 ) − 1
e=1−γ , (8.57)
(p1 /p2 ) − 1
where γ = Cp /CV .
8.9 Projects
Chemical potential and Gibbs
Distribution 9
299
300 9 Chemical potential and Gibbs Distribution
Particles can pass from A to B and the other way. This is similar to
the molecular dynamics model for the ideal gas where half the system
was empty. (Similar, but not identical, since our molecular dynamics
model was for constant energy and not constant temperature!). We can
characterize this sysytem by N the total number of particles in the
system, where NA + NB = N is constant, but NA and NB may vary.
NA → NA + dNA (9.1)
NB → NB + dNB = NB − dNA (9.2)
∂FA ∂FB
dF = dNA − dNA
∂NA V,T ∂NB V,T
! . (9.4)
∂FA ∂FB
= − dNA
∂NA V,T ∂NB V,T
This looks very similar to what we found for the canonical system. This
is the quantity related to particle transport which must be the same for
the two systems to be in diffusive equilibrium. This is the X we were
looking for!
Definition of chemical potential. We call this quantity the chemical
potential. Indeed, we will use this as the definition of the chemical
potential:
Chemical potential:
∂F
µ(T, V, N ) = , (9.6)
∂N V,T
or
µ(T, V, N ) = F (V, T, N + 1) − F (V, T, N ) . (9.7)
µA = µB . (9.8)
µ = F (N + 1, V, T ) − F (N, V, T ) , (9.9)
9.1 Chemical potential 303
which is the same as the definition above for large N . This definition
also emphasizes that:
This will occur until the chemical potential in the two systems are equal
and a further change in particles does not change Helmholtz free energy.
This effects makes intuitive sense since taking a particle from a part with
large chemical potential and transferring it to a part with lower chemical
potential will reduce the total Helmholtz free energy of the system and
therefore move the system towards equilibrium.
now we have defined this X as the chemical potential. The potential for
Helmholtz free energy is therefore
1
N
ZN = , (9.15)
1 − e−∆/kT
and
F = −kT ln ZN = N kT ln 1 − e−∆/kT , (9.16)
which gives
∂F
µ= = kT ln 1 − e−∆/kT . (9.17)
∂N
1 N
ZN = Z , Z = Ztrans Zvib Zrot , (9.18)
N! 1
3/2
where Ztrans = nQ (T ) V and nQ (T ) = 2πmkT /h2 for a three-
dimensional ideal gas. For a monatomic gas Zvib = Zrot = 1, and
Z1 = Ztrans . Helmholtz free energy is therefore:
µB > µA . If the two systems are placed in contact, particles will flow
from B to A.
How can we stop that flow? By changing the chemical potential, for
example by lifting one of the systems up in the gravitational field (if the
particles have masses). How does a change in potential energy change the
chemical potential? We can find out be addressing Helmholtz free energy
and then taking the derivative to find the chemical potential. Helmholtz
free energy consists of two parts, F = E − T S. We expect the energy
E of the system to depend on the position in a gravitational field. If
we lift an ideal gas from height z = 0 to a height z, this corresponds
to adding a potential energy u = mgz to all the particles. The energy
therefore depends on the height, E(z) = E(0) + mgz. However, if we
add a potential energy to the system, we only add a constant to all the
energy levels for all the particles, we do not change the distribtion of
energy levels. Therefore, we do not expect the entropy of the system to
change, S(0) = S(z). Helmholtz free energy is thererfore
A μA B μB A
0 0
Let us for simplicity assume that the atmosphere has the same tem-
perature T at all heights. (This is generally not true). The chemical
potential of gas at a height z is then
which gives
n(z) = n(0)e−mgz/kT . (9.28)
What does that mean for the pressure of an ideal gas? If the temperature
does not depend on height, the pressure is
N
pV = N kT ⇒ p = kT = nkT , (9.29)
V
and
p(z) = p(0) e−mgz/kT = p(0) e−z/zc , (9.30)
where zc = kT /mg is a characteristic height for the decay of the density.
Notice that the result depends on the mass of the gas molecules!
For N2 the mass of a molecule is 28 which gives zc = 8.5 km. Lighter
molecules will extend further up - and will mostly have escaped from the
atmosphere. Notice that T is not really constant, and n(z) is generally
more complicated. And also notice that various gases have different m,
and will therefore have different values of zc , which means that the
composition of the air will change with distance z as well.
i i
where Z is the partition function for the system without the potential
energy. We find Helmholtz free energy from the partition function
F 0 = −kT ln Z 0 = −kT ln e−N 0 /kT Z (9.32)
= −kT ln e−N 0 /kT − kT ln Z = N 0 + F , (9.33)
where F is Helmholtz free energy for the system without the potential
energy. The chemical potential of the system is then
∂F 0
µ =
0
= 0 + µ , (9.34)
∂N V,T
L x
We can use this to discuss how the chemical potential must develop as the
system approaches equilibrium. If the chemical potential is not constant,
as sketched in the figure, we can redure the total Helmholtz free energy
by moving a particle from a position with high chemical potential to a
position with low chemical potential. When we remove a particle from
a point, the decrease in F is the chemical potential at that point, and,
similarly, when we add the same particle to another point, the increase
in F is the chemical potential. If we remove a particle from a region
with high chemical potential and place it in a region with low chemical
potential, we therefore remove more from Helmholtz free energy than we
put back, hence the free energy is reduced. This process will continue
until the chemical potential is equal everywhere.
Another alternative to obtain equilibrium is to add an external poten-
tial, so that the total chemical potential is constant. For example, we
can add the external potential u(x) given as u(x) = u0 − µ0 (x), where
u0 is a constant and µ0 (x) is the initial chemical potential. The total
chemical potential is then:
which is a constant. In practice, we may not add any potential, but only
simple potentials such as a linear potential in the case of an electrical
potential difference for charged particles or a gravitional field for particles
with non-negligible masses.
9.2 Phase equilibrium at constant volume 311
μg
solid μs
Table 9.1 Symbols used to describe phase equilibrium between an Einstein crystal and
an ideal gas of the same particles.
Symbol Description
Approach. Our plan is the find the chemical potential for each of the
two subsystems. In equilibrium, the chemical potentials must be equal,
otherwise there would be a flow of particles from the part of the system
with high chemical potential towards the part with a low chemical
potential. We can calculate the chemical potential from Helmholtz free
energy, which is turn can be found from the partition function for each
of the two systems.
Helmholtz free energy for an ideal gas. We have previously found
that Helmholtz free energy for a gas in a volume Vg is
2πmkT
! 2
nQ
Fg = −Ng kT ln +1 , nQ (T ) = , (9.37)
ng h2
Here, we have written Nosc because this is the energy is for a given
number of oscillators and not a given number of particles. For a three-
dimensional system, each particle can oscillate in three different, indepen-
dent directions (x, y, and z), and the number of oscillators is therefore
Nosc = 3Ns , where Ns is the number of particles in the solid. Helmholtz
free energy for an Einstein crystal with Ns particles is therefore:
Fs = 3Ns kT ln 1 − e−∆/kT . (9.39)
Finding the chemical potentials. The chemical potentials for both the
gas and the solid can now be found from Fg and Fc :
!
∂Fg ng
µg (Vg , T, Ng ) = = kT ln , (9.41)
∂Ng Vg ,T
nQ (T )
and
∂Fs
µs (Vs , T, Ns ) = = 3kT ln 1 − e−∆/kT − 0 . (9.42)
∂Ns Vs ,T
In equilibrium we assume that the two chemical potentials are the same.
ng
µg (Vg , T, Ng ) = kT ln = µs (Vs , T, Ns ) = 3kT ln 1 − e−∆/kT −0 .
nQ (T )
(9.43)
We solve for ng , getting:
314 9 Chemical potential and Gibbs Distribution
ng = nQ (T )e3 1 − e−∆/kT e−0 /kT . (9.44)
From the ideal gas law for the gas, we know that pVg = Ng kT and
therefore ng = Ng /Vg = p/kT . We insert this to get an equation for the
pressure in the gas:
p(T ) = kT nQ (T )e3 1 − e−∆/kT e−0 /kT . (9.45)
μs>μg gas
Let us see if we can use the model and the chemical potentials to
understand what would happen if we instead of doing the experiment
at constant volume, did the experiment at constant pressure: Instead of
doing the experiment with a closed cup, we do the experiment inside a
piston, where the outside of the piston has a pressure corresponding to
the pressure in the lecture room. What would happen if we start the
9.3 Gibbs Free Energy 315
system on the p(T ) curve described by the model, and then increase the
pressure?
In the model, it is only the chemical potential of the gas that depends
on the pressure. And the chemical potential of the gas will increase if
we increase the pressure and decrease if we decrease the pressure. At
p(T ) the chemical potential in the gas and the solid is the same. If we
increase the pressure from this state, the chemical potential in the gas
will increase while the chemical potential in the solid remains constant
(this is in our model, not necessarily in the actual, physical system). As
a result particles will diffuse from the gas and into the solid – until all
the particles are in the solid. This means that the region above the p(T )
curve in the p − T diagram corresponds to a region where the whole
system is a solid. If we decrease the pressure, the chemical potential
in the gas will decrease while the chemical potential in the solid will
remain constant, hence all the particles will diffuse to the gas. The region
below p(T ) in the p − T diagram hence corresponds to a gas. The phase
coexistence curve is therefore the border between the solid and the gas
phases!
Now, there are a few problems with this argument. Primarily, the
problem is that we have described the system in terms of T , V , and
N , but the system we have sketched with the piston is not a system
with constant V , but rather a system with constant p. We therefore
need to introduce methods to address systems with constant T , p, N ,
including methods to find the equilibrium states in such systems. We
will therefore introduce the (T, p, N ) system and the corresponding free
energy — Gibbs free energy — before we return to the model system to
complete the discussion of the phase coexistence curve.
ΔE ΔV
pS ,TS
∂E
F =E− = E − TS . (9.46)
∂S V,N
Now, we want to introduce a new free energy with the natural variables T ,
p, N . We know that F has the variables T , V , and N and the differential
We would now like to replace pdV by some term which depends on dp. We
see that we can do this by adding pV to F , because the new differential
of d(F + pV ) will then not contain pdV , but instead a term V dp. If we
introduce G = F + pV then the differential of G is
dG = d (F + pV )
= dF + pdV + V dp
(9.48)
= −SdT − pdV + µdN + pdV + V dp
= −SdT + V dp + µdN .
9.3 Gibbs Free Energy 317
G(T, p, N ) = E − T S + pV , (9.49)
dG = −S dT + V dp + µ dN . (9.50)
We can therefore find the temperature, the volume and the chemical
potential from Gibbs free energy:
∂G ∂G ∂G
S=− ,V = ,µ = (9.51)
∂T p,N ∂p T,N ∂N T,p
Since the total energy and the total volume is conserved, we have that
This demonstrates that Gibbs free energy always decreases and is mini-
mum in equilbrium.
9.3 Gibbs Free Energy 319
This principle will turn out to be a vary powerful theoretical and practical
tool as we will see below.
where g(T, p) is the Gibbs free energy per particlem, which only depends
on the intensive variables T and p.
Notice that since T and p are intensive, this means that
G(T, p, N ) ∂G
g(T, p) = = = µ(T, p) . (9.62)
N ∂N T,p
k
dG = −T dS + V dp + (9.65)
X
µj dNj .
j=1
We can also for this expression for Gibbs free energy demonstrate that
Gibbs free energy for a system of k species is also minimum in equilibrium.
Notice that the species can be molecules or atoms of different types,
but it can also be atoms or molecules of the same type, but in different
phases, where the particles will have different chemical potentials.
We have now developed the basic tools needed to discuss the behavior of
a system at constant T , p, and N . This corresponds to the case where
we have a system of a given number of particles inside a box, but where
the volume of the box is varying while the pressure outside (and inside)
the box is constant. This is what happens in a system with a piston.
Now, we can address the same question as we did above for the T , V ,
and N system: What is the state of a system of particles, which may be
in several phases, inside a piston for a given set of T , p, and N values?
where gs (p, T ) = µs (p, T ) is the Gibbs free energy per particle in the
solid phase, that is for a particle in the crystal, and gg (p, T ) = µg (p, T )
9.4 Phase coexistence at constant pressure 321
is Gibbs free energy per particle in the gas phase. We can therefore look
for that state with the minimum of GT OT , as this will be the equilibrium
state. Alternatively, we realize that the minimum of GT OT occurs when
dGT OT = 0, and the differential of Gibbs free energy for a multi-species
system is
dG = −SdT + V dp + (9.67)
X
µj dNj .
j
This means that for a system with two species, where the total number
of particles is conserved, the chemical potential of the two species must
be identical in equilibrium. That is, we can use the same principle as we
found for a system at constant (T, V, N ).
Finding the equilibrium. Our plan is therefore to find Gibbs free energy
for each of the species, and use the expressions for Gibbs free energy to find
the chemical potentials, and from this find the equilibrium concentration
of gas and solid.
Gibbs free energy for the solid. For the crystal, we find Gibbs free
energy from
Gs (T, p, Ns ) = Fs (T, Vs , Ns ) + pVs , (9.70)
where Vs is the volume of the crystal. The volume does not appear in
Fs , but we will need an expression for Vs for the pVs term. We therefore
make a small addition to the ideal crystal (Einstein crystal) model: We
assume that there is a volume v0 associated with each crystal particle,
so that the volume of the crystal is Vs = Ns v0 . We insert the result
Fs (T, Vs , Ns ) = 3Ns kT ln 1 − e−∆ − Ns 0 (9.71)
Phase coexistence and Gibbs free energy. For this system, the pe (Te )
represents a singular region. It is only when the pressure and temperature
are exactly on this curve that there is co-existence between the two phases
in the system. If the system starts at the co-existence curve, and we
increase the temperature in the system, then the chemical potential in the
gas will be lower than the chemical potential of the crystal (or, similarly,
the Gibbs free energy per particle will be lower in the gas than in the
crystal), and the system will only contain gas particles. If we lower the
temperature from pe (Te ), all the particles will be in the crystal phase.
Behavior at the phase coexistence curve. Let us look at what happens
as we cross the coexistence curve. We start from a temperature that is
324 9 Chemical potential and Gibbs Distribution
lower that Te (for a given p), and then gradually (and slowly) increase the
temperature. As long as T < Te , the Gibbs free energy of the crystal will
be lower than the Gibbs free energy of the solid, and all the particles will
be in the solid phase until we reach T = Te . At this point, the number
of particles in the crystal and the gas phases are not known — they are
not determined by the minimum in Gibbs free energy! Any choise of Ns
and Ng (consistent with the condition that Ng + Ns = N ) will give the
same Gibbs free energy
Gtot = Ng gg + Ns gs , (9.80)
Q = ∆E + p∆V . (9.82)
v0
solid
We insert the ideal gas law for the ideal gas: pVg = Ng kT , which gives
Vg /Ng = kT /p. We insert this and Vs = Ns v0 , getting:
!
Ng kT Ns v0
w=p − = kT − pv0 . (9.85)
p Ng Ns
326 9 Chemical potential and Gibbs Distribution
Heat per particle for phase transformation. The heat added in order
to transfer a single particle from the solid to the gas phase is therefore
3 1
q = e + w = 0 − kT + kT − pv0 = 0 − kT − pv0 . (9.86)
2 2
Usually, we will assume that pv0 kT and we can therefore neglect the
last term.
This means that in order to transfer one particle from the solid to the
gas, we need to add a thermal energy q ' 0 − kT /2 to the system. This
seems reasonable, since we need to add the binding energy 0 , we need
to perform work against the external pressure in order to increase the
volume of the gas, and we gain energy due to the difference in degrees of
freedom for a solid and a gas particle.
Latent heat in simplified model. We call the heat added to the system
in order to transform one particle from solid to gas, the latent heat of the
system. The latent heat is usually given as the heat needed to transfer
one mole of the substance from one phase to another, and we use the
symbol L for the latent heat of the system or the symbol ` for the latent
heat per particle:
` ' 0 − kT /2 . (9.87)
Melting Evaporation
pe p=const
M B
SOLID
Triple point
GAS
Sublimation
Te T
LIQ
UI
D
LIQUID+GAS
GA
S
from Fig. 9.10. Heat will also in this case flow into the system from the
thermal bath in order to keep the system at the same temperature while
the system is expanding and particles are transferred from liquid to solid.
Notice that the pressure is a function of the volume, but that the volume
is not a function of pressure: There are many possible volumes for the
pressure pe .
Melting, evaporation, and sublimation. It is common to call the di-
agram in Fig. 9.9 a phase diagram, since it divides the p-T space into
regions that belong to different phases.
The various phase-transformation processes illustrated in Fig. 9.9
have different names. We call the transformation from a solid to a
liquid, melting. We call the tranformation from a solid directly to a
gas, sublimation, and we call the transformation from a liquid to a gas
evaporation.
Triple-point and critial point. We have also marked two other special
points in the p(T ) phase diagram in Fig. 9.9. The triple-point is the
temperature and pressure at which we have coexistence between all three
phases. We will return to methods to address the equilibrium near this
point below. The triple-point for water at a pressure of one atmosphere
is very close to 0◦ C, and this point is indeed used to define the kelvin
scale.
9.4 Phase coexistence at constant pressure 329
The critial point is the point in p, V, T space beyond which gases and
liquids are called supercritical, and there is no longer any phase transition
between a liquid and a gas. Various values for the critical temperatures
are listed in Table ??.
O2 154.3 K
H2 O 647.1 K
CO2 304.2 K
N2 126.0 K
H2 033.2 K
where gg , gl , and gs are the Gibbs free energy per particles for the gas,
liquid and solid phases, and Ng + Nl + Ns = N are the particles in the
gas, liquid and solid phases respectively.
In general, the three free energies will have different dependencies of
p and T . In Fig. 9.11 we have sketched the behavior of the Gibbs free
energies for a sample system. Just like for the simplified model, we know
that the system will be in the phase with the minimum Gibbs free energy
per particle. Phase coexistence occurs where the Gibbs free energies
per particle are equal: The evaporation transition (e) from gas to liquid
occurs for the pe , Te values where gg (pe , Te ) = gl (pe , Te ); and the melting
(m) transition from liquid to solid occurs where gl (pm , Tm ) = gs (pm , Tm ).
This provides us with a method to calculate the phase coexistence curves
if we know the Gibbs free energies for the various phases in the system.
In the following we use this to find the shape of the p(T ) curve without
knowing all the details of the underlying system.
330 9 Chemical potential and Gibbs Distribution
TM(p) TB(p) T
∂gl ∂gl
= vl , = −sl . (9.94)
∂p T ∂T p
where the small symbols indicate that the volume and entropy are per
particle. We insert this into (9.92), getting
Q = T ∆s = T (sg − sl ) = ` , (9.98)
` = T (sg − sl ) , (9.99)
where sg is the entropy per particle in the gas and sl is the entropy
per particle in the liquid phase.
Latent heat. It is common to describe the latent heat by the latent heat
for the evaporation of one mole and not one particle. The molar latent
heat is L = T (sg − sl ), where sg and sl are the entropies of one mole of
gas and liquid phase of the molecules. (If we use molar values for the
entropy or latent heat, we also need to use molar values for the volumes
v.) Notice that the latent heat is generally dependent on temperature:
L = L(T ). We can now rewrite (9.97) as
332 9 Chemical potential and Gibbs Distribution
Clausius-Clapeyron’s equation:
dp ∆s T ∆s L(T )
= = = , (9.100)
dT ∆v T ∆v T ∆v
where L(T ) is the (molar) latent heat for the transition and ∆v is
the (molar) volume change.
but since µg = µl the last term is zero. At constant pressure, the latent
heat is the heat T dS transferred, which is
and Z
H= Cp dT . (9.110)
We have so far used the ideal gas model as our canonical model for a
gas. But the model is limited — it does not contain any interactions
between the gas particles. How well does this model really describe a
real gas or a real liquid? We can test this by studying the behavior of a
334 9 Chemical potential and Gibbs Distribution
create_atoms 1 box
mass 1 1.0
velocity all create 0.1 87287
pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5
neighbor 0.3 bin
neigh_modify every 20 delay 0 check no
fix 1 all nvt temp 0.6 0.6 1.0
dump id all atom 100 vdw-coalesce01.lammpstrj
thermo 100
run 20000
specifies what region the fix is applied to. The three numbers 0.6, 0.6,
1.0 tells that the fix should change the temperature from T0 = 0.6 to
T1 = 0.6 over a simulation time corresponding to ∆t = 1.0, and then
continue with a fix at T1 = 0.6 from that time onward. This simulation
is therefore of a canonical system. Notice that it is also possible to model
systems at a constant pressure using special techniques that change the
volume of the system to keep the pressure (approximately) constant.
The resulting snapshots demonstrate that the model is able to model
the phase coexistence between a liquid and a gas — and indeed also
the non-equilibrium transition towards a stable equilibrium with a given
density of both fluid and gas.
Measuring the equation of state in a molecular model. We can use the
molecular dynamics model also to calculate the equation of state — the
relation between the pressure, volume, particle number and temperature
for a real gas with attractive as well as repulsive interactions. To do this,
we need to vary the temperature, the number of particles, and the volume
336 9 Chemical potential and Gibbs Distribution
0.8
Len n a r d -Jo n es
0.75 Id e a l g a s
Cl a u s i u s
0.7 va n d e r Wa a l s
0.65
0.6
P∗
0.55
0.5
0.45
0.4
0.35
Fig. 9.13 Plot of p(T ) as measured in molecular dynamics simulations using the Lennard-
Jones potential, for the ideal gas law, and for various modifications of the ideal gas law.
nQ (T ) V nQ (t)
FIG = −N kT ln + 1 = −N kT ln +1 . (9.112)
n N
In this equation, the volume only occurs once, and we can include the
excluded volume by replacing V → V − N b:
(V − N b)nQ (t)
FC = −N kT ln +1 . (9.113)
N
This model for a gas is called the Clausius model, and the corresponding
equation of state is found by calculating p as a derivative of F :
∂FC N kT
pC = − = . (9.114)
∂V T,N V − Nb
Clausius’ law:
pC = (N kT )/(V − N b) . (9.115)
We have plotted Clausius’ law in the same plot as the ideal gas law and
the observed behavior for p(T ). Clausius law is an improvement over the
ideal gas law, but there are still clear discrepancies. Let us now see how
we also can include the effect of attractive interactions.
Including the effect of attractive interactions. While Clausius law is
an improvement of the ideal gas model, it does not include the correct
shift, p0 , in pressure. We therefore need an additional term. Based on the
plot in Fig. 9.13 we see that the additional term must reduce the effective
pressure: The actual pressure must be lower than the pressure predicted
by Clausius law. What physical effect may cause this? Attraction between
the particles! We therefore need to include the effect of the attractive
part of the Lennard-Jones model. This will give rise to a binding energy
— a reduction in the energy and in Helmholtz free energy — when the
density is high.
Let us construct a simplified model for the attractive interaction
between the atoms. An atom in the gas will experience attractive interac-
tions from all the other atoms. The potential energy of this interaction is
the sum of the potential energies for all the other atoms. The potential
energy of atom i is
ui = ULJ (rij ) , (9.116)
X
j6=i
340 9 Chemical potential and Gibbs Distribution
a V b V-Nb c
b
b
b
b
b
b
b
b
Fig. 9.14 Illustration of attractive and repulsive interactions in a van der Waals gas.
a and b Illustration of the excluded volume N b , corresponding to a volume b for each
atom. c Illustration of the attractive interactions between the atoms. This gives rise to
an average binding energy.
where rij is the distance from atom i to atom j. However, since the
potential energy only depends on the distance, we can instead sum over
distances, but then we need to include the number of atoms at each
distance, which corresponds to the density of atoms measured around
atom i, ni (r) times the volume element dV :
Z
ui = ULJ (r)ni (r)dV . (9.117)
V
For each atom, the actual ni (r) will vary in time as all the other atoms
move about. Instead of calculating this integral for each atom, we will
assume that all atoms experience the same, avarage density n(r) as a
function of distance to the atom, and that this average density can be
written as n(r) = nφ(r), where n is the average density of the system and
φ(r) gives the variations relative to the average density. The potential
energy of atom i is then:
Z Z
ui = ULJ (r)nφ(r)dV = n ULJ φ(r)dV = −2an . (9.118)
V
|V {z }
=−2a
∂Fvdw N kT N 2a
p=− = − 2 , (9.121)
∂V T,N V − Nb V
(V − N b)nQ (T ) N2
Fvdw = −N kT ln +1 −a (9.123)
N V
Equation of state for the van der Waals system:
!
N 2a
p + 2 (V − N b) = N kT , (9.124)
V
The van der Waals model is described by two parameters, the excluded
volume b and the attractive interaction integral, a. First, let us see how
these parameters are determined, then let us see how we can describe the
342 9 Chemical potential and Gibbs Distribution
behavior of the system in a general way, where the details of the particular
parameters values only are included as dimensionless parameters.
Parameters for the Lennard-Jones system. How can we determine
the values of b and a for an actual gas? We can find these either from
experimental data, by simulations of more complicated fluids such as
water, or by theoretical considerations for simple fluids such as a Lennard-
Jones system. The actual values of a and b will be different for different
substances, and they may even vary for the same substance.
For the Lennard-Jones system we may estimate the values of a and
b. The excluded volume corresponds to a volume that is not available
for motion. This must be related to σ, the characteristic length of the
potential. We could assume that the excluded volume starts where the
potential is zero, that is for a volume of radius σ in the Lennard-Jones
potential. However, this is too large, since the atoms often may be
compressed into this zone. Instead, we will guess that the exluced volume
is one half of the volume corresponding to σ, that is
We can estimate a from the integral of the potential, assuming that the
density is constant, n(r) = n (φ(r) = 1):
∞ σ6 8π 3
Z
a' − 4πr2 dr = σ . (9.126)
σ/21/3 r6 3
This p(T ) curve for this set of parameter values are plotted in Fig. 9.13,
and the resulting model fits excellently to the data measured in molecular
dynamics simulations of the Lennard-Jones model.
(N b)2 a
!
V − Nb N kT
p+ = , (9.127)
V 2 b2 Nb Nb
(N b)2
!
a p V − Nb N kT
+ = . (9.128)
b2 a/b2 V2 Nb Nb
(V ∗ )2
!
p kT b2
+ (V ∗ − 1) = . (9.129)
p∗ V2 ab
Why did we introduce these reduced coordinates? Now, all the material-
specific details are in the characteristic values, whereas the equation of
state is general. We can therefore study general properties of the van der
Waals gas — properties that are valid for all van der Waals gases.
While the characteristic values p∗ , V ∗ , and T ∗ we have introduced
are very simple and lead to a simple equation of state in the rescaled
344 9 Chemical potential and Gibbs Distribution
p = 8.0/3.0*T/(V-1/3)-3.0/(V**2)
plot(V,p); hold(’on’)
xlabel(’V/V_c’); ylabel(’p/p_c’)
Where we have plotted p(V ) for values of T 0 = T /Tc that are below and
above 1 in Fig. 9.15.
p=pc
1
0.5
0
0.5 1 1.5 2 2.5 3 3.5 4
V =Vc
(V − N b)nQ (T ) N2
G = −N kT ln +1 −a + pV , (9.133)
N V
346 9 Chemical potential and Gibbs Distribution
Here, we will neglect the last term, since this only depends on T 0 and
will not influence the n0 that makes g 0 minimal.
In Fig. 9.16 we have plotted g 0 (n0 ; p0 , T 0 ) near the values p0 = 0.647
and T 0 = 0.9, which are on the phase coexistence curve. In Fig. 9.16a
we have varied the pressure p0 . If we start with a pressure below phase
coexistence, at p0 = 0.55, we see that Gibbs free energy has a clear
minimum at n0 = 0.315. This means that in equilibrium, the van der
9.5 Van der Waals fluid model 347
Waals gas will only contain a single phase with this density — a gas
phase.
However, if we increase the pressure, Gibbs free energy will go from
a configuration with only one minimum, to a configuration with two
(global) minimum values, here occuring for p0 = 0.647. For pressures just
below this value, there is only one minimum in Gibbs free energy, and the
whole system is a gas, but when the pressure reaches this value, there are
suddenly to minima at n01 = 0.42 and n02 = 1.65 so that g 0 (n01 ) = g 0 (n02 ).
We interpret this to mean that there are now two phases in the system,
one phase with a high density — a fluid phase — and one phase with
a low density — the gas phase. Notice that at this particular set of p0 ,
T 0 values, all the densities along the stapled line between n01 and n02 are
possible values for the density. When the density of the system is n01 it
means that all of the system is in the low density gas phase, whereas
when the density of the system is n02 all of the system is in the high
density liquid phase. If half of the system is in the gas phase, and half
is in the liquid phase, the density of the system is n0 = 0.5 n01 + 0.5 n02 .
This means that Gibbs free energy is the same value, and minimal, for
all densities n0 in the interval from n01 to n02 , and that the density is
determined by how much of the system is in the gas or in the liquid
phase. Gibbs free energy therefore has the form ge0 (n0 ; p0 , T,0 )
g (n ; p , T )
0 0 0 0
n0 < n01
ge0 (n0 ; p0 , T 0 ) g 0 (n1 ; p0 , T 0 ) n01 < n0 < n02 , (9.140)
g (n ; p , T )
0 0 0 0 n02 < n0
g=gc
-4
p'=0.550
p'=0.647
p'=0.750
-4.5
0 0.5 1 1.5 2 2.5
n=nc
-3.5
g=gc
-4
T'=0.85
T'=0.90
T'=0.95
-4.5
0 0.5 1 1.5 2 2.5
n=nc
point. Beyond the critical point, there is only a single phase in the system,
and there is no longer any phase coexistence or phase transition. This
is the reason for the choice of the numerical prefactors for pc and Tc , so
that the critical point occurs at (p0 , T 0 ) = (1, 1).
-4 p=0.80, T=0.38
p=0.90, T=0.65
p=0.95, T=0.81
p=0.98, T=0.92
p=0.99, T=0.96
-4.5
0 0.5 1 1.5 2 2.5 3
n0
Behavior of van der Waals gas below Tc . The full behavior of the van
der Waals gas system is address in project XX.
p(T ) and latent heat for the van der Waals gas.
However, we must also include the surface free energy, because this
tends to increase the energy of the liquid.
For a very small droplet, with a very small radius of curvature, the
surface energy will be dominating and the drop can be unstable with
respect to the gas/vapor.
Let us study this by addressing Gibbs free energy when a droplet of
radius R forms. We introduce
∆µ = kT ln(p/peq ) , (9.144)
9.5.6 Stability
350 9 Chemical potential and Gibbs Distribution
ams 10: If the gas starts in a local minimum in g(n), it may take some
time for the system to reach the global minimum. Metastability and
stability, supercooled and superheated water, heterogeneous nucleation,
glasses
9.6 Solutions
The systems we have been studying so far mostly only contain one type of
particles. The state of the system is described by the number of particles,
N , the pressure, p, the temperature, T , and possible also the volume in
the case of phase coexistence.
If we introduce another type of particles, we get a mixture or a solution.
There are many types of solutions: a solution may be a mixture of gases;
in a liquid we can dissolve gases or solids; in solids we can dissolve
gases, liquids or other solids. For example, hydrogen-gas can be dissolved
in palladium, or mercury can be dissolved in gold and in many other
metals; tin and zink can be dissolved in copper. Solutions are one of the
most important classes of systems for chemist, and our understanding of
solutions is important for our understanding of many problems of both
theoretical and practical importance.
We will here primarily study dilute solutions, which are where one
of the components are so dilute that they do not affect the energy of
the other component. Typical examples are trace gases in air or dilute
solutions in water.
Solution definitions:
• the component that is dissolved is called the solute
• the substance it is being dissolved in is called the solvent
• the resulting product is called the solution.
For example, salt water is a solution, made from a solvent, water,
and a solute, salt.
where gi0 (p, T, Ni ) is Gibbs free energy per particle for a system consisting
only of type i particles in the same box. (The superscript 0 indicates
352 9 Chemical potential and Gibbs Distribution
that this is the Gibbs free energy without any interactions). What is the
entropy of mixing?
A+B
Entropy of mixing. We can find the entropy of mixing from the multi-
plicity of mixing. For an gas or for a solid of N = i Ni particles, how
P
many ways can we rearrange the particles? We know that for two species,
1 and 2, the total number of ways that we rearrange N1 particles of type
1 and N2 particles of type 2 is
(N1 + N2 )!
!
N
Ω(N1 , N2 ) = = (9.147)
N1 N1 !N2 !
k
Smix /k = ln Ω = N ln N − N − (Ni ln Ni − Ni ) (9.149)
X
i=1
k k
= |{z}
N ln N − N − Ni ln Ni + (9.150)
X X
Ni
P
= Ni i=1 i=1
i | {z }
=N
k k
= Ni ln N − Ni ln Ni (9.151)
X X
i=1 i=1
k
Ni
=− Ni ln (9.152)
X
.
i=1
N
i=1 i=1
∂G
µi = (9.157)
∂Ni p,T,{Nj }
k
! !
∂G0i ∂ X
= + Nr ln xr (9.158)
∂Ni p,T,{Nj }
∂Ni r=1
p,T,{Nj }
k
1 ∂xr
= µ0i (p, T ) + kT ln xi + (9.159)
X
Nr
r=1
xr ∂Ni
k
∂xr X
= µ0i (p, T ) + kT ln xi + N xr (9.160)
∂Ni r=1
| {z }
=1
= µ0i (p, T ) + kT ln xi . (9.161)
where µ0i (p, T ) = gi0 (p, T ) is the chemical potential of the system when
only species i is present.
The chemical potential for component i is therefore only dependent
on xi = Ni /N = ni /n = mi , and not on the other xj values. The only
dependence on the other atoms is through the N in the denominator of
xi = Ni /N . We can check the consistency of the expression by noticing
that for x1 = 1 we only have the pure substance, and µ1 = µ01 , as it
should.
The ideal mixture approximation is versatile. This simple expression
for the chemical potential is an approximation to case of a general
mixtures. We call this approximation the ideal mixture approximation.
This approximation is versatile. It is clearly applicable to ideal gases,
where there are no interactions between the particles, but it is also a
reasonable approximation to many other systems. It is well demonstrated
the the ideal mixture approximation is:
• almost exact for mixtures of isotopes
• good for mixtures of similar molecules
• very good for the solvent in dilute solutions
• reasonably good for use in chemical equilibriums
Let us now see how we can address an ideal mixture of ideal gases.
Solution of ideal gases. Mixtures of ideal gases are ideal mixtures,
since there are no interactions between the particles in the gas. For a
multi-component gas, with Ni particles (atoms/molecules) of species i,
the total number of particles is N = i Ni . The pressure of the gas is
P
9.6 Solutions 355
k k
N kT Ni kT
p= = = (9.162)
X X
pi ,
V i=1
V i=1
For an ideal gas the fraction xi can be expressed in terms of the partial
pressure: xi = Ni /N = Ni kT /N kT = pi V /pV = pi /p, which gives the
following expression for the chemical potential of species i in a mixture
of ideal gases:
i
= N (1 − x)g10 (p, T ) + N xg20 (p, T ) + N kT ((1 − x) ln(1 − x) + x ln x) ,
(9.165)
(illustrated by the red line). The total Gibbs free energy is clearly smaller
when the system is mixed due to the effect of the entropy of mixing.
2 0.8
0.6
1.5
0.4
G
S
1
0.2
0.5 0
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
x x
Fig. 9.19 Plots of the Gibbs free energy for a mixed (blue) and an unmixed (red) system.
where µ01 (p, T ) was the chemical potential of the solvent before the solute
was added. Notice that this means that the chemical potential of the
solvent therefore becomes lower after the solute is added.
Chemical potential for the solute in a dilute solution.
ams 11: May add derivation of this?
9.6 Solutions 357
solvent solvent+solute
∂G N0
µl = = gv (T, p) − kT . (9.170)
∂Nl T,p,Ng ,N 0 Nl
Here, we now insert p = p0 + ∆p, and we approximate gv (T, p0 + ∆p)
with its first order Taylor expansion, and similarly for gl (T, p0 + ∆p):
∂gg
µg (p0 + ∆p, T ) = gg (p0 + ∆p, T ) = gg (p0 , T ) + ∆p , (9.171)
∂p T
and similarly
N0 ∂gl N0
µl (p0 +∆p, T ) = gl (p0 +∆p, T )−kT = gl (p0 , T )+ ∆p−kT ,
Nl ∂p T Nl
(9.172)
We introduce x = N 0 /Nl , where x 1. We notice that
∂gl ∂gg
= vl , = vg , (9.173)
∂p T ∂p T
We can find the derivative of the chemical potential from the derivative
of Gibbs free energy, because µ0s = G0s /N , and therefore
1
! !
∂µ0s ∂G0s V
= = = vs0 , (9.180)
∂p T,N,x
N ∂p T,N,x
N
that is, the volume per particle in the pure solute. This gives
V
µ0s (p2 ) ' µ0s (p1 ) + ∆p (9.181)
N
which we can insert into (9.178), getting
V
µ0s (p2 ) ' µ0s (p1 ) + ∆p = µ0s (p1 , T ) − kT x , (9.182)
N
and therefore
N kT n N kT NB NB kT
∆p = − =− =− , (9.183)
V VN V
where B represent the solute. This pressure difference is called the os-
motic pressure. And the equation describing the osmotic pressure of
a dilute solution is called van’t Hoff’s formula. This means that the
pressure difference needed corresponds to the pressure in an ideal gas
with the concentration NB /V of the solute.
This pressure can be quite significant for realistic, biological systems.
For example, for a cell there are about 200 water molecules for every
molecule of some other type – this is therefore a dilute solution. Since
the atomic weight of water is 18u, the number of water molecules in a
liter of water (1 kg) is
1kg
Ns = , (9.184)
18 · 1.66 · 10−27 kg
and the pressure in a gas of Ns /200 particles in 1 liter is
9.7 Chemical reactions 361
N kT (1/200)Ns kT
p= =
V 0.001m3 (9.185)
1.38 · 10−23 J/K · 300K
= = 6.9N/m2 .
200 · 18 · 1.66 · 10−27 · 0.001m3
The pressure difference between the inside and the outside of a cell in
equilibrium with pure water is therefore approximately 7 atm – which is
high!
If the pressure difference is smaller than the osmotic pressure, molecules
from the pure solvent will flow through the membrane and into the so-
lution. However, if the pressure difference is larger than the osmotic
pressure, the pressure will drive the solvent from the solution and into
the pure solvent. This process is, not surprisingly, called reverse osmo-
sis and currently represents one of the best techniques for desalination
(removing salt from seawater) to make freshwater. Making good mem-
branes for this process is an area of great current technological and
industrial interest.
H+ + OH− ↔ H2 O , (9.186)
+ 1 H+ + 1 OH− − 1 H2 O = 0 , (9.188)
that is
ν1 = 1 , A1 = H+ , ν2 = 1 , A2 OH− , ν3 = −1 , A3 = H2 O . (9.189)
i=1
i=1
dG = µj dNj = µ j νj = 0 . (9.192)
X X
j j
We can determine this condition for any reaction if we only know the
chemical potential µj for each of the species. (Notice that this relation is
derived for constant p and T , but it also applies to the equilibrium of
reactions at constant T and V ).
Gibbs-Duhem relation. Notice that it is usual to call the relation
j
9.7 Chemical reactions 363
µi = µ0i + kT ln xi , (9.195)
i i i
which gives
ln xi = − (9.197)
X X
kT µ0i νi .
i i
where ∆G0 is the change in Gibbs free energy for the reaction – which is
the hypothetical change in G when one mole of H2 reacts with one mole
of OH− , forming one mole of water at 1 bar. This value of ∆G0 you can
usually find in reference tables. If we take the exponential on both sides,
we find
∆G0
xi i = e− RT = K(T ) , (9.199)
Y ν
where K(T ) is only a function of T – and you can often find the value
of ∆G0 in chemical tables. The constant K is usually knows as the
equilibrium constant – and we see that we can acually calculate the value
of K(T ) if we know the chemical potentials µ0i for all the components in
the reaction.
For ideal gases, the relation can be rewritten in terms of the concen-
trations, ni = Ni /V , instead:
Y Ni νi Y Ni kT νi
xνi i = =
Y
i i
N i
N kT
νi Y Ni νi kT νi (9.200)
Y Ni kT
= = = K(T ) ,
i
pV i
V pV
which gives
364 9 Chemical potential and Gibbs Distribution
Y Ni νi K(T )
= Q νi = K1 (p, T ) . (9.201)
i
V kT
i pV
H2 ↔ 2H , (9.202)
H2 − 2H = 0 , (9.203)
H2 O ↔ H+ + OH− , (9.208)
pH = − log10 H+ . (9.211)
A + B ↔ AB , (9.212)
A + E ↔ AE , AE + B ↔ AB + E , (9.216)
and
G(T, p, N ) = N µ(T, p) . (9.218)
T dS = dU + pdV − (9.224)
X
µj dNj ,
j
dG = −SdT + V dp + (9.225)
X
µj dNj .
j
% LJ MD calculation
clear all; clf;
L = 10; % Number of atoms = L^2
N = L*L;
rho = 0.8; % reduced density
Temp = 0.1; % reduced temperature
nsteps = 10000;
dt = 0.02;
printfreq = 1;
% Initial coordinates on cubic grid
r = zeros(N,2);
v = zeros(N,2);
[x y] = meshgrid((0:L-1),(0:L-1));
r(:,1) = x(:); r(:,2) = y(:);
% Rescale to wanted rho
L = L*(1.0/rho^2); r = r*(1.0/rho^2);
% Initialize with wanted T
v = sqrt(Temp)*randn(N,2);
% Internal variables
dt2 = dt*dt;
force = zeros(N,2);
9.8 Old Stuff 369
ir2 = 1.0/r2;
ir6 = ir2*ir2*ir2;
ir12 = ir6*ir6;
% Calculate force from i-j interaction
fij = (2*ir12-ir6)*rij*ir2;
ff(i,:) = ff(i,:) + fij;
ff(j,:) = ff(j,:) - fij;
% Calculate energy from i-j interaction
enij = (ir12-ir6);
en = en + enij;
end
end
en = en*4;
energy = en;
ff = ff*24;
force = ff;
return
9.9 Summary
9.10 Exercises
9.11 Projects
Fermi and Bose gases
10
371
372 10 Fermi and Bose gases
are both constants. Let us now at a particular case where system S has
NS particles and is in a state i with energy i . (Notice that the states
and the energies of the states depend on the number of particles in the
system). How can we find the probability for this state?
TR
ΔE ΔN
TS
Fig. 10.1 Illustration of a system S in contact with a reservoir R, where the system is
allowed to exchange both energy and particles with the reservoir.
We therefore get
NS µR i
k ln ΩR = SR (N − NS , E − i ) ' SR (N, E) + − , (10.6)
TR T
and therefore the multiplicity is
NS i NS i
374 10 Fermi and Bose gases
ZG (T, V, µ) = (10.11)
XX
e(N µ−i )/kT .
N i
N i
Notice that both the energy, E, and the number of particles, N , now
are fluctuating quantities, but for macroscopic systems the values will
typically be sharp.
For example, the average number of particles is:
1 XX
hN i = N e(N µ−i )/kT . (10.13)
ZG N i
10.1 Gibbs factor and Gibbs sum 375
Following exactly the same arguments are above, the probability for a
state with Nj particles of each of the species and for a state i of this
system is
1 (
P
Nj µj −i )/kT
P (i, N1 , N2 , . . . , Nk ) = (10.17)
X
e j ,
ZG (N1 ,N2 ,...,Nk )
We demonstrate the use of Gibb’s sum for both a single species and for
several species through the following example.
376 10 Fermi and Bose gases
ZG = e| (0 µ−0)/kT
{z } + e| {z } .
(1 µ−)/kT
(10.19)
(N =0) (N =1)
10.1 Gibbs factor and Gibbs sum 377
We see that this function includes the chemical potential, µ. But we have
not been given a value for µ. How can we find this? We assume that in
the lungs, the blood is in diffusive equilibrium with the air in the lungs,
and we can therefore use the chemical potential for an ideal gas, where
we know that the density of O2 molecules can be related to the partial
pressure of O2 using the ideal gas law: pV = N kT , and N/V = p/kT ,
hence
when T = 310K, which is the temperature in your body, and p = 0.2 atm,
which is the partial pressure for oxygen. This gives
NO NCO i
0 0 0
1 0 O
0 1 CO
ZG = e(0 µO +0 µCO −0)/kT + e(1 µO +0 µCO −O )/kT + e(0 µO +1 µCO −CO )/kT .
(10.23)
378 10 Fermi and Bose gases
When we discussed the ideal gas we assumed that quantum effects were
not important. This was implied when we introduced the term 1/N ! for
the partition function for the ideal gas, because this term only was valid
in the limit when the number of states are many compared to the number
of particles.
Now, we will address the general case of a quantum gas. The concepts
and methods we introduce here will be important for your understanding
of applied problems in quantum mechanics, such as electrical conducitiv-
ity, solar power cells, thermo-electric materials, neutron stars, and many
other processes.
The system we will study is a system of non-interacting particles in a
box of size L × L × L = V . For a single particle in a box, we know that
the possible translational states of the particle have energies
2
~2 π
(nx , ny , nz ) = n2x + n2y + n2z
2m L (10.27)
=a n2x + n2y + n2z = an ,
2
where
10.2 Fermi-Dirac and Bose-Einstein distribution 379
~2 π 2 h2
a= = , (10.28)
2m L 8mV 2/3
and m is the mass of the particle. The three positive integers nx , ny ,
nz enumerates all the possible states of the system. That is, the state
of one particle in a box is given by (nx , ny , nz ), where nx = 0, 1, 2, . . .,
ny = 0, 1, 2, . . ., nz = 0, 1, 2, . . ..
This describes a the states of a single particle in a box. However, if
we have many particles in the same box, we need to address whether
two particles can occupy the same quantum state in the system. This
depends on the type of particle:
• For Fermions (1/2 spin) Only 0 or 1 fermion can be in a particular
state.
• For Bosons (integer spin) Any number of bosons can be in a particular
state.
Given this condition, we will assume that there are no other interactions
between the particles and that they can occupy any of the possible
quantum states of the system.
How can we find the thermodynamics of this system using a statistical
physics approach? We will apply a simplification that allows us to address
each state separately: Let us assume that we study a grand-canonical
system, that is, we will assume a system at constant temperature, T ,
volume, V , and chemical potential µ. We will then use a “trick” – we
will look only at a single state in the system, find the probability that
this state is occupied, and then sum the occupation numbers of all states
to find the total number of particles in the system and the total energy
of the system.
Let us first look at a system of Fermions with spin 1/2, such as
the electrons in an electron gas. In this case, there can only be one
particle in each state. However, for each translational state given by
(nx , ny , nz ) we will have 2 spin states, σ = ±1/2. Let us pick one such
state, (nx , ny , nz , σ) with energy (nx , ny , nz ) ( For example, the state
(1, 0, 1, −1/2) with energy = a(12 + 02 + 12 ) = 2a). We study the
occupancy of this state using the Gibbs sum approach. The Gibbs sum
is the sum over the possible number of particles in this state, and for
each number of particles, we sum over all the possible states of the
system given this number of particles. In this case these sums are simple.
The system may have either N = 0 particles or N = 1 particle. For
N = 0 the system consisting of the state (nx , ny , nz , σ) can only have
380 10 Fermi and Bose gases
one possible energy – zero. For N = 1, the energy of the system is simply
(nx , ny , nz , σ), which we write at for short. The Gibbs sum is therefore
1 X
ZG = e−(s(N ) −N µ)/kT
X
N =0 s(N )
(10.29)
= e−(0−0µ̇)/kT + e−(−1µ̇)/kT
= 1 + e−(−µ)/kT .
N =0
1 −(−µ̇)/kT
=0·1+1· e
ZG (10.31)
e−(−µ)/kT
= −(−µ)/kT
e +1
1
= (−µ)/kT .
e +1
This quantity – the average number of particles in a state (nx , ny , nz , σ)
– is called the Fermi-Dirac distribution function:
1
N̄(nx ,ny ,nz ,σ) = fF D (; µ, T ) = . (10.32)
e(−µ)/kT + 1
Because the average number of particles in a state (nx , ny , nz , σ) only
depends on the energy of this state, and not on any other details of the
state, we write the average number as a function of the energy of the
state alone.
What does the average number of particles – the Fermi-Dirac distri-
bution function – look like? First, let us look at the functional form. We
see that if we introduce x = ( − µ)/kT , the functional form is
1
f (x) = , (10.33)
ex + 1
10.2 Fermi-Dirac and Bose-Einstein distribution 381
What happens when T = 0? We see from the plots that the function
approaches a step function that goes from 1 to 0 at the chemical potential.
We call the chemical potential at T = 0 the Fermi energy:
F = µ(T = 0) . (10.34)
At T = 0 all the states up to the level F are occupied – and none of the
levels above F are occupied. Later on we will see how we can relate F
to the number of particles N in the gas.
1
Notice that here the chemical potential is a given, constant, whereas further on, we
will assume that the number of particles is constant instead, and the calculate a chemical
potential that will depend on T , V , and N .
382 10 Fermi and Bose gases
0.8
f ( ϵ; µ , T )
0.6
0.4
0.2
0
−10 −8 −6 −4 −2 0 2 4 6 8 10
( ϵ − µ ) /k T
1 kT = 5. 0 · ϵ
kT = 1. 0 · ϵ
kT = 0. 2 · ϵ
0.8
f ( ϵ, µ , T )
0.6
0.4
0.2
0
−20 −15 −10 −5 0 5 10 15 20
ϵ/µ
Fig. 10.3 Plot of Fermi-Dirac distribution.
N =0 s(N )
∞
= e−(N s −N µ)/kT (10.35)
X
N =0
∞
1
= e−N (s −µ)/kT =
X
,
N =0
1− e−(s −µ)/kT
10.2 Fermi-Dirac and Bose-Einstein distribution 383
where the sum is the well-known geometric series. The average number
of particles in state s is
XX N
N̄s = e−(s(N ) −N µ)/kT
N
Z
s(N ) G
1 X
= N e−(N s −N µ)/kT
ZG N
1 X
= N e−N (s −µ)/kT (10.36)
ZG N
1 X ∂ −(s −µ)N/kT
= kT e
ZG N ∂µ
∂
= kT ln ZG ,
∂µ
where we have used a usual “trick” by introducing the derivative and
taking it outside the sum. The result is
1
N̄s = fBE (s ; µ, T ) = . (10.37)
e(s −µ)/kT −1
Because the distribution only depends on the energy s of the state s of
the particle-in-box system, it is common to simply write the distribution
is a function of . We have plotted the Bose-Einstein distribution along
with the Fermi-Dirac distribution in figure 10.4.
% Plot FD
kt = 1.0;
legarray = [];
x = linspace(-10,10);
f = 1.0./(exp(x/kt)+1);
plot(x,f)
hold all
legarray = [legarray; ’FD’];
x = linspace(0.4,10);
f = 1.0./(exp(x/kt)-1);
plot(x,f)
legarray = [legarray; ’BE’];
x = linspace(-1.0,10);
f = exp(-x/kt);
plot(x,f)
legarray = [legarray; ’C ’];
xlabel(’(\epsilon-\mu)/kT’);
ylabel(’f(\epsilon, \mu,T)’)
legend(legarray);
ax = axis();
ax(4) = 2.0;
384 10 Fermi and Bose gases
axis(ax);
2
FD
BE
C
1.5
f (ϵ, µ, T )
1
0.5
0
−10 −5 0 5 10
(ϵ − µ)/k T
Fig. 10.4 Plot of Bose-Einstein distribution.
We have plotted all the distributions functions in the same plot in fig. 10.4,
where we see that all the distribution functions are indistinguishable for
large values of ( − µ)/kT .
Let us now compare this result with our results for a classical ideal
gas in a canonical system, where the chemical potential is a function of
T, V, N : µ = µ(T, V, N ). Since we have now addressed the system using
the Gibbs formalism, the (average) number of particles in the system
is a function of T , V , and µ, N̄ = N̄ (T, V, µ). How can we compare the
two results? We can calculate the average total number of particles, N̄ ,
as a function of the chemical potential in the T, V, µ system, and then
solve the resulting equation to find the chemical potential as a function
of the average total number of particles. (We may not always be able
to solve this equation analytically, but we may then resort to numerical
methods and still save the day).
For a given chemical potential, µ, the total average number of particles,
N̄ , is the sum of the average number of particles in each state, s, summed
over all possible states s:
s s
The last sum is the sum over all states, s, for a particle in a box.
We recognize this as the one-particle partition function, Z1 , for the
translational motion of one particle in a box:
N̄ = eµ/kT Z1 , (10.41)
For an ideal gas - that is for a particle in a box - we found that the
one-particle partition function is
Z1 = nQ V , (10.43)
where
386 10 Fermi and Bose gases
mkT 3/2
nQ = , (10.44)
2πh2
was called the quantum concentration. The chemical potential is therefore
where n̄ = N̄ /V .
N̄ = f (s ; µ, T ) , (10.46)
X
where the sum is over all the states for a single particle in a box.
However, we are usually instead interested in understanding the be-
havior in a system with a given number, N , of particles and not a given
chemical potential. How can we transform the results we have for a given
chemical potential to a system with a given number of particles? Since
we know how to calculate the (average) number of particles, N̄ , in a
system, we can simply find the chemical potential, µ(V, T, N ), for which
the average number of particles, N̄ , is equal to the number of particles,
N : N̄ = N . From a more practical point of view, this means that we
first calculate N̄ = N̄ (T, V, µ) for a given µ, and then find µ from the
equation
N = N̄ = N̄ (T, V, µ) . (10.47)
s s
where the sum is over all the states s of the system. The states of a
particle in a box are given as (nx , ny , nz , σ). We can sketch the states in
the nx , ny , nz space as illustrated in fig. 10.5. We see that for each set of
integers nx , ny , nz we have two states. If we look at a “volume” ∆V =
∆nx ∆ny ∆nz in this space, we know that ∆nx = ∆ny = ∆nz = 1 we will
have 2 states in this volume (as long as the volume is in octant where nx ,
ny , and nz all are positive). We can therefore introduce a density of
states in the nx , ny , nz -space: D(nx , ny , nz ) so that the number of states,
∆N , in the volume from nx , ny , nz to nx + ∆nx , ny + ∆ny , nz + ∆nz is
Fig. 10.5 Illustration of the states of a particle in a box. Each vertice of a voxel represents
a single state. The three figures illustrates the states that are below nF for nF = 3, 7, 11.
388 10 Fermi and Bose gases
which means that the energy only depends on the distance n from the
origin in nx , ny , nz -space. The condition that ≤ F therefore corresponds
to
≤ F
an2 ≤ F (10.52)
r
F
n≤ = nF .
a
To find the number of states with ≤ F we must therefore count the
number of states in the nx , ny , nz -space with n ≤ nF , that is, we must
count all the states inside a sphere with radius nF .
Let us follow two approaches to find the number of states in this
volume. First, we simply use that the denstiy of states in nx , ny , nz -space
is uniform, and that the number of states therefore is the volume of the
sphere with radius nF multiplied with the density of states which is 2,
taking into account that only positive values of nx , ny , nz . Using this
argument, the number of states inside nF is
1 4π 3 π 3
N̄ = 2 · VF = |{z}
2 · · nF = n . (10.53)
8 |3{z } 3 F
2 spins |{z}
nx ,ny ,nz >0 volume of sphere
s s
N̄ = f ((nx , ny , nz ); µ, T ) . (10.55)
XXXX
nx ny nz σ
If we assume that the sum will be over many states, we can approximate
this sum by an integral over (nx , ny , nz ), where we also must include the
10.3 Fermi gases 389
density of states:
ZZZ
N̄ = f ((nx , ny , nz ); µ, T )D(nx , ny , nz )dnx dny dnz . (10.56)
From this equation, we see that we can interpret πn2 as the density of
states in n-space (which here is different from nx , ny , nz -space): D(n) =
πn2 .
This integral can be easily solved:
nF πn3F
Z
N̄ = πn2 dn = . (10.60)
0 3
This is, of course, the same as we found in (10.53).
Solving for the chemical potential. We insert nF = F /a to find the
p
3N̄
!
3/2
a3/2 = F , (10.62)
π
h2
a= , (10.64)
8mV 2/3
which gives
!2/3 !2/3
3N̄ 3
2/3
h2 h2 N̄
F = = . (10.65)
π 8mV 2/3 8m π V
where D(n) is the density of states in the n-space and D(n)dn gives the
number of states in the interval from n to n + dn.
10.3 Fermi gases 391
How can we solve this integral? We will work more with this in general
in the following, but for the T = 0 case, the integral reduces to a simple
form because f (; µ, T = 0) = 0 when n > nF and 1 otherwise. The
integral therefore becomes:
Z nF
Ē = an2 D(n)dn , (10.68)
0
(10.72)
Similarly, we find the average energy from a similar integral:
Z ∞
Ū = 2(nx , ny , nz )f ((nx , ny , nz ); µ, T ) = (n)f ((n); µ, T )D(n)dn ,
X
(10.73)
10.3 Fermi gases 393
as the density of states in space. The quantity D()d gives the number
of states with energies between and + d.
Let us find the density of states in energy space for the three-
dimensional gas. We find it using the integral transformation we in-
troduced above:
D(n)dn = D()d , (10.78)
and therefore
1
D(n()) = D() , (10.79)
d/dn
where we now use that
2
~ π
(n) = n2 = an2 , (10.80)
2m L
and therefore we find:
n = (/a)1/2 , (10.81)
and that
d
= 2an , (10.82)
dn
which we insert in (10.79) to get
394 10 Fermi and Bose gases
1
D() = D(n)
d/dn
1
= πn2
2an
π
= n
2a r
π
= (10.83)
2a a
π
= 3/2 1/2
2a
π(8m)3/2 √
= V
2h3
3N √
= 3/2 .
2F
The nice thing about this expression is that it can be interpreted in
the same plot - in the same space as we say here - as the distribution
function f . This is illustrated in fig. 10.6, where we have plotted both
the density of states D(), f (; µ, T ) and their product in the same plot.
2
f (ϵ)
f ( ϵ, µ , T ) , D ( ϵ)
D (ϵ)
1.5 f ·D
0.5
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
ϵ/ϵ F
Fig. 10.6 Plot of the density of states, D(), the number of particles in a state with
energy , f (; µ, T ), and their product for kT = 0.25 · F .
10.3.3 Behavior at T = 0
We can use fig. 10.6 to gain more insight into the system at T = 0. In
this case, the distribution function f (; µ, T ) is a step function with the
step at F . We can therefore think of what happens at T = 0 in a slightly
different way: We can assume that we have a given number of particles
10.3 Fermi gases 395
N . These particles will fill up all the states, starting with the states with
the lowest energy first. Since two particles cannot occupy the same state,
we fill in the density of states, D(), function starting from = 0 and
then up to F , as illustrated in fig. 10.7. In this case, it is simple to find
the average number of particles – it is the area under the D() curve
from 0 to F :
Z ∞
N̄ = f (; µ, T )D()d
0
Z F
= D()d
0
F
r (10.84)
π
Z
= d
0 2a a
π 1 2 3/2
= √ ,
2a a 3 F
for µ(T ). What does this integral represent? It represents the area
under the curve f (; µ, T ) · D() as illustrated in fig. 10.7. Since the
area corresponds to the number of particles, and we assume that the
number of particles is conserved, the area must be conserved when the
temperature is increased from T = 0.
What happens as T is increased? Some of the particles in the states
below the chemical potential (area A) are moved into states above the
chemical potential (area B) as illustrated in fig. 10.7. However, the
number of particles removed from states below the chemical potential
396 10 Fermi and Bose gases
f ( ϵ, µ , T ) , D ( ϵ)
2.5
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
ϵ/ϵ F
3
f ( ϵ, µ , T ) , D ( ϵ)
2.5
2 A
1.5
0.5
B
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
ϵ/ϵ F
Fig. 10.7 (Top) At T = 0 all the states up to F are filled. (Bottom) For T > 0 the
particles in the states in area A have been moved into the the states B with higher energies
for kT = 0.25F .
(area A), must be equal to the number of particles added to states above
the chemical potential (area B) in order for the number of particles to
remain constant.
Now, if we assume that the chemical potential µ does not change when
T is increased, we see that area B will be larger than area A because
D() is an increasing function and f (; µ, T ) is symmetric around = µ.
This is illustrated in the magnification shown in fig. 10.8. The top figure
shows what happens if we assume that the chemical potentia µ(T ) = F
also when T > 0. In this case the area B is larger than the area A. This
is not that easy to see from the figures, since the differences are rather
small.
How should µ(T ) depend on T in order to increase the area A and
decrease the area B? To get this argument right, it is important to realize
what areas we really are to compare. We have illustrated this in the
bottom figure in fig. 10.8. Here we have illustrated the chemical potential
by the dotted line. The chemical potential is smaller than F in this
10.3 Fermi gases 397
figure. We have also illustrated the relevant areas: It is the area below
F and above F we should compare. (Not the area below and above µ –
can you see the difference?). At T = 0 the area below D() corresponds
to the number of particles in the system.
In the top figure in fig. 10.8 we have argued that area B is slightly
larger than area A. In the bottom figure in fig. 10.8 we see that area A
is clearly larger than area B. This means that the correct value for µ lies
somewhere between µ = F in the top figure and µ = 0.99 · F in the
bottom figure. This means that µ must be smaller than F , but not as
small as illustrated in this figure.
Conclusion: µ(T ) must be a decreasing function of T near T = 0.
f ( ϵ, µ , T ) , D ( ϵ)
0
0.9 0.92 0.94 0.96 0.98 1 1.02 1.04 1.06 1.08 1.1
ϵ/ϵ F
f ( ϵ, µ , T ) , D ( ϵ)
2 A
1
B
0
0.9 0.92 0.94 0.96 0.98 1 1.02 1.04 1.06 1.08 1.1
ϵ/ϵ F
f ( ϵ, µ , T ) , D ( ϵ)
2 A
1
B
0
0.9 0.92 0.94 0.96 0.98 1 1.02 1.04 1.06 1.08 1.1
ϵ/ϵ F
Fig. 10.8 Plot of f (; µ, T = 0) · D() (top), f (; F , T = 0.1TF ) · D() (middle), and
f (; µ, T = 0.1TF ) · D() (bottom) where TF = F /k.
398 10 Fermi and Bose gases
df (; µ(T ), T ) ∂f ∂f dµ
= + . (10.88)
dT ∂T ∂µ dT
This gives
Z ∞ ∂f dµ
Z ∞ ∂f
CV = D()d + D()d . (10.89)
0 ∂T dT 0 ∂µ
dN̄ ∞ ∂f Z
= D()d , (10.91)
dT 0 ∂T
Z ∞ ∂f dµ ∞ ∂f
Z
0= D()d + D()d . (10.92)
0 ∂T dT 0 ∂µ
(Where we have used that (dN̄ /dT ) is constant, since the number of
particles in the system does not change when we change the temperature
if the number of particles is constant). Up to now we have not done any
approximations. Now, we see that f is a rapidly varying function of
around µ:
∂f e(−µ)/kT
= 2 . (10.93)
∂µ e(−µ)/kT + 1
10.3 Fermi gases 399
∂F ( − µ) e(−µ)/kT
= . (10.98)
∂T kT 2 e(−µ)/kT + 1 2
3N 1 3 1
D(µ) ' D(F ) = = , (10.101)
2 F 2 N kTF
and therefore
1 T
CV ' π 2 N k = aN T , (10.102)
2 TF
where kTF = F , that is, TF = F /k, and a is a constant that does
not depend on N or T . A typical values for TF for an electron gas is
TF ' 5 · 104 K.
This long derivation shows that the heat capacity due to an electron
gas (or another Fermi gas) is proportional to T at low temperatures (T
small compared with TF ).
Let us now use the theory we have developed to address the behavior of
a photon gas - a system with electromagnetic waves inside a container –
in equilbrium with the container walls. In this case the walls will absorb
and emit electromagnetic wave (packets) - so the number of photons is
not conserved.
For a container of length L, we assume that the field only consists of
standing waves (in equilbrium). These waves can therefore have frequen-
cies f = c/λ and corresponding energies = nhf = n~ω, where n is an
integer corresponding to the state.
(The integer n comes from the number of half-wavelengths that make
up the length L: L = (n/2)λ, where n is an integer.)
This corresponds to the harmonic oscillator we have already studied.
We will now study the occupancy probability for these states. We can
assume that the system has constant volume V and temperature T , and
that since photons are continually created and destroyed - the chemical
potential for the system is therefore zero.
We can then use the Bose-Einstein distribution law:
1
fBE (, µ, T ) = , (10.103)
e(−µ)/kT −1
which we can simplify since µ = 0 to
1
fBE (, µ = 0, T ) = , (10.104)
e(/kT −1
10.4 Photon Systems 401
which is the same as we found for the harmonic oscillator in the canonical
ensemble.
This tells us the occupancy of a given energy level s . In addition we
need to know the density of states for the photon gas.
For particles (fotons) in a box, the possible (standing wave) solutions
are
2L hn
λ= , , (10.105)
n 2L
where n is a positive integer. The energy of the photon is
hcn
= pc = ~ω = , (10.106)
2L
instead of = p2 /2m for classical particles.
This means that the energy of a photon generally is proportional to n
while the energy of a classical moving particles (in an ideal gas / Fermi
gas) is proportional to n2 .
This is also true in three dimensions, where the momentum is inde-
pendent in the three direction, and equal to hc n/2L in each direction:
hc
p= (nx , ny , nz ) , (10.107)
2L
and the energy still is = pc, where p is the magnitude of p:
hc 2 1/2 hcn
= nx + n2y + n2z = . (10.108)
2L 2L
In order to use the distribution function, we need to sum over all
possible states (and their corresponding energies) to find the number of
photons and the total energy of the photon gas.
Let us first look at the total energy - which we find by summing over
all possible n-values - including the effect of two possible polarizations:
nx ny nz
8π(kT )4 L3 ∞ x3
Z
U= dx , (10.111)
(hc)3 0 ex − 1
U 8π 5
= (kT )4 . (10.112)
V 15h3 c3
This is called the Stehan-Boltzmann law of radiation.
We can also find the frequency (or energy, since they are propotional
= hν) distribution of the photon gas / blackbody radiation.
What does that mean? We can find for example how many photons are
in the range from ν to ν + dν, how many photons are in the range from
to + d - or preferrably – how much energy is in the corresponding
range of frequencies / energies: We find this as the number of photons in
the range multiplied by the energy per photon, .
We can read this directly from the integral, realizing that the integral
for the total energy can be written as
Z ∞ Z ∞
U= n D(n)dn = D()d , (10.113)
0 0
8π 3
u() = . (10.117)
(hc)3 e/kT − 1
We can express it instead using ν where = hν:
10.4 Photon Systems 403
8πhν 3 1
u(ν) = dν . (10.118)
c3 ehν/kT − 1
This is called the Planck radiation law.
We can plot this distribution in dimensionless form by plotting x3 /(ex −
1) as a function of x = /kT .
This function has a maximum at x = 2.82, which corresponds to
= 2.82 kT .
This shows that the maximum energy (or frequency) increases with
temperature. This law is called Wien’s law. (Wien’s displacement law).
This law implies that the temperature can been seen from the most
prominent color - since the frequency of this this color is proportional to
the temperature. (If we can consider the body we examine as blackbody
radiation).
dU 4aT 3
T dS = dU , dS = = , (10.119)
T T
which we integrate from 0 to T , getting:
1 32π 5
3
kT
S(T ) = 4a T 3 = V k. (10.120)
3 45 hc
(We can find the total number of photon using the same formula, but
with a different prefactor).
dE udV uAcdtg
J= = = = ucg . (10.121)
Adt Adt Adt
and
cU 2π 5 (kT )4
J= = = σT 4 , (10.122)
4V 15 (hc)3
where σ is called the Stefan-Boltmann constant.
And the law is called Stefan’s law.
This is from a black body - non-reflecting! - body with surface tem-
perature T .
Applications: Cosmic black body background radiation, Emission and
absorption (Kirchoffs law).
collective modes that have lower energy. Therefore the heat capacity goes
to zero slower than predicited by the Einstein model.
The vibration modes in a crystal resembles electromagnetic waves:
They are waves, but they have smaller velocities (much smaller of
course). We will here assume that the speed is a constant cs - even if it
acutally depends on the wave length in a crystal.
They have three polarizations. The transverse and one longitudinal.
The polarizations really have different velocities. At first we will ignore
this effect.
The waves cannot have all possible wavelengths, because the atoms
are on a lattice with a given lattice spacing, and we cannot resolve waves
with wavelength shorter than (two times) the lattice spacing.
Let us assume that we can otherwise describe a phonon - a lattice
vibration mode energy packet - just as we have described photons: with
uniformly spaced energy levels:
hcs hcs n
s = hν = = , (10.124)
λ 2L
where L is the system size. Again n is the magnitude of the n vector in
n-space.
We also assume that phonons are bosons with µ = 0, so that the
distribution function is given by the Bose-Einstein distribution:
1
fBE = . (10.125)
e/kT − 1
We find the energy and the number of phonons by summing over all
possible n values:
nx ny nz
The main difference with the crystal lattice is that not all values are
possible - we can only have some values for n.
Let us look at the x-direction.
Along this direction we have Nx = (N )1/3 atoms as shown in the
figure.
This puts at limit on the maximum upper number of n.
This should correspond to a cube in n-space.
The Debye approximation is to assume that we instead include all
modes up to a radius nD in n-space, but so that we ensure that the total
number of modes is equal to 3N :
406 10 Fermi and Bose gases
3 nD
Z
3 = 4πn2 dn = 3N , (10.127)
XXX
nx ny nz 8 0
U= n f (n , µ = 0, T )
XXX
nx ny nz
(10.130)
3 nD 2 hνn
Z
= n dn ,
8 0 exp(hνn /kT ) − 1
where
hcs n
hνn = . (10.131)
2L
The integral is therefore
3π nD hcs n3
Z
U= dn . (10.132)
2 0 2L exp(hcs n/2LkT ) − 1
6N
1/3
hcs nD hcs TD
xD = = = , (10.133)
2LkT 2kT πV T
where we call TD the Debye temperature.
This gives - after some algebra:
9N kT 4 TD /T x3
Z
U= dx . (10.134)
TD3 0 ex − 1
This integral cannot be solved analytically, but it is easy to solve numer-
ically.
However, we can also find the high and low temperature limits directly
by approximations.
10.5 Phonon Systems 407
In the high temperature limit the upper bound of the integral is much
smaller than 1 and in this limit we can approximate ex = 1 + x, and the
integral becomes
9N kT 4 TD /T x3
Z
U= dx
TD3 0 x
9N kT 1 (10.135)
4 3
TD
=
TD3 3 T
= 3N kT .
3π 4 N kT 4
U= , (10.136)
5 TD3
and the heat capacity in this limit is
12π 4
3
T
CV = Nk , (10.137)
5 TD
which agrees very well with experimental measurements.
We find the intermediate values by numerical integration.
For metals we need to include both the contribution from the phonos
and the contributions from the electrons, so that the heat capacity has
the behavior:
12π 4 N k 3
CV = γT + T , (10.138)
5TD3
when T TD and γ = π 2 N k 2 /2F .
If we now plot CV /T as a function of T 2 we can check both constants
in the resulting plot, which should be linear in T 2 with an intercept
corresponding to γ.
What are typical values for TD ?
For lead 88K
For diamond 1860K
Above TD you can get away with using the equipartition theorem since
the heat capacity by then has reached 95% of its maximum value.
408 10 Fermi and Bose gases
h2 2
= n + n2
+ n 2
, (10.139)
8mL2 x y z
3h2
0 = , (10.140)
8mL2
which is a very small value for realistic (macroscopic) values of L.
The Bose-Einstein distribution gives the average number of atoms in
this state:
1
N0 = , (10.141)
exp((0 − µ)/kT ) − 1
As the temperature approaches zero, we know that N0 will be large,
which means that exp((0 − µ)/kT ) − 1 must be close to 1. This means
that the exponent is close to zero. In this limit, we can expand the
exponent using exp(x) = 1 + x, getting:
1 kT
N0 = = , (10.142)
1 + (0 − µ) /kT − 1 0 − µ
and therefore that µ = 0 when T = 0 and then just a bit larger when T
is small.
To make life simpler, let us change energy scales, so that 0 = 0. The
result is then
kT kT
N0 = − , µ=− . (10.143)
µ N0
The energy is
h2 2
= n + n2
+ n2
(10.144)
8mL2 x y z
the energy difference between the lowest and the second lowest is therefore
3h2
∆ = (10.145)
8mL2
Now if we look at Helium-4, m = 6.6 × 10−24 g and L = 1cm, then
∆
= 1.8 × 10−14 K . (10.146)
k
This is a small splitting!
How could this play an important physical role at temperatures which
are Kelvin or at best a thousands of a Kelvin?
10.6.2 Approaching T = 0
What happens if we have a constant particle number, N , and we lower
the temperature? Then the number of particles in the lowest leverl, N0 ,
approaches N - all the particles are in the state with the lowest energy.
This means that
1
N0 = , (10.147)
exp((0 − µ)/kT ) − 1
Since 1 also is very small ( 1 ' 0) and g(0) = 0, we can instead put
0 as the lower bound for the integral. In addition, we still assume that
410 10 Fermi and Bose gases
µ = 0: Z ∞ g()d
N = N0 , (10.150)
0 e/kT − 1
where we now insert for g():
2 2πm
3/2
√
g() = √ V , (10.151)
π h2
and we introduce the variable x = /kT . The integral is then reduced to
2 2πmkT
3/2 ∞ x1/2 dx
Z
N = N0 + √ V , (10.152)
π h2 0 ex − 1
where the integral is
√
∞ x1/2 π
Z
dx = · 2.612 = 2.315 , (10.153)
0 e −1
x 2
and therefore we find
2πmkT
3/2
N = N0 + 2.612 V . (10.154)
h2
This expression is only valid for low temperatures, but the second term
increases with temperature. What is the upper limit of validity of this
expression? That is when N0 is zero and all the particles are in higher
energy levels, this occurs at a temperature TC given by:
2πmkTC
3/2
N = 2.612 V , (10.155)
h2
which gives
1
2/3
h2 N
kTC = . (10.156)
π(2.612)2/3 2m V
The critical temperature TC therefore depends both on details of the
particles, through m, and on the density N/V of the system. (for low
temperatures).
We can also use TC to rewrite the expression for N :
3/2
T
N = N0 + N , (10.157)
TC
which gives
10.6 Boson Gas and Einstein Condensation 411
3/2 !
T
N0 = N 1 − . (10.158)
TC
In the range T < TC we have Bose-Einstein condensation. At T = 0 all
the particles are in the lowest energy state.
What happens when T < TC ? In this case our calculation is no longer
valid. Instead we must include how the chemical potential varies with
temperature. We can do this by solving the equation
Z ∞ g()
N= d , (10.159)
0 e(−µ)/kT −1
numerically. We introduce new variables, x = /kTC , t = T /TC and
c = µ/kTC , and get the integral
∞ x1/2 dx
Z
2.315 = , (10.160)
0 e(x−c)/t − 1
which you now know how to solve.
References
413
Index
415
416 INDEX
uncorrelated, 61
uniform distribution, 100
unit cell, 34, 38
universal distributions, 98