
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!

function plotLattice( lattice, spin ) %plotLattice Plot a lattice of spins % Input: % lattice - the lattice of spins % spin - (optional) the spin of all particles in % the lattice. Defaults to 1/ % Use spin 1/2 for default if (nargin < 1) spin = 1/2; end % Get size of lattice lsize = size(lattice); if (length(lsize) > 3) error('Lattice size limited to one, two, or three dimensions!'); end if (length(lsize) < 3) lsize(3) = 1; end % Number of Dimensions dim = length(find(lsize > 1)); % Always plotting largest dimension along x, etc. Szs = unique(lattice); for sstep = 1:length(Szs); Sz = Szs(sstep); % Normalized spin Sz_n = (Sz+spin)/(2*spin); %points = find(lattice == Sz); [xcoord, ycoord, zcoord] = ind2sub(lsize,find(lattice == Sz)); if (dim > 2) plot3(xcoord-1,ycoord-1,zcoord-1,'.','Color',[Sz_n 0 1-Sz_n]); hold on else plot(xcoord-1,ycoord-1,'.','Color',[Sz_n 0 1-Sz_n]); hold on end end if (dim <= 1) axis([-1 lsize(1) -1 1]) elseif (dim == 2) axis([-1 lsize(1) -1 lsize(2)]) else axis([-1 lsize(1) -1 lsize(2) -1 lsize(2)]) end hold off