-
Notifications
You must be signed in to change notification settings - Fork 0
/
w3l605_clearSim.py
86 lines (53 loc) · 1.74 KB
/
w3l605_clearSim.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import random, pylab
#set line width
pylab.rcParams['lines.linewidth'] = 6
#set font size for titles
pylab.rcParams['axes.titlesize'] = 20
#set font size for labels on axes
pylab.rcParams['axes.labelsize'] = 20
#set size of numbers on x-axis
pylab.rcParams['xtick.major.size'] = 5
#set size of numbers on y-axis
pylab.rcParams['ytick.major.size'] = 5
def clear(n, clearProb, steps):
numRemaining = [n]
for t in range(steps):
numRemaining.append(n*((1-clearProb)**t))
pylab.plot(numRemaining, label = 'Exponential Decay')
#clear(1000, 0.01, 500)
#pylab.xlabel('Number of Steps')
#pylab.ylabel('Number of Molecules')
#pylab.title('Clearance of Molecules')
#pylab.show()
def clearSim(n, clearProb, steps):
numRemaining = [n]
for t in range(steps):
numLeft = numRemaining[-1]
for m in range(numRemaining[-1]):
if random.random() <= clearProb: #monte carlo
numLeft -= 1
numRemaining.append(numLeft)
pylab.plot(numRemaining, 'ro', label = 'Simulation')
#clear(10000, 0.01, 1000)
#clearSim(10000, 0.01, 1000)
#pylab.xlabel('Number of Steps')
#pylab.ylabel('Number of Molecules')
#pylab.legend()
#pylab.show()
def clearSim2(n, clearProb, steps):
numRemaining = [n]
for t in range(steps):
numLeft = numRemaining[-1]
for m in range(numRemaining[-1]):
if random.random() <= clearProb: #monte carlo
numLeft -= 1
if t != 0 and t % 100 == 0:
numLeft += numLeft
numRemaining.append(numLeft)
pylab.plot(numRemaining, 'ro', label = 'Simulation')
clear(10000, 0.01, 1000)
clearSim2(10000, 0.01, 1000)
pylab.xlabel('Number of Steps')
pylab.ylabel('Number of Molecules')
pylab.legend()
pylab.show()