-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathdynamic-randomwalk-pSetter.py
More file actions
39 lines (33 loc) · 948 Bytes
/
dynamic-randomwalk-pSetter.py
File metadata and controls
39 lines (33 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pycxsimulator
from pylab import *
n = 1000 # number of particles
sd = 0.1 # standard deviation of Gaussian noise
def initialize():
global xlist, ylist
xlist = []
ylist = []
for i in range(n):
xlist.append(normal(0, 1))
ylist.append(normal(0, 1))
def observe():
global xlist, ylist
cla()
plot(xlist, ylist, '.', alpha = 0.2)
axis('image')
axis([-20, 20, -20, 20])
def update():
global xlist, ylist
for i in range(n):
xlist[i] += normal(0, sd)
ylist[i] += normal(0, sd)
def num_particles (val = n):
'''
Number of particles.
Make sure you change this parameter while the simulation is not running,
and reset the simulation before running it. Otherwise it causes an error!
'''
global n
n = int(val)
return val
import pycxsimulator
pycxsimulator.GUI(parameterSetters = [num_particles]).start(func=[initialize, observe, update])