Matlab Ising model: Anti-ferromagnet

Click For Summary

Discussion Overview

The discussion revolves around implementing a MATLAB simulation of the 2D Ising model, specifically focusing on creating an anti-ferromagnetic lattice and calculating thermal averages of magnetization and energy. Participants explore coding techniques and debugging strategies within the context of statistical mechanics.

Discussion Character

  • Technical explanation, Homework-related, Exploratory

Main Points Raised

  • One participant seeks guidance on creating a lattice with alternating spins (1s and -1s) to represent an anti-ferromagnet.
  • Another participant inquires about calculating thermal averages of magnetization and energy using a Monte Carlo algorithm, expressing uncertainty about the role of the partition function.
  • A suggestion is made to create a checkerboard pattern in MATLAB using matrix indexing techniques.
  • Participants discuss methods for visualizing the lattice as a color/greyscale grid, with one participant recommending the use of the "imagesc" function for better plotting.
  • One participant reports that their simulation shows incorrect behavior despite the graphs appearing correct and seeks debugging advice.
  • A suggestion is provided to trace the input/output chain backwards as a debugging strategy.

Areas of Agreement / Disagreement

Participants generally agree on the methods for creating the lattice and visualizing it, but there is no consensus on the debugging issues or the correctness of the simulation results, which remain unresolved.

Contextual Notes

The discussion includes limitations related to the understanding of the Monte Carlo algorithm and the potential need for a partition function, which are not fully resolved.

Beer-monster
Messages
285
Reaction score
0
Hi

I'm working on a MATLAB simulation of the 2D Ising model, and would like to verify my code and its results. One thing I'd like to try and observe is the transition from anti-ferromagnet to ferromagnet, but I'm not sure how to create the initial lattice in Matlab. I've already made a (pseudo)random lattice of spins and one that starts as a ferromagnet.

In other words, how can I create a lattice with alternating elements (1s and -1s)?

Also, is there a way to plot or graph my matrix as a colour/greyscale grid, so that -1s are black and +1s are black say? Currently I've used a surface plot but have to rotate the 3D image to a plan view.
 
Physics news on Phys.org
As an additional point. I'd also like to calculate the thermal average of magnetisation and Energy <M>,<E> as a function of temperature. I'm not quite sure how to do this with a Monte Carlo algorithm, without a partition function. Is the best way to run the alogrithm for different temperatures then average the results for each temperature?
 
Beer-monster said:
In other words, how can I create a lattice with alternating elements (1s and -1s)?

If I understand what you're asking for (a checkerboard pattern?)
Code:
Y = zeros(m,n) %make a mxn matrix of zeros

%now make checkerboard 1,-1
Y(1:2:end,1:2:end) = 1
Y(2:2:end,1:2:end) = -1
Y(1:2:end,2:2:end) = -1
Y(2:2:end,2:2:end) = 1

Also, is there a way to plot or graph my matrix as a colour/greyscale grid, so that -1s are black and +1s are black say? Currently I've used a surface plot but have to rotate the 3D image to a plan view.

try "doc imagesc"
you can call options to customize the colors, read up on it.
 
Thanks for the tip. That did the trick nicely. The simulation is showing the wrong behaviour but the graphs look good:biggrin:

Does anyone have any tips for debugging a code in matlab, I'm really not seeing my error at the moment.
 
Just follow the input/output chain backwards (pause ad display function can help with this).
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 45 ·
2
Replies
45
Views
7K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K