Python Problem in a simulation with Python

AI Thread Summary
The discussion centers on simulating the Ising model, specifically focusing on calculating the magnetization (M) and its fluctuations (⟨M²⟩). The user successfully implemented a code snippet to compute the magnetization using a summation over the lattice spins. However, they encounter difficulties when attempting to modify this code to calculate the average fluctuations ⟨M²⟩, which involves a double summation of spin products. The user expresses frustration over their inability to achieve the desired output and requests assistance in rewriting the code to correctly compute ⟨M²⟩. They emphasize the need for others to review the existing code to provide effective help.
Berti
Messages
2
Reaction score
3
TL;DR Summary
I wanted to simulate the Ising model and it was okay until I wanted to get the fluctuations <M^2>.
In fact, first, I wanted to obtain the magnetization M :
$$ M = \sum_i \sigma ^ z_i $$
and it worked, I got indeed the magnetization M. However I don't succeed unfortunately to obtain the fluctuations <M^2>.
I wanted to simulate the Ising model and it was okay until I wanted to get the fluctuations <M^2>.
In fact, first, I wanted to obtain the magnetization M :

$$ M = \sum_i \sigma ^ z_i $$​

and it worked, I got indeed the magnetization M by writing these lines :

sigmaxop = []
sites = []
for i in range (L):
# \ sum_i sigma ^ z (i)
sigmaxop.append ((sigmaz) .ToList ())
sites.append ()

with L being the length of the lattice (ie the number of spins).

However I would like now to obtain the average fluctuations :


$$ \langle M^2\rangle = \sum_ {i, j} \langle\sigma_i \sigma_j\rangle $$​


To obtain this average fluctuation, I try to modify the part of the code above (that allowed me to obtain M) to get the fluctuations <M^2> but I didn't succeed : I don't obtain <M^2>.

A priori for every lattice
$$m_j=\sum_k \sigma_k$$
and the average of magnetization is
$$<M>=\sum_j m_j$$
So
$$<M^2>=\sum_j m^2_j$$

Unfortunately after trying again I am still stuck with my code. It doesn't work.

Could someone help me to modify/rewrite this part of code to obtain the fluctuations <M^2>, please?
 
Technology news on Phys.org
You need to post your actual code so we can see it. Enclose it with Code tags (the </> icon above, then choose python as the language - like below).

Python:
import numpy as np
 
phyzguy said:
You need to post your actual code so we can see it. Enclose it with Code tags (the </> icon above, then choose python as the language - like below).

Python:
import numpy as np

Sorry. The part of the code for the magnetization M is :

Code:
sigmaxop = []
sites = []
for i in range (L):
     # \ sum_i sigma ^ z (i)
     sigmaxop.append ((sigmaz) .ToList ())
     sites.append ()

And now I'd like to get the fluctuations <M^2> . So I tried to modify this part of the code to get <M^2> but I am unsuccessful ...
 
Berti said:
Sorry. The part of the code for the magnetization M is :

Code:
sigmaxop = []
sites = []
for i in range (L):
     # \ sum_i sigma ^ z (i)
     sigmaxop.append ((sigmaz) .ToList ())
     sites.append ()

And now I'd like to get the fluctuations <M^2> . So I tried to modify this part of the code to get <M^2> but I am unsuccessful ...
How can we possibly comment without seeing the part of the code that isn't working?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
2
Views
3K
Replies
15
Views
2K
Replies
6
Views
3K
Replies
1
Views
4K
Replies
6
Views
2K
Back
Top