# Levy problem HW01 ICFP 2018.py

(Difference between revisions)
Jump to: navigation, search
 Revision as of 16:49, 11 September 2016Werner (Talk | contribs)← Previous diff Current revisionWerner (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 2018 course in Statistical physics. Note that this program is written in Python 2.X. I hope to make a Python 3 version available soon.

## Current revision

This is the program Levy.py that is useful for Homework 1 of the ICFP 2018 course in Statistical physics. Note that this program is written in Python 2.X. I hope to make a Python 3 version available soon.

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