

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


%Demo_IsingAnimation - Animate the Ising Model % as the system is cooled
clear all; close all; help Demo_IsingAnimation;
% Getsize of lattice fprintf('3D may be slow to animate.\n'); fprintf('Suggested size is 40 in each desired dimension.\n') lsize = input('Input size of lattice [x y z]: '); lsize = fliplr(sort(lsize));
% Boltzmann constant; easiest to set to 1 kb = 1;
%Particle spin spin = 1/2;
% Strength of interaction J = 1;
Bz = input('Input external magnetic field strength: ');
% Range of temperatures maxT = input('Input starting (high) temperature (Suggested: 2): '); minT = input('Input final (low) temperature (Suggested: 0): ');
if (maxT < minT) disp('Warning: System may not reach equilibrium until higher temperatures.') end
T = linspace(maxT,minT,40);
% Random Lattice nspins = 2spin + 1; lattice = -spin + floor(rand(lsize)nspins);
beta = 1./(kb*T);
for tstep = 1:length(T) % Repeat 4 times for each possible temperature for istep=1: tic % Take a Monte Carlo step lattice = MCStep(lattice, beta(tstep), J, Bz, spin);
% Show the lattice figure(1); plotLattice(lattice, spin); title(sprintf('T = %g',T(tstep))) elapsed = toc; if (elapsed < 0.1) pause(.1-elapsed); else
drawnow; end end end