Buggy surface 2d.py
From Werner KRAUTH
(Difference between revisions)
Revision as of 12:46, 6 June 2024 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
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, math | import random, math | ||
import matplotlib.pyplot as plt | import matplotlib.pyplot as plt |
Current revision
[edit]
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).
[edit]
Python program
import random, math import matplotlib.pyplot as plt N_trials = 1000000 data = [] twopi = 2.0 * math.pi for iter in range(N_trials): x = random.uniform(-1.0, 1.0) y = random.uniform(-1.0, 1.0) r = math.sqrt(x **2 + y ** 2); x = x / r; y = y / r # non-uniform sample on the surface of unit sphere phi = (math.atan2(y, x) + twopi) % twopi data.append(phi) plt.title('buggy_surface_2d.py (histogram of angles)') plt.xlabel('angle') plt.ylabel('histogram') plt.hist(data, bins=100, density=True) plt.show()