Skip to content

Commit 35566ed

Browse files
committed
moved example
1 parent c3d43af commit 35566ed

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

brownian_motion.py renamed to example/brownian_motion.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def __init__(self,N, L, T, V, r, tmax, dt, x0 = 0, seed=-1):
1010
self.tmax = tmax
1111
self.x0 = x0
1212

13-
if seed!=-1:
13+
if seed != -1:
1414
np.random.seed(seed)
1515

16-
self.t = np.linspace(0,self.tmax,self.tmax/self.dt+1)
16+
self.t = np.linspace(0,self.tmax,int(self.tmax/self.dt)+1)
1717
self.X = np.zeros((len(self.t),self.N))
1818
self.X[0,:] = x0*np.ones((self.N,))
1919

@@ -25,8 +25,8 @@ def simulate(self):
2525
self.X[t,:] = self.X[t-1,:] + \
2626
self.V*(self.r-self.X[t-1,:]) * self.dt + \
2727
self.factor_B * np.random.randn(self.N)
28-
ndcs_left = np.nonzero(self.X[t,:]<-self.L/2)[0]
29-
ndcs_right = np.nonzero(self.X[t,:]>+self.L/2)[0]
28+
ndcs_left = np.nonzero(self.X[t,:] < -self.L/2)[0]
29+
ndcs_right = np.nonzero(self.X[t,:] > +self.L/2)[0]
3030
self.X[t,ndcs_left] += self.L
3131
self.X[t,ndcs_right] -= self.L
3232

@@ -44,7 +44,6 @@ def get_trajectories(self):
4444
V = 1
4545
r = 0
4646
L = 1
47-
4847

4948
sim = BrownianMotion(N=N,L=L,T=T,V=V,r=r,tmax=tmax,dt=dt)
5049
sim.simulate()
@@ -53,12 +52,11 @@ def get_trajectories(self):
5352

5453
import matplotlib.pyplot as pl
5554

56-
bins = np.linspace(-L/2.,L/2.,11)
55+
bins = np.linspace(-L/2.,L/2.,11)
5756
bins_mean = 0.5*(bins[1:]+bins[:-1])
5857

5958
for t_ in range(len(t)):
6059
vals,bins = np.histogram(X[t_,:],bins=bins,density=True)
6160
pl.plot(0.5*(bins[:-1]+bins[1:]),vals)
62-
6361

6462
pl.show()

0 commit comments

Comments
 (0)