Diffusion.py
From Werner KRAUTH
(Difference between revisions)
Revision as of 05:26, 6 June 2024
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()