[关闭]
@Guoguo0605 2016-04-17T16:28:43.000000Z 字数 1720 阅读 1293

Nuclei Decay

code trajectory_of_cannon_shell


  1. from pylab import *
  2. from matplotlib import animation
  3. import time
  4. from math import *
  5. N_A = []
  6. N_B = []
  7. N_B.append(0.0)
  8. NN_A = []
  9. NN_B = []
  10. t = []
  11. tau_A = 1.0
  12. tau_B = 0.
  13. dt = 0
  14. n = 0
  15. def initialize(N_A, N_B, t, _tau_A, _tau_B, _dt, _n):
  16. global tau_A, tau_B, dt, n, time
  17. N_A.append(100)
  18. tau_B = 0.
  19. dt = 0.01
  20. time = 5.0
  21. t.append(0)
  22. n = int(time / dt)
  23. for i in range(n):
  24. t.append(dt*(i+1))
  25. return 0
  26. initialize(N_A, N_B, t, tau_A, tau_B, dt, n)
  27. nnn = arange(0.5,7,0.5)
  28. for ratio in nnn:
  29. tau_B = float(tau_A / ratio)
  30. # print tau_A,tau_B
  31. for i in range(n):
  32. tmp_A = N_A[i]-N_A[i]/tau_A*dt
  33. tmp_B = N_B[i]+dt*(N_A[i]/tau_A-N_B[i]/tau_B)
  34. N_A.append(tmp_A)
  35. N_B.append(tmp_B)
  36. NN_A.append(N_A)
  37. NN_B.append(N_B)
  38. # print len(NN_A[ratio-1])
  39. # print len(t)
  40. N_A=[100,]
  41. N_B=[0,]
  42. #for i in range(10):
  43. # print len(NN_A[i])
  44. fig = figure()
  45. ax1 = fig.add_subplot(1,1,1,xlim=(0, time), ylim=(-3, 100))
  46. # ax1 = fig.add_subplot(2,1,1,xlim=(0, 2), ylim=(-4, 4))
  47. # ax2 = fig.add_subplot(2,1,2,xlim=(0, 2), ylim=(-4, 4))
  48. line, = ax1.plot([], [], color='red', linestyle="-",label="$Nuclei\quad A$")
  49. #lineTh, = ax1.plot([], [], '-b')
  50. line2, = ax1.plot([], [], color='blue', linestyle="-",label="$Nuclei\quad B$")
  51. xlabel('$Time(s)$', fontsize = 16)
  52. ylabel('$Number of Nuclei$',fontsize = 16)
  53. ttt = text(time*0.5, 80,'',fontsize = 18)
  54. #line2Th, = ax1.plot([], [], '-r')
  55. legend(loc='upper left', frameon=False)
  56. def init():
  57. line.set_data([], [])
  58. line2.set_data([], [])
  59. ttt.set_text('')
  60. return line,line2, ttt
  61. # animation function. this is called sequentially
  62. def animate(i):
  63. x = t
  64. y = NN_A[i]
  65. line.set_data(x, y)
  66. x2 = t
  67. y2 = NN_B[i]
  68. line2.set_data(x2, y2)
  69. ttt.set_text( r'$\tau A=1.00$' +'\n' + r'$\tau B=%f$' % float(tau_A / i))
  70. return line,line2,ttt
  71. fram = len(nnn)
  72. anim1=animation.FuncAnimation(fig, animate, init_func=init, frames=fram, interval=300, blit=True)
  73. #savefig("chapter.png")
  74. # anim1.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
  75. show()
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注