[关闭]
@oliver1995 2016-10-10T16:49:20.000000Z 字数 2280 阅读 525

Exercise04

Abstract

  • use python to do homework 1.5

Background

  • After learning how to use Matplotlib and the first numerical problem, we start to solve a physics problem by our own.

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 nuclei of 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 resonance 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 in which and are constant. In such a steady state, the time derivatives and should vanish.

The Main Body

  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.na_uranium.append(tmpa)
  21. self.nb_uranium.append(tmpb)
  22. self.t.append(self.t[i] + self.dt)
  23. def show_results(self):
  24. pl.plot(self.t, self.na_uranium)
  25. pl.plot(self.t, self.nb_uranium,'r')
  26. pl.xlabel('time ($s$)')
  27. pl.ylabel('Number of Nuclei')
  28. pl.show()
  29. a = uranium_decay()
  30. a.calculate()
  31. a.show_results()

Conclusion

show result:

  1. Initial number of NA -> 100
  2. Initial number of NB -> 0
  3. Time constant -> 1
  4. time step -> 0.05
  5. total time -> 5

image

Acknowledgment

  • Thanks teacher cai's ppt and classmate Lijinting to guide me.
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注