Diffusion.py
From Werner KRAUTH
(Difference between revisions)
| Revision as of 05:27, 6 June 2024 Werner (Talk | contribs) ← Previous diff |
Revision as of 15:09, 6 June 2024 Werner (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| + | ==Context== | ||
| + | This page is part of my [[BegRohu_Lectures_2024|2024 Beg Rohu Lectures]] on "The second Markov chain revolution" at the [https://www.ipht.fr/Meetings/BegRohu2024/index.html Summer School] "Concepts and Methods of Statistical Physics" (3 - 15 June 2024). | ||
| + | |||
| + | ==Python program== | ||
| import random | import random | ||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
Revision as of 15:09, 6 June 2024
Context
This page is part of my 2024 Beg Rohu Lectures on "The second Markov chain revolution" at the Summer School "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).
Python program
import random
import matplotlib.pyplot as plt
N = 5
data = []
tmax = 10
for stat in range(100000):
pos = 0
for t in range(tmax):
pos = min(max(pos + random.choice([-1, 0, 1]), 0), N - 1)
data.append(pos)
plt.title('diffusion starting at $x=0$, $t = $' + str(tmax))
plt.hist(data, bins=N, range=(-0.5, N-0.5), density=True)
plt.savefig('diffusion.png')
plt.show()
