Professional Documents
Culture Documents
properties
beta % Constant value.
j % Constant value for interaction strength.
B % Magnetic field value.
N % Number of spins.
FigGUI % Property for the figure.
spins % Property for the spins array.
RunningCondition % Condition for while loop.
UpdateNumber % Number of updates.
end
methods
function obj = TwoDimIsing(obj)
obj.spins = double(randn(obj.N,obj.N)>0); %
Initializing array for spins.
obj.spins(obj.spins==0)=-1; %
Initializing first element of the array.
imshow(obj.spins,[],'InitialMagnification',400) % Plots
the spins using the imshow function.
s=sprintf('Beta=%g, J=%g, B=%g',obj.beta,obj.j,obj.B); % Title
for the figure.
title(s)
catch
end
pause(.01)
end
end
end
function[H,HTest] = EnergyComputation(obj,spins,SpinsTest)
spins = obj.spins; % Initializing spins variable
with object property value.
IDX=ceil(obj.N*rand); % Picking a test value. (x)
IDY=ceil(obj.N*rand); % Picking a test value. (y)
SpinsTest=obj.spins; % Initializing test array.
SpinsTest(IDX,IDY)=-obj.spins(IDX,IDY); % Inverting at test
values.
E_Spin=obj.j*(sum(sum(spins(1:end-1,:).*spins(2:end,:)))+... %
Energy value from neighbor interaction
sum(spins(1,:).*spins(end,:))+... %
Neighbor for Y
sum(sum(spins(:,1:end-1).*spins(:,2:end)))+... %
Neighbor for X
sum(spins(:,1).*spins(:,end))); % X
E_SpinTest=obj.j*(sum(sum(SpinsTest(1:end-
1,:).*SpinsTest(2:end,:)))+... % Neighbor for Y
sum(SpinsTest(1,:).*SpinsTest(end,:))+...
% Y
sum(sum(SpinsTest(:,1:end-1).*SpinsTest(:,2:end)))+...
%Neighbor for X
sum(SpinsTest(:,1).*SpinsTest(:,end)));
%X
function delete(obj)
end
function StopModel(obj)
obj.RunningCondition = 0; % Gui closes when this value is zero.
end
function gui(obj)
% Graphical User Interface function for the class to have
% modularity for the number of updates, the number of spins,the
% value for interaction strenth and magnetic field.
Z=findall(0,'Tag','TWODIMISINGGUI') % Checks for an empty
figure.
if ~isempty(Z);return;end
% Setup UI CONTROLS----------------------------------------------
TextBoxA = uicontrol('Style','edit','String','Beta',... %
First Text Box (editable).
'Position',[100 300 50 50]);
ALabel = uicontrol('Style','text','String','Beta',... %
Label for the first text box.
'Position',[0 300 50 50]);
TextBoxB = uicontrol('Style','edit','String','Interaction
Strength',... % Second text box for jump size (editable).
'Position',[100 250 50 50]);
BLabel = uicontrol('Style','text','String','Interaction
Strength',... % Label for the second text box.
'Position',[0 250 50 50]);
TextBoxD = uicontrol('Style','edit','String','Number of
Spins',... % Fourth Text Box (editable).
'Position',[100 150 50 50]);
DLabel = uicontrol('Style','text','String','Number of Spins',...
% Label for the fourth text box.
'Position',[0 150 50 50]);
TextBoxE = uicontrol('Style','edit','String','Number of
Updates',... % First Text Box (editable).
'Position',[100 350 50 50]);
ELabel = uicontrol('Style','text','String','Number of
Updates',... % Label for the first text box.
'Position',[0 350 50 50]);
function runTwoDimIsing(~,~)
gui2property() % Callback for button.
obj.TwoDimIsing() % Runs Ising function.
property2gui()
end
function runStopModel(~,~)
obj.StopModel
end
function property2gui()
TextBoxA.String=num2str(obj.beta); % Writes object
property for the constant value beta to the first uicontrol.
TextBoxB.String=num2str(obj.j); % Writes object
property for the interaction strength to the second uicontrol.
TextBoxC.String=num2str(obj.B); % Writes object property
for the magnetic field magnitude to the third uicontrol.
TextBoxD.String=num2str(obj.N); % Writes object
property for the number of spins of the data to the fourth uicontrol.
TextBoxE.String=num2str(obj.UpdateNumber); % Writes object
property for the number of updates to the fifth uicontrol.
end
function gui2property()
obj.beta=str2double(TextBoxA.String); % Value for first
object property.
obj.j=str2double(TextBoxB.String); % Value for second
object property.
obj.B=str2double(TextBoxC.String); % Value for third object
property.
obj.N=str2double(TextBoxD.String); % Value for
fourth object property.
obj.UpdateNumber=str2double(TextBoxE.String); % Value for
fifth object property.
end
end
end
end