Levy problem HW01 ICFP 2017.py
From Werner KRAUTH
(Difference between revisions)
Revision as of 10:43, 30 August 2017 Werner (Talk | contribs) ← Previous diff |
Current revision Werner (Talk | contribs) |
||
Line 1: | Line 1: | ||
- | This is the program Levy.py that is useful for Homework 1 of the ICFP 2016 course in Statistical physics. Note that this program is written in Python 2.X. | + | This is the program Levy.py that is useful for Homework 1 of the ICFP 2017 course in Statistical physics. Note that this program is written in Python 2.X. |
Current revision
This is the program Levy.py that is useful for Homework 1 of the ICFP 2017 course in Statistical physics. Note that this program is written in Python 2.X.
import random, math, pylab gamma = -0.5 alpha = -1.0 / gamma Ndata = 1000 data = [] for k in range(10000): x = 0 for l in range(Ndata): x += random.uniform(0.0, 1.0) ** gamma data.append(x / Ndata - 1.0/(gamma + 1.0)) pylab.hist(data,bins=100, range=(-1.0, 2.0), normed=True) pylab.title("Histogram of Levy distribution for $ \\alpha $ = " + str(alpha)) pylab.xlabel('x') pylab.ylabel('p(x)') pylab.savefig('levy.png') pylab.show()