@@ -10,10 +10,10 @@ def __init__(self,N, L, T, V, r, tmax, dt, x0 = 0, seed=-1):
10
10
self .tmax = tmax
11
11
self .x0 = x0
12
12
13
- if seed != - 1 :
13
+ if seed != - 1 :
14
14
np .random .seed (seed )
15
15
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 )
17
17
self .X = np .zeros ((len (self .t ),self .N ))
18
18
self .X [0 ,:] = x0 * np .ones ((self .N ,))
19
19
@@ -25,8 +25,8 @@ def simulate(self):
25
25
self .X [t ,:] = self .X [t - 1 ,:] + \
26
26
self .V * (self .r - self .X [t - 1 ,:]) * self .dt + \
27
27
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 ]
30
30
self .X [t ,ndcs_left ] += self .L
31
31
self .X [t ,ndcs_right ] -= self .L
32
32
@@ -44,7 +44,6 @@ def get_trajectories(self):
44
44
V = 1
45
45
r = 0
46
46
L = 1
47
-
48
47
49
48
sim = BrownianMotion (N = N ,L = L ,T = T ,V = V ,r = r ,tmax = tmax ,dt = dt )
50
49
sim .simulate ()
@@ -53,12 +52,11 @@ def get_trajectories(self):
53
52
54
53
import matplotlib .pyplot as pl
55
54
56
- bins = np .linspace (- L / 2. ,L / 2. ,11 )
55
+ bins = np .linspace (- L / 2. ,L / 2. ,11 )
57
56
bins_mean = 0.5 * (bins [1 :]+ bins [:- 1 ])
58
57
59
58
for t_ in range (len (t )):
60
59
vals ,bins = np .histogram (X [t_ ,:],bins = bins ,density = True )
61
60
pl .plot (0.5 * (bins [:- 1 ]+ bins [1 :]),vals )
62
-
63
61
64
62
pl .show ()
0 commit comments