2次元イジングモデルをEXCEL VBA でシミュレーションする方法

とりあえずコードを張るだけ。
物理的な意味が、まだ理解できていない。

Const L = 32
Const T = 2.3
Dim spin(L, L) As Integer

Sub ising()
    Dim e As Double
    Dim step As Double
    Dim rr As Double
    step = 1
    rr = 1
    For i = 0 To L - 1
        For j = 0 To L - 1
            If Rnd() < 0.5 Then
                spin(i, j) = 1
                Cells(j + 1, i + 1).Interior.Color = RGB(0, 0, 0)
            Else
                spin(i, j) = -1
                Cells(j + 1, i + 1).Interior.Color = RGB(255, 255, 255)
            End If
        Next
    Next
    e = 0
    Do
        x = Int(Rnd() * L)
        y = Int(Rnd() * L)

        w = spin(x, y) * (spin(IIf(x - 1 > 0, x - 1, L - 1), y) + spin(IIf(x + 1 < L, x + 1, 0), y) + spin(x, IIf(y + 1 < L, y + 1, 0)) + spin(x, IIf(y - 1 > 0, y - 1, L - 1)))
        r = Exp(-2 * w / T)
        If Rnd() < r Then
            spin(x, y) = -1 * spin(x, y)
            If spin(x, y) = 1 Then
                Cells(y + 1, x + 1).Interior.Color = RGB(0, 0, 0)
            Else
                Cells(y + 1, x + 1).Interior.Color = RGB(255, 255, 255)
            End If
        End If

        If step Mod 100 = 0 Then
            e = 0
            m = 0
            For x = 0 To L - 1
                For y = 0 To L - 1
                    e = e - spin(x, y) * (spin(IIf(x + 1 < L, x + 1, 0), y) + spin(x, IIf(y + 1 < L, y + 1, 0)))
                    m = m + spin(x, y)
                Next
            Next

            Cells(101 + rr, 101 + 1) = e
            Cells(101 + rr, 101 + 2) = m
            rr = rr + 1
        End If
        step = step + 1
    Loop

End Sub