How Does the Metropolis Algorithm Calculate Specific Heat in a 2D XY Model?

  • Thread starter Thread starter Firben
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary

Homework Help Overview

The discussion centers around the application of the Metropolis algorithm to calculate specific heat capacity in a 2D XY model defined on a square lattice. Participants are exploring the implementation of the Hamiltonian and the associated code in MATLAB.

Discussion Character

  • Exploratory, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants are sharing snippets of code and questioning specific lines related to the calculation of the Hamiltonian. There are inquiries about the definition and dimensions of variables, particularly regarding the Hamiltonian sum and the use of random angles.

Discussion Status

Several participants are actively troubleshooting code issues, with some providing clarifications about MATLAB functions. There is ongoing exploration of how to correctly implement the Hamiltonian and the randomization of angles, but no consensus has been reached on the specific problems encountered.

Contextual Notes

Participants are working under the constraints of homework rules, which may limit the amount of direct assistance they can provide. There are indications of confusion regarding the setup of the Hamiltonian and the random number generation process.

Firben
Messages
141
Reaction score
0

Homework Statement


In a XY - model in two dimensional square lattice. I want to calculate specific heat capacity, <E> and <E^2>. By using the formula:

H = -Jsum(<i,j>)Cos(tetha(i)-tetha(j))

The Metropolis algorithm reads:

Simulations for Statistical and Thermal Physics

Homework Equations


H = -Jsum(<i,j>)Cos(tetha(i)-tetha(j))

The Attempt at a Solution



Here is my code for the Hamiltonian:
http://s716.photobucket.com/user/Pitoraq/media/MC_zpsqqzwctgg.png.html?sort=3&o=0

What is wrong with my code ?
 
Physics news on Phys.org
Updated my code:

clear
clc
J = 1;
for N = 1:10000

for M = 1:2
tetha1 = (-1 + (1+1)*rand(4,1))*2*pi;
tetha2 = (-1 + (1+1)*rand(4,1))*2*pi;
for i=1:1:4

Hamton(i,M) = J*(cos((tetha1(i)-tetha2(i))));

end

Hamtonsum = sum(Hamton);

end
DeltaE(N) = Hamtonsum(1) - Hamtonsum(2);
end

Still clueless what to do
 
Is pi defined anywhere?
 
Pi is build in Matlab, no need to define it
 
OK, I've done some C++ but not MatLab.

How about Hamtonsum, Hamtonsum(1) and Hamtonsum(2) ? Should Hamtonsum have a dimension?
 
That is not the problem now. It is Hamton(i,M) = J*(cos((tetha1(i)-tetha2(i)))); .
Why should i take the hamiltonian 8 times ?. If tetha = 2*pi*[-1,1] (random numbers).
H = -(cos(tehta(i) - tetha(j) + cos(tetha(i) - etha(j+1)+..)
How do i choose the value tetha(i) ?
 
My new code is :

clear
clc
Nsq = 100*100;
N = sqrt(Nsq);
T = linspace(0,2,100);J = 1;

randIndx = randi([1,Nsq],Nsq,1);
randR = rand(Nsq,1);
for j = 1:100
spins=2*pi*rand(N);

for i=1:Nsq
index = randIndx(i);
H = 0;
H = H + cos(spins(mod(index,Nsq) + 1) - spins(mod(index - 1 + N,Nsq) + 1));
H = H + cos(spins(mod(index - 2 + Nsq,Nsq) + 1) - spins(mod(index - 1 + Nsq,Nsq) + 1));
H = -J*H;
%Hamiltonian(j) = -H; Hi = (spins(index)*H)/2;
if(Hi <= 0 || randR(i) < (spins(index)*H)/2 )
spins(index) = -spins(index);
end

E(j) = (1/j)*H;

%plot(T,E,'r');
%plot(T,H);
end

%plot(T,Cv,'b');
end
%Esquared(j) = (1/j).*H.^2
%Cv = (1./T.^2).*((E.^2)-Esquared);

plot(T,E);

what is wrong ?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K