Thursday 26 March 2020

Ising Model simulation Code

MATLAB code for the Ising model simulation is given in this post. Try Yourself.

You can access ready-made simulation of this in your phone with the following Android app https://play.google.com/store/apps/details?id=com.gaurtavm.randomprocesssimulation


MATLAB CODE:

a=200;  %height
b=200;  %width
T=1;    %Temprature
steps=10000000;
img=2*(randi(2,a,b)-1)-1;  % Random 2D array containing +1 and -1
for i=1:steps
    x=randi(a,1);
    y=randi(b,1);
    tmp=(img(mod(x-1-1,a)+1,y)+img(mod(x+1-1,a)+1,y)+img(x,mod(y+1-1,b)+1)+img(x,mod(y-1-1,b)+1));
    E=-img(x,y)*tmp;   %Energy
    r=rand;
    if E>0
        img(x,y)=-img(x,y);
    elseif E<=0 && r<exp(E)/T
        img(x,y)=-img(x,y);
    end
   
    if mod(i,10000)==0   %update image after 10000 steps
        imshow(((img+1.0)/2))
        fprintf("%d\n",i)
    end
end


OUTPUT:


No comments:

Post a Comment