Ising Model, Mathematica Code
Ising Model, Mathematica Code
n = 25;
B = 0; J = 0.01;
H*a table consisting of all possible energy changes if a single site is flipped
based on all possible configurations of the sites 4 nearest neighbors*L
∆E@ 1, 4D = 2 HB + 4 JL;
∆E@ 1, 2D = 2 HB + 2 JL;
∆E@ 1, 0D = 2 HB + 0 JL;
∆E@ 1, - 2D = 2 HB - 2 JL;
∆E@ 1, - 4D = 2 HB - 4 JL;
∆E@- 1, 4D = - 2 HB + 4 JL;
∆E@- 1, 2D = - 2 HB + 2 JL;
∆E@- 1, 0D = - 2 HB + 0 JL;
∆E@- 1, - 2D = - 2 HB - 2 JL;
∆E@- 1, - 4D = - 2 HB - 4 JL;
flipStep =
H
L = ð; H*the ð symbol is a literal
call to the array that this function will work on*L
If@∆E@L@@i1, i2DD, eDiffD < 0 ÈÈ Random@D < Exp@- ∆E@ð@@i1, i2DD, eDiffDD,
L@@i1, i2DD = - L@@i1, i2DD; L, LD;
Program
This section is the chunk of code that you will run, the Ising2D function, to answer questions about the
behavior of a FM and an AFM system. You will also be required to modify it a bit in some later
problems.
The variable n controls the dimensions of the lattice while the variable count controls the number of
iterations. Be warned that this program can get memory intenstive. The larger you make n and count,
the longer you can expect to hang out. Also, if you want to use the last line of code in this section, the
one that animates the result, I would recommend tunring off Dynamic Upadate (do this from the menu
bar at the top: Evalutaion > Dynamic Updating Disabled/Enabled). If you don’ t, then everytime you run
the program, Mathematica will try and update it as well, which gets very memory intensive.
ClearAll@"Global`*"D
B + 4J B + 2J
∆E@ 1, 4D = 2 ; ∆E@ 1, 2D = 2 ;
T T
B + 0J B - 2J
∆E@ 1, 0D = 2 ; ∆E@ 1, - 2D = 2 ;
T T
B - 4J B + 4J
∆E@ 1, - 4D = 2 ; ∆E@- 1, 4D = - 2 ;
T T
B + 2J B + 0J
∆E@- 1, 2D = - 2 ; ∆E@- 1, 0D = - 2 ;
T T
B - 2J B - 4J
∆E@- 1, - 2D = - 2 ; ∆E@- 1, - 4D = - 2 ;
T T
flipStep =
H
L = ð;
If@∆E@L@@i1, i2DD, eDiffD < 0 ÈÈ Random@D < Exp@- ∆E@ð@@i1, i2DD, eDiffDD,
L@@i1, i2DD = - L@@i1, i2DD; L, LD;
F H*end Module*L
nSteps = 1000;
Questions
Problem 1
a.) Run the program with n=20 at a variety of temperatures, say T = 10, 5, 2.5, 1, and 0.1, using about
1000 steps or so. At each temperature, roughly estimate the size of the emerging clusters.
b.) Repeat part (a) with n=50. Do the cluster sizes change? Explain.
c.) Run the program with n=20 at tempertures T=2, 1, and 0.5 with a variety of step values. Estimate
the average magnetization of the lattice at each temperature. Discuss the results. Do you ever see
symmetry breaking, the point where the whole system takes on one spin value?
d.) Run the program with n=10 at T = 2.5 using at least 100,000 steps. Using the animation code,
watch the system evolve. Discuss and explain this behavior.
e.) Based on the previous parts, estimate where the critical temperature of the system is. Try using
larger lattices with more iterations (as much as your computer can handle) to get a good feeling for what
is happening.
Problem 2
Modify the provided function to calculate the average energy of the lattice (energy over all iterations).
Then run the program with n=20 for temperatures from T=5 to T=1 (using an adequate number of steps)
and plot the resultant energies versus temperature (Mathematica does this using the ListPlot com-
mand). Explain your results.
Problem 3
Modify the provided function to calculate the average magnetization (the sum of all spin values). Run
the program at a variety of temperatures and discuss you results. Note: there are a variety of ways to
do this in Mathematica...one suggestion is to look at the Flatten command an see how it could be useful.
Problem 4
To quantify the clustering of alignments with an Ising magnet, we can define a quantity called the
correlation function, c(r). To do this, take any two sites i and j, seperated by a distance r, and com-
pute the product of thier states: if the product si s j is positive, the dipoles are parallel, if it is negative,
they are anti-parallel. If you average this quantity over all pairs within a certain fixed distance, you
obtain a measure of the tendency of dipoles to be “correlated”over this distance. Effectively, you find
the distance over which sites can “communicate”with other sites. To remove the effect of any overall
magnetization of the system, you subtract off the square of the average s. Thus, the correlation func-
tion is given as
c HrL = si sj - si 2 ,
where it is understood that the first term averages over all pairs at the fixed distance r.
a.) Modify the provided function to calculate the correlation function for the final state of the lattice,
averaging over all pairs vertically and horizontally (not diagonally) seperated by r units of distance,
where r ranges from 1 to half the width of the lattice.
b.) Run this program at a variety of temperatures above, at, and below the critical temperature (use a
larger lattice near the critical temperature). Describe the behavior of the correlation function with
respect to temperature.