Levy problem HW01 ICFP 2018.py

From Werner KRAUTH

(Difference between revisions)
Jump to: navigation, search
Revision as of 16:49, 11 September 2016
Werner (Talk | contribs)

← Previous diff
Revision as of 16:49, 11 September 2016
Werner (Talk | contribs)

Next diff →
Line 3: Line 3:
import random, math, pylab import random, math, pylab
- +
gamma = -0.5 gamma = -0.5
alpha = -1.0 / gamma alpha = -1.0 / gamma

Revision as of 16:49, 11 September 2016

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