Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:43:29+00:00 2026-06-01T03:43:29+00:00

I wrote some code for the ising model in python (2d). Everything looks seems

  • 0

I wrote some code for the ising model in python (2d). Everything looks seems to be calculating correctly except the number of good and bad steps. Good steps is defined as steps where the spin is changed because the change in energy (d_energy) is less than or equal to zero. A bad step is when the spin is changed because a random integer is less than the value of e^(-d_energy/(Kb * temp) where kb is boltzman’s constant. And there is a no step where d_energy is greater than zero and rand is > than the e^(what i wrote above).

When i talked to a professor about this, he told me that when I make the temp really high, the number of bad steps should be half of the total number of steps

from numpy import zeros
from random import choice, random
import math

def create_lattice(nx,ny):
   possibleSpins = [-1,1]
   lattice = zeros((nx,ny))
   for i in range(nx):
     for j in range(ny):
        lattice[i,j] = choice(possibleSpins)
 return lattice

def ising_model(nsweeps, nx, ny, Js, kb, temp):

    s_energy = 0.0
    e_energy = 0.0
    d_energy = 0.0
    spin = 0.0
    rand = 0.0
    good = 0.0
    bad = 0.0
    nostep = 0.0
    lattice = create_lattice(nx, ny)
    energies = zeros((nx,ny))
    print(lattice)
    # Each sweep is a complete look at the lattice
    for sweeps in range(nsweeps):
        for i in range(nx):
            for j in range(ny):
                spin = lattice[i][j]
                s_energy = -1 * Js * spin * (lattice[(i-1)%nx][j] + lattice[i][(j-1)%ny] + lattice[i][(j+1)%ny] + lattice[(i+1)%nx][j])
                lattice[i][j] = -1 * spin
                e_energy = -1 * Js * lattice[i][j] * (lattice[(i-1)%nx][j] + lattice[i][(j-1)%ny] + lattice[i][(j+1)%ny] + lattice[(i+1)%nx][j])


                d_energy = e_energy - s_energy
                rand = random()
                if d_energy <= 0 :
                    good = good + 1
                elif d_energy > 0 and rand <= math.exp(-1 * d_energy / (kb * temp)):
                    bad = bad + 1
                else:
                    lattice[i][j] = spin
                    nostep = nostep + 1
                print(math.exp(-1 * d_energy / (kb * temp)))
                print(rand)


    print(lattice)
    print(good)
    print(bad)
    print(nostep)
    # energies array is
    return energies



ising_model(10,7,7,1.0,1.0,10000000000000000000000000000.0)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:43:30+00:00Added an answer on June 1, 2026 at 3:43 am

    There are only 6 possibilities for the delta in energy: -8, -4, 0, 0, 4, 8. I repeat 0 because there are two different configurations with that energy. The probability of each of those is 1/6 for a random configuration. That means 1/3 for d_energy > 0, 1/3 for d_energy < 0 and 1/3 for d_energy == 0.

    If you change if d_energy <= 0 : to if d_energy < 0 : you will get a third “good” a third “bad” and a third “nostep”. I think what your professor meant is that the number of “bad” steps should be the same as the number of “good” step for infinite temperature. Which is the case if you fix the ‘<=’.

    Edit: you may also want to have a >= for the elif.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote some code that looks like this: def get(x, y) @cachedResults.set(x,y, Math.hypot(x, y))
i wrote some code in codeigniter index controller using model ' navigation ': $this->load->model('navigation');
I wrote some code with a lot of recursion, that takes quite a bit
I wrote some code recently (ISO/ANSI C), and was surprised at the poor performance
I wrote some code to read a file in my Java Servlet class. (I'm
I wrote some code which monitors the output of Stopwatch using a tight loop.
I wrote some code (Java and LDAP) to create a user in the Active
I wrote some code today and It was changed by another developer who said
I just wrote some code to test the behavior of std::equal, and came away
I'm very new to C#. My boss asked me to wrote some code using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.