Problem in a simulation with Python

In summary, the conversation discusses the speaker's attempt to simulate the Ising model and obtain the magnetization M and average fluctuations <M^2>. The speaker successfully obtains M using a code but is unsuccessful in modifying the code to obtain <M^2>. They ask for help in modifying the code to obtain <M^2>.
  • #1
Berti
2
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
  • #2
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
 
  • #3
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 ...
 
  • #4
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?
 

1. What is a simulation in Python?

A simulation in Python is a computer program that models a real-world system or process. It allows the user to manipulate variables and observe how they affect the outcome of the simulation. This can be useful in understanding complex systems and making predictions.

2. How do I create a simulation in Python?

To create a simulation in Python, you will need to use a combination of programming concepts such as variables, loops, and conditional statements. You will also need to have a clear understanding of the system or process you want to model and how it behaves.

3. What are some common problems that can arise in a simulation with Python?

Some common problems that can arise in a simulation with Python include bugs in the code, incorrect assumptions about the system, and insufficient data or input. It is important to thoroughly test and validate your simulation to ensure its accuracy.

4. How can I troubleshoot problems in my simulation with Python?

To troubleshoot problems in your simulation with Python, you can use debugging tools such as print statements and error messages to identify where the issue is occurring. You can also break down your code into smaller parts and test each one individually to pinpoint the problem.

5. Is it possible to simulate complex systems with Python?

Yes, it is possible to simulate complex systems with Python. However, it may require advanced programming skills and knowledge of the system being modeled. It is also important to validate the simulation and make sure it accurately represents the real-world system.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
3
Views
927
  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top