[关闭]
@LiuYongJie 2016-10-09T13:11:14.000000Z 字数 2959 阅读 352

Ex_04

Abstract

•Using Python to draw function pictures.
•Using Python to solve differential equation.

Background

•Learning to solve physics problems by using computer.
•Learning how to use class function.


The Main Body

● 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


where for simplicity we have assumed that the two types of decay are characterized by the same time constant, . Solve this system of equations for the numbers of nuclei,and,as functions of time .Consider different initial conditions, such as,etc., and take. Show that your numerical results are consistent with the idea that the system reaches a steady state whichare constant. In such a steady state, the time derivatives should vanish.

mathematical formula


● solution

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,


It's the same with
Taylor expansion for

Similarly,

Code.1 Shows the picture when initial NA=100,NB=20

  1. import pylab as pl
  2. class uranium_decay:
  3. def __init__(self, number_of_NA = 100,number_of_NB = 0, time_constant = 1, time_of_duration = 5, time_step = 0.05):
  4. self.na_uranium = [number_of_NA]
  5. self.nb_uranium = [number_of_NB]
  6. self.t = [0]
  7. self.tau = time_constant
  8. self.dt = time_step
  9. self.time = time_of_duration
  10. self.nsteps = int(time_of_duration//time_step + 1)
  11. print("Initial number of NA ->", number_of_NA)
  12. print("Initial number of NB ->", number_of_NB)
  13. print("Time constant ->", time_constant)
  14. print("time step -> ", time_step)
  15. print("total time -> ", time_of_duration)
  16. def calculate(self):
  17. for i in range(self.nsteps):
  18. tmpa = self.na_uranium[i] + (self.nb_uranium[i]-self.na_uranium[i])/self.tau * self.dt
  19. tmpb = self.nb_uranium[i] + (self.na_uranium[i]-self.nb_uranium[i])/self.tau * self.dt
  20. self.nb_uranium.append(tmpb) self.na_uranium.append(tmpa)
  21. self.t.append(self.t[i] + self.dt)
  22. def show_results(self):
  23. pl.plot(self.t, self.na_uranium)
  24. pl.plot(self.t, self.nb_uranium)
  25. pl.xlabel('time ($s$)')
  26. pl.ylabel('Number of Nuclei')
  27. pl.show()
  28. a = uranium_decay()
  29. a.calculate()
  30. a.show_results()

result: NA=100 NB=0

now we change the initial conditions:
result: NA=100 NB=50
result: NA=20 NB=80

● Conclusion

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.

Thanks to

Hu Shengyong

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注