chapter 4 monte carlo methods and simulation. monte carlo methods

49
Chapter 4 Monte Carlo Methods and Simulation

Upload: christina-underwood

Post on 03-Jan-2016

360 views

Category:

Documents


17 download

TRANSCRIPT

Page 1: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Chapter 4

Monte Carlo Methods and Simulation

Page 2: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Monte Carlo Methods

Page 3: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Introduction of Monte Carlo

1. Monte Carlo methods have been used for centuries.

2. However during World War II, this method was used to simulate the probabilistic issues with neutron diffusion (first real use).

3. Named after the capital of Monaco (one of the world’s center for gambling), due to the similarity to games of chance.

4. Otherwise known as the random walk method.

Page 4: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 5: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Solve mathematical problems:

• Multi-dimensional integrals• Integral equations• Differential equations• Matrix inversion• Extremum of functions

Disadvantages

• Time consuming.• Doesn’t give exact solution.• Is the model correct?• Bugs, bugs, bugs.

Page 6: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Consider particle transport through matter

Three possible methods

• Direct Experiment– Sometime virtually impossible– Very expensive / time consuming

• Theoretical– Solve complex equations subject to interface & boundary conditions– Often need approximations

• Monte Carlo– Use basic physics laws and probabilities– Minimal amount of approximations– Since a statistical method, can require large amounts of computer time

Page 7: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

What is Monte Carlo

Monte Carlo methods are a class of algorithms that rely on repeated random sampling to compute their results.

Monte Carlo Methods use Statistical Physics techniques to solve problems that are difficult or inconvenient to solve deterministically.

Non Monte Carlo methods typically involve ODE/PDE equations that describe the system.

Monte Carlo methods are stochastic techniques. (process involving a number of random variables depending on a variable parameter)

It is based on the use of random numbers and probability statistics to simulate problems.

Something can be called a Monte Carlo method if it uses random numbers to examine the problem it is solving.

Page 8: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Components of Monte Carlo simulation

Probability distribution functions (pdf's) - the physical (or mathematical) system

must be described by a set of pdf's.

Random number generator - a source of random numbers uniformly distributed on

the unit interval must be available.

Sampling rule - a prescription for sampling from the specified pdf's, assuming the

availability of random numbers on the unit interval, must be given.

Scoring (or tallying) - the outcomes must be accumulated into overall tallies or

scores for the quantities of interest.

Error estimation - an estimate of the statistical error (variance) as a function of the

number of trials and other quantities must be determined.

Variance reduction techniques - methods for reducing the variance in the

estimated solution to reduce the computational time for Monte Carlo simulation

Parallelization and vectorization - algorithms to allow Monte Carlo methods to be

implemented efficiently on advanced computer architectures.

Page 9: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Probability Density Function

A probability density function (or probability distribution function) is a function f defined on an interval (a, b) and having the following properties:

Page 10: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Uses for Random Numbers

In Monte Carlo calculations, we usually have to take random samples of certain quantities with definite distributions.

For this reason, the random number we use should follow the same distribution.

For example, in a one-dimensional Monte Carlo integration, we wish to sample the variable of integration with uniform probability within the integration limits. For this purpose, we need random numbers with a uniform distribution.

A simple way to obtain a random integer is to read the timer, or systemclock, on the computer we are using.

Another interesting way to produce random integers is the middle-squaremethod of von Neumann. If we square an integer consisting of severaldigits, both the most significant digits and the least significant digits arepredictable. However, it is more difficult to predict the digits in the middle.For example, if we square an integer of three digits,

(123)2 = 15,129

Page 11: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

the result is a five-digit integer.

By chopping off the leading and trailing digit, we obtain the number 512.

If we square this number and retain only the third, fourth, and fifth digits, we obtain the number 214. In this way, a sequence of random integers can be obtained, each constructed from the square of the previous one with only the middle part of the digits retained.

Although this method has been in use for a long time, it is no longer apreferred way to generate random integers. Tests have shown that thereare many ways such a sequence can develop into a bad direction. Forexample, if for any reason a member of the sequence becomes zero, all theremaining members of the sequence will obviously be zero.

(123)2 = 15,129

15,129

(512)2 = 262144

(214)2 = 45796

Page 12: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

The linear congruence method

The most popular way to generate random integers with a uniform distribution is the linear congruence method. In this approach, a random integer Xn+1 is produced from another one Xn through the operation

Xn+1 = (aXn + c) mod m

where the modulus, m, is a positive integer. The multiplier a and increment c are also positive integers but their values must be less than m. To start off the sequence of random integers X0, X1, X2, ..” we need to input an integer X0, generally referred to as the seed of the random sequence.

Page 13: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

As a simple example of a Monte Carlo simulation, consider calculating the probability of a particular sum of the throw of two dice (with each die having values one through six). In this particular case, there are 36 combinations of dice rolls:

Based on this, you can manually compute the probability of a particular outcome.  For example, there are six different ways that the dice could sum to seven.  Hence, the probability of rolling seven is equal to 6 divided by 36 = 0.167.

A Simple Example: Rolling Dice

Page 14: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Instead of computing the probability in this way, however, we could instead throw the dice a hundred times and record how many times each outcome occurs. 

If the dice totaled seven 18 times (out of 100 rolls), we would conclude that the probability of rolling seven is approximately 0.18 (18%).

Obviously, the more times we rolled the dice, the less approximate our result would be. Better than rolling dice a hundred times, we can easily use a computer to simulate rolling the dice 10,000 times (or more).

Because we know the probability of a particular outcome for one die (1 in 6 for all six numbers), this is simple.  The output of 10,000 realizations (using GoldSim software):

Page 15: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Finding PI

Area of circle in 1st quadrant:

0X

Y

R=1

1

1

24 r

A

Equation for a Circle:(centered at the origin)

Area of a Circle:

PI Equation:

222 ryx

2rA

2r

A

Page 16: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

• We can determine PI by finding the area, A, for a given radius, r.• This is equivalent to integrating the equation of the circle as follows:

2 2

0

( )b r

a

A f x dx r x dx= = -ò ò

Rejection Method

X

Y

A1

CB

y

x0

1

Finding PI

Page 17: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Algorithm Guts:• Initialize a counter for the area.• Select a “x”.• Select a “y”.• Calculate x2 + y2.• If this value is less than r2, increment area counter.• Repeat sampling

Finding PI

Page 18: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Simulation Process

Read simulationparameters

Start

Initialize positionsof all particles

New simulation?

Read oldconfiguration

Monte Carloloop

Stop

yes no

Monte Carlo loop Subroutine

Start

Stop

Trial move

Satisfy Metropolis

rule?

Accept thetrial move

Update energyand virial

Sample thepressure

End ofsimulation?

yes

no

yes

no

Main program

Page 19: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Program to compute Pi using Monte Carlo methods /* Program to compute Pi using Monte Carlo methods */

#include <stdlib.h>#include <stdio.h>#include <math.h>#include <string.h>#define SEED 35791246

main(int argc, char* argv){ int niter=0; double x,y; int i,count=0; /* # of points in the 1st quadrant of unit circle */ double z; double pi;

printf("Enter the number of iterations used to estimate pi: "); scanf("%d",&niter);

/* initialize random numbers */ srand(SEED); count=0; for ( i=0; i<niter; i++) { x = (double)rand()/RAND_MAX; y = (double)rand()/RAND_MAX; z = x*x+y*y; if (z<=1) count++; } pi=(double)count/niter*4; printf("# of trials= %d , estimate of pi is %g \n",niter,pi);}

Page 20: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 21: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 22: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Monte–Carlo Integration

Advantages

• Evaluates integrals based on a selection of random samples in the integration domain

• Works no matter how complex the function to be integrated is (even discontinuous)• Does not even require the a priori knowledge of the integrand!

Theorem (Mean Value Theorem for Integrals): If f(x) is continuous over [a, b], then there exists a number c, with a < c < b, such that

1( ) ( )

b

af x dx f c

b a

( ) ( ) ( )b

af x dx b a f c

Page 23: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Often we are faced with integrals which cannot be done analytically. Especially in the case of multidimensional integrals the simplest methods of discretisation can become prohibitively expensive. For example, the error in a trapezium rule calculation of a d–dimensional integral falls as N-2/d� , where N is the number of different values of the integrand used. In a Monte–Carlo calculation the error falls as N-1/2 independently of the dimension. Hence for d > 4 Monte-Carlo integration will usually converge faster.

We consider the expression for the average of a statistic, f(x) when x is a random number distributed according to a distribution p(x), then

( ) ( ) ( )f x p x f x dx

Page 24: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

which is just a generalisation of the well known results for (e.g. ) <x> or <x2>, where we are using the notation <> —Žto denote averaging. Now consider an integral of the sort which might arise while using Laplace transforms.

This integral can be evaluated by generating a set of N random numbers, {x1,..........xN}, from a Poisson distribution, p(x) = exp(x), and calculating the mean of f(x) as

The error in this mean is evaluated as usual by considering the corresponding standard error of the mean

0

exp( ) ( )x f x dx

1

1( )

N

ii

f xN

22 21( ) ( )

1f x f x

N

0 2 4 6 8 10

0.0

0.2

0.4

0.6

0.8

1.0

exp(

-x)

x

Page 25: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Example:  Let   .  

Use the Monte Carlo method to calculate approximations to the integral   .

2

4( )

1f x

x=

+1

2

0

4

1dx

x+ò

0.0 0.2 0.4 0.6 0.8 1.00

1

2

3

4

5

6 2

4( )

1f x

x=

+

]

1

2

0

1

0

4

1

4arctan 4arctan1 4arctan 0 4 04

I dxx

I xp

p

=+

= = - = - =

ò

Page 26: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 27: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 28: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

The Metropolis Algorithm

In statistical mechanics we commonly want to evaluate thermodynamic averages of the form

where Ei is the energy of the system in state i and = 1/kT . Such problems can be solved using the Metropolis et al. (1953) algorithm.

i

i

Eii

E

i

y ey

e

Page 29: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 30: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Choose an initial configuration of N spins. (E.g. take all the spins to be +1 initially)

Pick a spin at random and compute the energy difference ΔE, that would occur if the spin were flipped.

Calculate W, the transition probability for that flip.

Draw a random number, r, uniformly distributed between 0 and 1.

For ΔE<0 accept the flip. For ΔE>0,  accept the flip if r<W otherwise reject the flip and retain the original microstate In any case, the configuration of the spins obtained in this way at the end of step 5 is counted as a "new configuration".

Analyse the resulting configuration as desired, store its properties to calculate the necessary averages.

Page 31: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods
Page 32: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Lattice spin model with nearest neighbour interaction. The red site interacts only with the 4 adjacent yellow sites.

If there are N sites on the lattice, then the system can be in 2N states. The energy state of the system (Hamiltonian) can be written in terms of the products of the spins and interaction with an external magnetic field, if present. The Partition function then is proportional to sum over all the possible states of the system on the exponential of the Hamiltonian.

Page 33: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

where Pi is the probability of finding the system in state i and Ti→j is the probability (or rate) that a system in state i will make a transition to state j. Eq. can be rearranged to read

Generally the right-hand-side of equation is known and we want to generate a set of states which obey the distribution pi. This can be achieved by choosing the transition rates such that

( )j iE Ei j j

j i i

T pe

T p

( )

1

j i

j i j i

E Ei j

j i j i

if p p or E ET

e if p p or E E

Let us suppose the system is initially in a particular state and we change it to another state j. The detailed balance condition demands that in equilibrium the flow from i to j must be balanced by the flow from j to i.

This can be expressed as i i j i j ip T p T

Page 34: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

This method is not the only way in which the condition can be fulfilled, but it is by far the most commonly used.

An important feature of the procedure is that it is never necessary to evaluate the partition function, the denominator in (8) but only the relative probabilities of the different states. This is usually much easier to achieve as it only requires the calculation of the change of energy from one state to another.

Note that, although we have derived the algorithm in the context of thermodynamics, its use is by no means confined to that case.

In practice if pj < pi, a random number, , is chosen between 0 and 1and the system is moved to state j only if the ratio is less than pj /pi ore−(Ej−Ei).

Page 35: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Ferromagnetism arises when a collection of atomic spins align such that their associated magnetic moments all point in the same direction, yielding a net magnetic moment which is macroscopic in size. The simplest theoretical description of ferromagnetism is called the Ising model. This model was invented by Wilhelm Lenz in 1920: it is named after Ernst Ising, a student of Lenz who chose the model as the subject of his doctoral dissertation in 1925.

The Ising model

Ernst Ising 1900-1998

Born in Cologne, Germany on May 10, 1900, died in Peoria, IL, USA on May 11, 1998. Obtained his PhD at age 24 but dismissed from job when Hitler came to power.Became school teacher, immigrated to Luxembourg but soon fled to USA. Known as an excellent teacher. He published just a few physics papers. Between 1966-2000, at least 16,000 articles with contents related to the Ising model published.

Page 36: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

magnetic dipole moments randomly aligned in

a paramagnetic sample

magnetic dipolemoment (Spin)

magnetic dipole moments randomly aligned in

a ferromagnetic sample

magnetic dipole moments randomly aligned in

a antiferromagnetic sample

Above TC a ferromagnet becomes a paramagnet

http://cp3-origins.dk/content/movies/2013-10-25-1200-arthur.pdf/#/9

Page 37: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

•Named after the physicist Ernst Ising who did it in 1920s

•It is a mathematical model in statistical mechanics

•It has since been used to model diverse phenomena in which bits of information,

interacting in pairs, produce collective effects

•Serious applications include complicated models of ferromagnets, fluids, alloyds,

interfaces, nuclei, subnuclear particles•For us we will use it to model the behavior of a ferromagnet, just a single domain within it.•We will account for the tendency of neighboring dipoles to align parallel to each other while neglecting interactions between dipoles

•Notation: For spin-up () we have si = 1 and spin-down () we have si = −1

•The energy due to interaction: − if parallel and + if anti-parallel

Page 38: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

We write the energy as

which is negative if parallel and positive if anti-parallel.

To predict the thermal behavior we need the partition function

For N dipoles the number of terms in the sum is 2N.

In 1D it is possible to solve by hand as shown by Ingemar in the lecture.

In 2D you can find exact solution but it is complicated. Solved in 1940s by LarsOnsager, a Norwegian who won The Nobel Prize in Chemistry 1968. Can youimagine working with a 10 × 10 lattice which has 2100 ~ 1030 possible states?!

NO exact solution ever found in 3D we need approximations!

,

i jneighbouringpairs i j

U s s

U

All possible sets ofdipole alignments

Z e

Page 39: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

The Ising model

The Ising model for a ferromagnet is not only a very simple model which has a phase transition, but it can also be used to describe phase transitions in a whole range of other physical systems. The model is defined using the equation

where the i and j designate points on a lattice and Si takes the values 1/2. The various different physical systems differ in the definition and sign of the various Jij’s.

Here we will consider the simple case of a 2 dimensional square lattice with interactions only between nearest neighbors. In this case

where ji is only summed over the 4 nearest neighbors of i.

, k

i ji j

E J S S

, i

i ji j

H J S S

Page 40: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

This model can be studied using the Metropolis method as described in the notes, where the state can be changed by flipping a single spin. Note that the change in energy due to flipping the kth spin from ↑ to ↓ is given by

The only quantity which actually occurs in the calculation is

and this can only take one of five different values given by the number of neighboring ↑ spins. Hence it is sensible to store these in a short array before starting the calculation. Note also that there is really only 1 parameter in the model, J/kBT , so that it would make sense to write your program in terms of this single parameter rather than J and T separately. The calculation should use periodic boundary conditions, in order to avoid spurious effects due to boundaries. There are several different ways to achieve this. One of the most efficient is to think of the system as a single line of spins wrapped round a torus. This way it is possible to avoid a lot of checking for the boundary. For an N × N system of spins define an array of N2 elements using the shortest sensible variable type: char in C(++).

exp( / )k k BZ E k T

k

k

k jj

E J S

Page 41: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

It is easier to use for spin ↑ and for spin ↓, as this makes the calculation of the

number of neighboring ↑ spins easier. In order to map between spins in a 2d

space Sr (r = (x, y)) and in the 1d array Sk the following mapping can be used.

where the 2nd N2 elements of the array are always maintained equal to the 1st N2.

This way it is never necessary to check whether one of the neighbors is over the

edge. It is important to remember to change Sk+N2 whenever Sk is changed.

The calculation proceeds as follows:

2

2

1

1

r x r

r x k N

r y k N

r y k N N

S S

S S

S S

S S

Page 42: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

1. Initialize the spins, either randomly or aligned.

2. Choose a spin to flip. It is better to choose a spin at random rather than

systematically as systematic choices can lead to spurious temperature gradients

across the system.

3. Decide whether to flip the spin by using the Metropolis condition.

4. If the spin is to be flipped, do so but remember to flip its mirror in the array.

5. Update the energy and magnetization.

6. Add the contributions to the required averages.

7. Return to step 2 and repeat.

Page 43: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

One does QMC for the same reason as one does classical simulations; there is no other method able to treat exactly the quantum many-body problem aside from the direct simulation method where electrons and ions are directly represented as particles, instead of as a “fluid” as is done in mean-field based methods. However, quantum systems are more difficult than classical systems because one does not know the distribution to be sampled, it must be solved for. In fact, it is not known today which quantum problems can be “solved” with simulation on a classical computer in a reasonable amount of computer time.

Quantum Monte Carlo Calculation

Page 44: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

IntroductionThis project is to use the variational quantum Monte Carlo method to calculate the ground state energy of the He atom. The He atom is a two electron problem which cannot be solved analytically and so numerical methods are necessary. Quantum Monte Carlo is one of the more interesting of the possible approaches (although there are better methods for this particular problem).

The MethodThe Schr¨odinger equation for the He atom in atomic units is,

where r1 and r0 are the position vectors of the two electrons, r1 = |r1| , r2 = |r2| and r12 = |r1 r2 |Energies are in units of the Hartree energy (1 Hartree = 2 Rydbergs) and distances are in units of the Bohr radius. The ground state spatial wavefunction is symmetric under exchange of the two electrons (the required antisymmetry is taken care of by the spin part of the wavefunction, which we can forget about otherwise).

Quantum Monte Carlo Calculation

1 2

2 21 2 1 2

1 2 12

1 1 2 2 1( , ) ( , )

2 2r r r r E r rr r r

Page 45: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

* 3 31 2

* 3 31 2

......

......

T T

T

T T

H d r d rE

d r d r

3 31 2 1 2

1...... ( , )T T

T

E H f r r d r d r

*1 2 1 2

1 2 * 3 31 2

( , ) ( , )( , )

......T T

T T

r r r rf r r

d r d r

* 3 31 2...... T T d r d r

The expression for the energy expectation value of a particular trial wavefunction, T(r1, r2), is,

In the variational Monte Carlo method, this equation is rewritten in the form,

where

is interpreted as a probability density which is sampled using the Metropolis algorithm. Note that the Metropolis algorithm only needs to know ratios of the probability density at different points, and so the normalisation integral,

always cancels out and does not need to be evaluated.

Page 46: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

1T

T

H

1 2 122 2 /2r r re e e

The mean of the values of the “local energy”,

at the various points along the Monte Carlo random walk then gives an estimate of the energy expectation value. By the variational principle, the exact energy expectation value is always greater than or equal to the true ground state energy; but the Monte Carlo estimate has statistical errors and may lie below the true ground state energy if these are large enough. Anyway, the better the trial wavefunction, the closer to the true ground state energy the variational estimate should be.

In this project you are given a possible trial wavefunction,

Use the variational Monte Carlo technique to calculate variational estimates of the true ground state energy.

Page 47: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

1 12 2 12

1 12 1 12

1 17

4

r r r rH

r r r r

Before you start programming, you will need the analytic expressions for the local energy. This involves some nasty algebra, but the answer is,

The Monte Carlo moves can be made by generating random numbers (use a library routine to do this) and adding them to the electron coordinates. I suggest that you update all six electron position coordinates (x1, y1, z1, x2, y2, z2) each move, and so you will need six random numbers each time. The accepted lore is that the Metropolis algorithm is most efficient when the step size is chosen to keep the acceptance probability close to 0.5. However, the method should work in principle no matter what the step size and you should try a few different step sizes to confirm that this is indeed the case. The starting positions of the two electrons can be chosen randomly, but remember that the Metropolis algorithm only samples the probability distribution exactly in the limit as the number of moves tends to infinity. You will therefore have to throw away the results from the moves near the beginning of the run and only start accumulating the values of the local energy once things have settled down. You should experiment to find out how many moves you need to throw away.

Page 48: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

The Physics

In general it is advisable to run the program for some time to allow it to reach equilibrium before trying to calculate any averages. Close to a phase transition it is often necessary to run for much longer to reach equilibrium. The behaviour of the total energy during the run is usually a good guide to whether equilibrium has been reached. The total energy, , and the magnetisation can be calculated from

It should be possible to calculate these as you go along, by accumulating the changes rather than by recalculating the complete sum after each step. A  lattice should suffice for most purposes and certainly for testing, but you may require a much bigger lattice close to a transition. A useful trick is to use the final state at one temperature as the initial state for the next slightly different temperature. That way the system won't need so long to reach equilibrium.

It should be possible to calculate the specific heat and the magnetic susceptibility. The specific heat could be calculated by differentiating the energy with respect to temperature. This is a numerically questionable procedure however. Much better is to use the relationship 

1i

i

M SN

Page 49: Chapter 4 Monte Carlo Methods and Simulation. Monte Carlo Methods

Similarly, in the paramagnetic state, the susceptibility can be calculated using 

where  and the averages are over different states, i.e. can be calculated by averaging over the different Metropolis steps. Both these quantities are expected to diverge at the transition, but the divergence will tend to be rounded off due to the small size of the system. Note however that the fact that (4.33) & (4.34) have the form of variances, and that these diverge at the transition, indicates that the average energy and magnetisation will be subject to large fluctuations around the transition.Finally a warning. A common error made in such calculations is to add a contribution to the averages only when a spin is flipped. In fact this is wrong as the fact that it isn't flipped means that the original state has a higher probability of occupation.

2

221

B

JCv E E

N k T

221χ

B

JE E

N k T