# Monte Carlo Simulation, Ising model in 2D

#### Firben

1. Homework Statement
Lo,Im stuck on how to retrieve the specific heat capacity from an MC simulation, with the metropolis algorithm. I want my graph to look something like this:
https://i.stack.imgur.com/NXeXs.png

2. Homework Equations
C_v = ((<E^2>-<E>^2)/T^2

3. The Attempt at a Solution

My code is similar to this guy:
but without magnetization

To retrieve C_v i wrote the following code to 4:19 from the video above.

Cv = (E2/16384 - E.*E/16384^2)./(T(i).^2);

plot(T,Cv);

Where E2 is given by the code:

function [E2] = ising_energy(u,J)

[L1,L2] = size(u);
E2=0;
for i=1:L1
for j=1:L2
f1i=mod(i,L1)+1;
f2j=mod(j,L2)+1;
forward_neighbors=u(f1i,j)+u(i,f2j);
E2=E2-(J*u(i,j)*forward_neighbors)*(J*u(i,j)*forward_neighbors);

end;clear j
end;clear i

However my graph looks more like the plot of <E> vs T.

#### Attachments

• 10.5 KB Views: 246
• 8.9 KB Views: 281
Related Advanced Physics Homework Help News on Phys.org

#### PF_Help_Bot

Thanks for the thread! This is an automated courtesy bump. Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post? The more details the better.

#### Firben

No, im still stuck atm. Cant get any reasonable graph. Is there someone that have done this type of simulation before ?

#### Firben

Someone that knows what iam missing ?

#### MohammadJCM

Someone that knows what iam missing ?
where is your code?

### Want to reply to this thread?

"Monte Carlo Simulation, Ising model in 2D"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving