Levy problem HW01 ICFP 2018.py

From Werner KRAUTH

Revision as of 00:12, 9 September 2018; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

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.


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()
Personal tools