-
Notifications
You must be signed in to change notification settings - Fork 8
/
Excercise_04(6).py
83 lines (78 loc) · 3.57 KB
/
Excercise_04(6).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
import pylab as pl
class duel_decay:
"""docstring for "duel decay"."""
def __init__(self, number_of_nuclei_A = 100, number_of_nuclei_B = 0, time_constant = 0.5, time_of_duration = 5, time_step1 = 0.05, time_step2 = 0.01, time_step3= 0.1):
self.n_A1 = [number_of_nuclei_A]
self.n_B1 = [number_of_nuclei_B]
self.n_A2 = [number_of_nuclei_A]
self.n_B2 = [number_of_nuclei_B]
self.n_A3 = [number_of_nuclei_A]
self.n_B3 = [number_of_nuclei_B]
self.N = number_of_nuclei_A + number_of_nuclei_B
self.t1 = [0]
self.t2 = [0]
self.t3 = [0]
self.tau = time_constant
self.dt1 = time_step1
self.dt2 = time_step2
self.dt3 = time_step3
self.time = time_of_duration
self.nsteps1 = int(time_of_duration // time_step1 + 1)
self.nsteps2 = int(time_of_duration // time_step2 + 1)
self.nsteps3 = int(time_of_duration // time_step3 + 1)
print("Initial number of nuclei A ->", number_of_nuclei_A)
print("Initial number of nuclei B ->", number_of_nuclei_B)
print("Time constant ->", time_constant)
print("Time step1 ->", time_step1)
print("Time step2 ->", time_step2)
print("Time step3 ->", time_step3)
print("Total time ->", time_of_duration)
def calculate(self):
for i in range(self.nsteps1):
tmp_A1 = self.n_A1[i] + (self.N - 2 * self.n_A1[i]) / self.tau * self.dt1
tmp_B1 = self.N - tmp_A1
self.n_A1.append(tmp_A1)
self.n_B1.append(tmp_B1)
self.t1.append(self.t1[i] + self.dt1)
for i in range(self.nsteps2):
tmp_A2 = self.n_A2[i] + (self.N - 2 * self.n_A2[i]) / self.tau * self.dt2
tmp_B2 = self.N - tmp_A2
self.n_A2.append(tmp_A2)
self.n_B2.append(tmp_B2)
self.t2.append(self.t2[i] + self.dt2)
for i in range(self.nsteps3):
tmp_A3 = self.n_A3[i] + (self.N - 2 * self.n_A3[i]) / self.tau * self.dt3
tmp_B3 = self.N - tmp_A3
self.n_A3.append(tmp_A3)
self.n_B3.append(tmp_B3)
self.t3.append(self.t3[i] + self.dt3)
def show_results(self):
pl.plot(self.t1, self.n_A1, 'g--', label='A1, Time Step = 0.05')
pl.plot(self.t1, self.n_B1, 'g', label='B1, Time Step = 0.05')
pl.plot(self.t2, self.n_A2, 'r--', label='A2, Time Step = 0.01')
pl.plot(self.t2, self.n_B2, 'r', label='B2, Time Step = 0.01')
pl.plot(self.t3, self.n_A3, 'b--', label='A3, Time Step = 0.1')
pl.plot(self.t3, self.n_B3, 'b', label='B3, Time Step = 0.1')
pl.title('Change of Nuclei Relative to the Time')
pl.xlim(0.0, 2.5)
pl.ylim(0.0, 100.0)
pl.xlabel('time ($s$)')
pl.ylabel('Number of Nuclei')
pl.legend(loc='best', shadow=True, fontsize='small')
pl.grid(True)
pl.show()
def store_results(self):
myfile = open('nuclei_decay_data.txt', 'w')
for i in range(len(self.t1)):
print(self.t1[i], self.n_A1[i], self.n_B1[i], file = myfile)
myfile = open('nuclei_decay_data.txt', 'w')
for i in range(len(self.t2)):
print(self.t2[i], self.n_A2[i], self.n_B2[i], file = myfile)
myfile = open('nuclei_decay_data.txt', 'w')
for i in range(len(self.t3)):
print(self.t3[i], self.n_A3[i], self.n_B3[i], file = myfile)
myfile.close()
a = duel_decay()
a.calculate()
a.show_results()
a.store_results()