Disclaimer: I just found a possible solution - eventhough i don't really understand, whats wrong with my prior approach. Edit:

I just tried to calculate it from scratch and found the following:

$E = -J*s\sum_r s_r$ and the new energy $E_n = -J*s_n \sum_r s_r$ where $s_n = -s$.

So the difference is:

$E_n - E = -J*s_n \sum_r s_r - -J*s\sum_r s_r = (-J\sum_r s_r)(s_n -s) = (-J\sum_r s_r)(-s -s) = (-J\sum_r s_r)(-2s)$.

So there's a factor 2 instead of a factor 4 in the energy difference.

My prior thought was:

If i change the spin from -1 to 1 from a point surrounded by +1 spins the energy of that point changes from +4J to -4J and all the surrounding points energy get reduced by 2, which adds up to the total difference $\delta E = (-4J-4J)+4*(-2J) = -16J

Why is that wrong?

The old problem, somewhat solved. Question- name still applies.

I'm currently writing a simulation of the 2D Ising model and there's something strange with my program.

I calculate my energy difference before a spinflip (Metropolis Hastings algorithm) with

dE = -4*s*S

where s is the spin value of the (soon to be flipped) lattice site and S is the sum of the nearest neighbours.

Usually there would be a coupling constant--I assumed it's just 1--and there is no field.

Then I calculate the probability with:

Math.exp(-dE* Beta) //Beta == 1/T

Here are the calculated acceptance prbpabilities, the first value is the temperature ($kT/J = kT$), the second value is the energy difference (if it's zero or below zero the probability is 100% so i didn't include those). The third value is the probability.

0.5 16.0 1.2664165549094176E-14
0.5 8.0 1.1253517471925912E-7

1.0 16.0 1.1253517471925912E-7
1.0 8.0 3.3546262790251185E-4

2.0 16.0 3.3546262790251185E-4
2.0 8.0 0.01831563888873418

2.2669 16.0 8.604140030289146E-4
2.2669 8.0 0.029332814440979144

3.0 16.0 0.004827949226449516
3.0 8.0 0.06948344570075318

4.0 16.0 0.01831563888873418
4.0 8.0 0.1353352832366127

This is a screen shot of the simulation at $T=T_c = 2.2669$ which differs from what I expect: http://i.stack.imgur.com/Dmpi3.png

Can someone confirm my probabilities or suggest what is wrong with them?

  • 1
    $\begingroup$ Looks like your missing a factor of 2 or 1/2 somewhere, the energy is a sum over all ordered pairs of neihgbours, so 2* a sum over all bonds. $\endgroup$
    – user27799
    Sep 25 '13 at 21:08
  • $\begingroup$ thanks so far - i will rewrite the whole question tomorrow - something's odd and i'm not sure where the problem is or how to phrase it at the moment. $\endgroup$
    – oerpli
    Sep 25 '13 at 22:47

I think you have a problem with double counting. The Ising Hamiltonian is $$H = - J \sum_{\langle i,j \rangle} S_i S_j$$ where this strange sum notation means to sum over all bonds between neighbouring spins. It is the bond that matters, so you should not count it twice (for $ij$ and $ji$). Actually you can get the energy difference of a spin flip as $$\Delta E = 2 J (N_{\uparrow\uparrow} - N_{\uparrow\downarrow})$$ where $N_{\uparrow\uparrow}$ ($N_{\uparrow\downarrow}$) is the number of neighbouring spins pointing in the same (opposite) direction before the flip.

  • 1
    $\begingroup$ that was indeed the problem. $\endgroup$
    – oerpli
    Aug 2 '14 at 16:06

Check out a copy of my MHMC Ising model code (written in Python) from GitHub. You might find the answer to your question by digging through the code, it is fairly well commented. Let me know if you have any questions about it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.