# -*- coding: utf-8 -*- """ Created on Tue Feb 03 17:07:04 2015 Listing 15.1 : analyse de marches aléatoires @author: grivet """ import numpy as ny import matplotlib.pyplot as plt NPMAX = 1000 dm = ny.zeros(NPMAX); sigma_d = ny.zeros(NPMAX) for np in range(10,NPMAX): if np % 10 == 0: print(" %d" %np, end = '') if (np + 1) % 100 == 0: print('\n') NR = int(ny.sqrt(np)); d = ny.zeros(NR); for ir in range(NR): x = 0; y = 0; for i in range(np): dx = ny.random.random()-0.5; dy = ny.random.random()-0.5 # plot2d([x,x+dx],[y,y+dy], frameflag = 0,style = ir) x += dx; y += dy d[ir] = ny.sqrt(x*x+y*y) dm[np] = ny.sum(d)/NR ddm = ny.sum(d*d)/NR sigma_d[np] = ny.sqrt(ddm - dm[np]*dm[np]) xx = range(NPMAX) plt.figure(2) plt.loglog(xx,dm) plt.xlabel("$N$") plt.ylabel("$$") plt.xlim(10,1000) plt.figure(3) plt.plot(ny.sqrt(xx),dm) plt.xlabel("$N^{1/2}$") plt.ylabel("$$") plt.xlim(3,32)