Problem in a simulation with Python

  • Context: Python 
  • Thread starter Thread starter Berti
  • Start date Start date
  • Tags Tags
    Python Simulation
Click For Summary

Discussion Overview

The discussion revolves around a participant's attempt to simulate the Ising model using Python, specifically focusing on calculating the average fluctuations of magnetization, denoted as . The scope includes programming challenges related to the implementation of the model and the mathematical formulation of the fluctuations.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant describes successfully calculating the magnetization M using a specific code snippet but struggles to modify it to compute the average fluctuations .
  • The participant provides the mathematical expressions for M and , indicating their understanding of the underlying physics.
  • Several participants request the actual code to better assist with the issue, emphasizing the need for specific details to provide effective help.
  • There is a repetition of the request for the code, indicating a lack of clarity or completeness in the original post.

Areas of Agreement / Disagreement

Participants generally agree that seeing the actual code is necessary for troubleshooting the issue. However, there is no consensus on the specific solution to the problem of calculating .

Contextual Notes

The discussion highlights the importance of sharing complete code for debugging purposes, but it does not resolve the underlying programming challenge faced by the participant.

Berti
Messages
2
Reaction score
3
TL;DR
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?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K