The model consists of a lattice of spins, each of which interacts with its nearest neighbors, as well as with an external field. The Ising model calculates the energy, E, of a number of spins on a lattice (2-dimensional here) using: where J is the "exchange energy" and S is a spin either up or down (+1 or -1), and the summations are over nearest neighbours. You'd better run the program in ising.m unless you want to improve my code. Dark sites point down, while light sites point up. Here's a working version: subplot(4,1,4); quiver3(Z,U,V,S(:,:,m)); colormap, The code is from this book, starting from page 502 , the code is mentioned explicity in page 521, https://drive.google.com/file/d/1nka7w4_RlwxvCqkeVyczcivPjFbHGQHM/view?usp=sharing. In the Ising model, the total energy of the system for a lattice with Nspins is given as: E= J XN i;j=nn(i) s is j H XN i=1 s i (2) The rst term represents the spin i Choose a web site to get translated content where available and see local events and offers. I modified the question , I added the code ising2.m in the end, Of course your code will be useful, as I am learning to do montecarlo using matlab with different approches, so I will be grateful if you share your code also. Thank you very much Alan Steven, you are very nice , I highly appreciate your remarks, and help, wish you have very nice day, and stay safe. The two dimensional model has a phase transition [4]. I can judge that better if you answer the question above. This example integrates computation into a physics lesson on the Ising model of a ferromagnet. You can also select a web site from the following list: Select the China site (in Chinese or English) for best site performance. My code will be different from the Russian version as mine calculates the equilibrium configuration only, whereas the comments in the coding above hints at time dependence (I think!). Unfortunately this doesn’t occur in the 1D Ising model. Other MathWorks country sites are not optimized for visits from your location. S1：原子１のスピンの向き（上＝１，下＝−１） The Hobbyhorse of Magnetic Systems: The Ising Model E. Ibarra-Garc a-Padilla and F. J. Poveda-Cuevas Instituto de F sica, Universidad Nacional Aut onoma de M exico, Apartado Postal 20-364, M exico D.F. 01000, M I found this code in Russian book , to simulate ising model in 2D using montecarlo method, but Franky I don't understand the 22 lines , alhtough it gives 2d square grid with a vector in each site, would anyone have an idea about this code ? What aspect don't you understand? % cyclic boundary conditions). https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913018, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913054, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913093, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913138, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913144, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913174, https://www.mathworks.com/matlabcentral/answers/554506-understand-a-code-to-simulate-ising-model-in-2d-using-montecarlo-method#comment_913207.