Docsity

Demo Ising Animation-Computational Physics-Codes, Exercises of Computational Physics

Toggle sidebar
bg1
%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 = 2*spin + 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:4
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
pf2

Partial preview of the text

Download Demo Ising Animation-Computational Physics-Codes and more Exercises Computational Physics in PDF only on Docsity!

%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