[关闭]
@ibilis 2016-10-08T13:14:23.000000Z 字数 2276 阅读 553

作业四

计算物理


1.摘要

运用Euler method,编写python程序,利用matplotlib绘图,模拟粒子衰变过程

2背景

通过以学习的模拟单个衰变的方法,考虑两个粒子A和B的衰变过程。假设A粒子衰变成B粒子的同时,B粒子也衰变成A粒子。模拟俩粒子组成的系统达到平衡的过程。

3正文

1.方程

已给出粒子数随时间改变速率的方程



运用泰勒近似得到的方程

可得


同时解出微分方程

2程序代码

  1. import pylab as pl
  2. class uranium_decay_A_and_B:
  3. def __init__(self,number_of_nuclei_A = 100,number_of_nuclei_B = 0, time_constant=1,time_of_duration = 5,time_step=0.1):
  4. self.n_uranium_A = [number_of_nuclei_A]
  5. self.n_uranium_B = [number_of_nuclei_B]
  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 nuclei A ->", number_of_nuclei_A)
  12. print("Initial number of nuclei B ->", number_of_nuclei_B)
  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. tmp_A = self.n_uranium_A[i] + (self.n_uranium_B[i] - self.n_uranium_A[i])/self.tau*self.dt
  19. tmp_B = self.n_uranium_B[i] + (self.n_uranium_A[i] - self.n_uranium_B[i])/self.tau*self.dt
  20. self.n_uranium_A.append(tmp_A)
  21. self.n_uranium_B.append(tmp_B)
  22. self.t.append(self.t[i] + self.dt)
  23. def show_results(self):
  24. pl.plot(self.t,self.n_uranium_A,'r')
  25. pl.plot(self.t,self.n_uranium_B)
  26. pl.xlabel('time($s$)')
  27. pl.ylabel('Number of Nuclei')
  28. pl.show()
  29. a = uranium_decay_A_and_B()
  30. a.calculate()
  31. a.show_results()
  32. from math import *
  33. class exact_results_check(uranium_decay_A_and_B):
  34. def show_results(self):
  35. self.et_A = []
  36. self.et_B = []
  37. for i in range(len(self.t)):
  38. temp_A = self.n_uranium_A[0]/2 + exp(-self.t[i])*self.n_uranium_A[0]/2
  39. temp_B = self.n_uranium_A[0]/2 - exp(-self.t[i])*self.n_uranium_A[0]/2
  40. self.et_A.append(temp_A)
  41. self.et_B.append(temp_B)
  42. pl.plot(self.t,self.et_A)
  43. pl.plot(self.t,self.et_B)
  44. pl.plot(self.t,self.n_uranium_A,'--')
  45. pl.plot(self.t,self.n_uranium_B,'--')
  46. pl.xlabel('time ($s$)')
  47. pl.ylabel('Number of Nuclei')
  48. pl.xlim(0, self.time)
  49. pl.show()
  50. b = exact_results_check()
  51. b.calculate()
  52. b.show_results()

3结果

模拟结果如下
20161008194242.png
与准确结果比较如下,虚线表示近似模拟,实线是准确结果
20161008194846.png

4结论

Euler method近似计算的结果与准确结果有一定误差,从图形中很容易得出,且近似的值总比准确值小,系统趋于平衡的准确时间大于近似的计算的时间。

5

感谢李云飞同学的公式输入法总结

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