Question: Matlab problem@@@ This the helpin code!!! function spin = metropolis_mc_ising(spin,T) % Metropolis Monte Carlo update (single sweep) of 2D Ising ferromagnet: % It takes matrix

Matlab problem@@@

 Matlab problem@@@ This the helpin code!!! function spin = metropolis_mc_ising(spin,T) %

This the helpin code!!!

function spin = metropolis_mc_ising(spin,T)

% Metropolis Monte Carlo update (single sweep) of 2D Ising ferromagnet:

% It takes matrix of spins and temperature as an input and returns

% matrix of updated spins via Metropolis algorithm; such conversion of

% input spins into out spins counts as one Monte Carlo time step

% INPUT:

% spin Input matrix of Ising classical spins on the square lattice

% T temperature in units in which J=1, k_B=1

% OUTPUT:

% spin Output matrix of Ising classical spins on the square lattice

N=100;

beta=1/T; % beta=J/(k_B*T)

size = length(spin); % find the dimension of the input matrix (which is equal to the size of the lattice)

for i=1:size %Loop over sites:

for j=1:size

% Find coordinates of neighboring spins for spin at position i,j

% while using periodic boundary conditions:

ipos = mod(i,size) + 1;

jpos = mod(j,size) + 1;

ineg = mod(i+size-2,size) + 1;

jneg = mod(j+size-2,size) + 1;

old_spin = spin(i,j); % spin at position i,j of the input matrix

new_spin = -spin(i,j); % flip the spin and test below if this is allowed

% sum of four spins surrounding spin at position i,j

spin_sum = spin(i,jpos) + spin(ipos,j) + spin(i,jneg) + spin(ineg,j);

% energy difference between old and new configuration of five spins

% consisting of spin at i,j plus its four nearest neighbors:

old_energy=-old_spin*spin_sum;

new_energy=-new_spin*spin_sum;

energy_diff = beta * (new_energy - old_energy);

% update spin at position i,j by checking if new_spin is allowed

% in accord with the laws of statistical physics

p = rand; %generate a uniform random number between 0 and 1

if( (energy_diff p) ) % Metropolis criterion

spin(i,j) = new_spin; % accept the change so that spin at position i,j is now flipped

end

end

end %Loop over site

end %function metropolis_mc_ising

Define an initial spin matrix of size 16 X 16 spins with all spins either up or down (-1 or Start with T = 0 and calculate the average spin of the system. For the T = 0 case it should be either 1 or -1. Gradually increase the temperature and calculate for each temperature. Make a plot of versus temperature. 1) Define an initial spin matrix of size 16 X 16 spins with all spins either up or down (-1 or Start with T = 0 and calculate the average spin of the system. For the T = 0 case it should be either 1 or -1. Gradually increase the temperature and calculate for each temperature. Make a plot of versus temperature. 1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!