Based on a Wolfram Demonstration of the Ising ferromagnet using Monte-Carlo Metropolis, I modified it a bit to the anti-ferromagnet case and to get the plot of the order parameters as a function of the Temperature. The problem is that for sizes of the system larger that 10 spins and for more than 100000 Monete-Carlo iterations it takes really long times to evaluate (days). Some people have said to me that MATLAB may run much faster, but I haven't been able to find some concise package that makes the job to translate the FULL code to MATLAB. What is available is ToMatlab but it translates just simple expressions, like sin(x)*cos(x), not functions. There are many stack discussions of examples of translations MLB<->WM but they're very particular examples, all focused on expressions, not on functions. Also matlink.org is not very informative.
I put the code for reference, but it's not about the code.
accept[m_, z_] := Module[{ech, x1, y1},
{x1, y1} = RandomInteger[{2, Length[m] - 1}, 2];
ech = m[[x1 - 1, y1]] + m[[x1 + 1, y1]] + m[[x1, y1 - 1]] +
m[[x1, y1 + 1]];
If[RandomReal[] < Exp[-ech*z*2.*m[[x1, y1]]],
ReplacePart[m, {x1, y1} -> -m[[x1, y1]]], m]];
M[T_] := Module[{ic, TL, TLT},
SeedRandom[1234];
ic = ReplaceAll[ArrayPad[RandomInteger[{1, 2}, {nx, nx}], 1],
2 -> -1];
TL = NestList[accept[#, -1/T] &, ic, nsteps];
TLT = Accumulate[
Abs@(Total /@ (Total /@ TL))]/(nx nx (Range[nsteps + 1]));
N[Last[TLT]]];
s[T_] := Module[{ic, TL, TLT, TLTa},
SeedRandom[1234];
ic = ReplaceAll[ArrayPad[RandomInteger[{1, 2}, {nx, nx}], 1],
2 -> -1];
TL = NestList[accept[#, -1/T] &, ic, nsteps];
TLT = Accumulate[
Abs@(Total /@ (Total /@ TL))]/(nx nx (Range[nsteps + 1]));
TLTa =
Accumulate[
Abs[Total /@
Total[Table[Diagonal[#, 2 i], {i, -nx, nx}] & /@
TL, {3}]]]/(nx nx (Range[nsteps + 1]));
N[2 Last[TLTa] - Last[TLT]]];
nx = 10
nsteps = 10000
ListLinePlot[{Table[{T, s[T]}, {T, 0.1, 5, 1/20}],
Table[{T, M[T]}, {T, 0.1, 5, 1/20}], {{2.269, 0}, {2.269, 1}}},
PlotRange -> All]
ReplacePartandReplaceAllshould be avoided if speed is concerned. – xzczd Jan 11 '20 at 03:49accept[ ]function recreatesmon every call, when you are just changing one element of the matrix, and could just pass the coordinates. So I think it could be improved before switching to Matlab. – MikeY Jan 11 '20 at 03:51