Skip to content

Commit

Permalink
moved example
Browse files Browse the repository at this point in the history
  • Loading branch information
benmaier committed Jun 14, 2021
1 parent c3d43af commit 35566ed
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions brownian_motion.py → example/brownian_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def __init__(self,N, L, T, V, r, tmax, dt, x0 = 0, seed=-1):
self.tmax = tmax
self.x0 = x0

if seed!=-1:
if seed != -1:
np.random.seed(seed)

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

Expand All @@ -25,8 +25,8 @@ def simulate(self):
self.X[t,:] = self.X[t-1,:] + \
self.V*(self.r-self.X[t-1,:]) * self.dt + \
self.factor_B * np.random.randn(self.N)
ndcs_left = np.nonzero(self.X[t,:]<-self.L/2)[0]
ndcs_right = np.nonzero(self.X[t,:]>+self.L/2)[0]
ndcs_left = np.nonzero(self.X[t,:] < -self.L/2)[0]
ndcs_right = np.nonzero(self.X[t,:] > +self.L/2)[0]
self.X[t,ndcs_left] += self.L
self.X[t,ndcs_right] -= self.L

Expand All @@ -44,7 +44,6 @@ def get_trajectories(self):
V = 1
r = 0
L = 1


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

import matplotlib.pyplot as pl

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

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


pl.show()

0 comments on commit 35566ed

Please sign in to comment.