From 35566edc1210738c20f3b9a1f695e75ef11ebaed Mon Sep 17 00:00:00 2001 From: "Ben F. Maier" Date: Mon, 14 Jun 2021 14:52:09 +0200 Subject: [PATCH] moved example --- brownian_motion.py => example/brownian_motion.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) rename brownian_motion.py => example/brownian_motion.py (83%) diff --git a/brownian_motion.py b/example/brownian_motion.py similarity index 83% rename from brownian_motion.py rename to example/brownian_motion.py index c3952cf..296810c 100644 --- a/brownian_motion.py +++ b/example/brownian_motion.py @@ -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,)) @@ -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 @@ -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() @@ -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()