@LiuYongJie
2016-10-09T13:11:14.000000Z
字数 2959
阅读 352
•Using Python to draw function pictures.
•Using Python to solve differential equation.
•Learning to solve physics problems by using computer.
•Learning how to use class function.
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
For problem 1.5,it dives us two relevant and which are characterised by two first-order differential equations.We can raplace with former equation,so,
Code.1 Shows the picture when initial NA=100,NB=20
import pylab as plclass uranium_decay:def __init__(self, number_of_NA = 100,number_of_NB = 0, time_constant = 1, time_of_duration = 5, time_step = 0.05):self.na_uranium = [number_of_NA]self.nb_uranium = [number_of_NB]self.t = [0]self.tau = time_constantself.dt = time_stepself.time = time_of_durationself.nsteps = int(time_of_duration//time_step + 1)print("Initial number of NA ->", number_of_NA)print("Initial number of NB ->", number_of_NB)print("Time constant ->", time_constant)print("time step -> ", time_step)print("total time -> ", time_of_duration)def calculate(self):for i in range(self.nsteps):tmpa = self.na_uranium[i] + (self.nb_uranium[i]-self.na_uranium[i])/self.tau * self.dttmpb = self.nb_uranium[i] + (self.na_uranium[i]-self.nb_uranium[i])/self.tau * self.dtself.nb_uranium.append(tmpb) self.na_uranium.append(tmpa)self.t.append(self.t[i] + self.dt)def show_results(self):pl.plot(self.t, self.na_uranium)pl.plot(self.t, self.nb_uranium)pl.xlabel('time ($s$)')pl.ylabel('Number of Nuclei')pl.show()a = uranium_decay()a.calculate()a.show_results()
now we change the initial conditions:
result: NA=100 NB=50
result: NA=20 NB=80
Euler mothed is powerful to solve simple first order ordinary differential equations.draw figures by Python is a little difficult as well as interesting.It is essential to master the basic Python syntax,for me,there is still a long way to go.