@Zemel-Yang
2016-10-04T10:29:05.000000Z
字数 3295
阅读 906
homework python
Problem 1.5
Consider again a decay problem with two types of nuclei A and B, but now suppose that nuclei of type A decay into ones of type B, while nucleiof type B decay into ones of type A. Strictly speaking, this is not a "decay" process, since it is possible for the type B nuclei to turn back into type A nuclei. A better analogy would be a reasonance in which a system can tunnel or move back and forth between two states A and B which have equal energies. The corresponding rate equations are
Ideas
1. Nummerical Approach
Taylor expansion for
import pylab as plclass uranium_decay:def __init__(self,number_of_a = 100, number_of_b = 0,time_constant = 1, time_of_duration = 5, time_step = 0.05):# unit of time is secondself.nuclei_a = [number_of_a]self.nuclei_b = [number_of_b]self.t = [0]self.tau = time_constantself.dt = time_stepprint("Initial number of nuclei ->", number_of_a)print("Time constant ->", time_constant)print("time step -> ", time_step)print("total time -> ", time_of_duration)def calculate(self):for i in range(100):tmpa = self.nuclei_a[i] + (self.nuclei_b[i] - self.nuclei_a[i]) / self.tau * self.dtself.nuclei_a.append(tmpa)tmpb = self.nuclei_b[i] + (self.nuclei_a[i] - self.nuclei_b[i]) / self.tau * self.dtself.nuclei_b.append(tmpb)self.t.append(self.t[i] + self.dt)def store(nuclei_a,nuclei_b,t):data = open('data.txt','w')for i in range(100):data.write(str(t[i]))data.write(' ')data.write(str(nuclei_a[i]))data.write(' ')data.write(str(nuclei_b[i]))data.write('\n')data.closedef show_results(self):plot1, = pl.plot(self.t,self.nuclei_a,'g')plot2, = pl.plot(self.t,self.nuclei_b,'r')pl.xlabel('Time(s)')pl.ylabel('Number of Nuclei')pl.legend([plot1, plot2], ['NA', 'NB'], loc="best")pl.xlim(0, 5)pl.ylim(0, 100)pl.savefig('chapter1_1.5.png',dpi=144)pl.show()b = uranium_decay()b.calculate()b.show_results()
Result
Figure:The number of nuclei of type A is marked by the green line and The number of nuclei of type B is marked by the red line.
And here is the data I saved.
From the figure we can see finally and the system reaches a steady state which and are constant.
Conclusion
From this project I learned how to use Euler mothed to solve simple first order ordinary differential equation or equations and how to use python draw figures.