[关闭]
@wudawufanfan 2016-10-01T09:56:19.000000Z 字数 5693 阅读 469

The numerical problem in the decays of two types of nucleus

calculation decay nucles


Introduction

A radioactive decay problem involving two types of nuclei,A and B,with populations and .That the type A nuclei decay to form type B nuclei according to the differential equations



while for simplicity.
Now we should solve this system of equations for the numbers of nuclei, and , as functions of time.

  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Oct 1 14:44:46 2016
  4. @author: 帆帆
  5. """
  6. import pylab as pl
  7. class uranium_decay:
  8. def __init__(self, number_of_nuclei_A = 100, number_of_nuclei_B=0, time_constant = 1, time_of_duration = 5, time_step = 0.05):
  9. # unit of time is second
  10. self.n_uranium_A = [number_of_nuclei_A]
  11. self.n_uranium_B = [number_of_nuclei_B]
  12. self.t = [0]
  13. self.tau = time_constant
  14. self.dt = time_step
  15. self.time = time_of_duration
  16. self.nsteps = int(time_of_duration // time_step + 1)
  17. print("Initial number of nuclei A ->", number_of_nuclei_A)
  18. print("Initial number of nuclei B->", number_of_nuclei_B)
  19. print("Time constant ->", time_constant)
  20. print("time step -> ", time_step)
  21. print("total time -> ", time_of_duration)
  22. def calculate(self):
  23. for i in range(self.nsteps):
  24. tmpA = self.n_uranium_A[i] + (self.n_uranium_B[i] / self.tau -self.n_uranium_A[i] / self.tau)* self.dt
  25. tmpB = self.n_uranium_B[i] + (self.n_uranium_A[i] / self.tau -self.n_uranium_B[i] / self.tau)* self.dt
  26. self.n_uranium_A.append(tmpA)
  27. self.n_uranium_B.append(tmpB)
  28. self.t.append(self.t[i] + self.dt)
  29. def show_results(self):
  30. pl.plot(self.t, self.n_uranium_A)
  31. pl.xlabel('time ($s$)')
  32. pl.ylabel('Number of Nuclei A')
  33. pl.show()
  34. pl.plot(self.t, self.n_uranium_B)
  35. pl.xlabel('time ($s$)')
  36. pl.ylabel('Number of Nuclei B')
  37. pl.show()
  38. a = uranium_decay()
  39. a.calculate()
  40. a.show_results()

[the two results and the combination]QQ截图20161001151230.jpgQQ截图20161001151242.jpg
QQ截图20161001153420.jpg

In attacking the radioactive decay problem we were led to treat time as a discrete variable.Such a discretization of time,or space,or both,is a common practice in numerical calculation,and brings up two related questions:

  1. How do we konw that the errors introduced by this discretencess are negligible
  2. How do we choose the value of such a step size for a calculation
    We know

    =
    solve this first order differential equations with initial conditions we have
  1. import pylab as pl
  2. class uranium_decay:
  3. def __init__(self, number_of_nuclei_A = 100, number_of_nuclei_B=0, time_constant = 1, time_of_duration = 5, time_step = 0.05):
  4. # unit of time is second
  5. self.n_uranium_A = [number_of_nuclei_A]
  6. self.n_uranium_B = [number_of_nuclei_B]
  7. self.t = [0]
  8. self.tau = time_constant
  9. self.dt = time_step
  10. self.time = time_of_duration
  11. self.nsteps = int(time_of_duration // time_step + 1)
  12. print("Initial number of nuclei A ->", number_of_nuclei_A)
  13. print("Initial number of nuclei B->", number_of_nuclei_B)
  14. print("Time constant ->", time_constant)
  15. print("time step -> ", time_step)
  16. print("total time -> ", time_of_duration)
  17. def calculate(self):
  18. for i in range(self.nsteps):
  19. tmpA = self.n_uranium_A[i] + (self.n_uranium_B[i] / self.tau -self.n_uranium_A[i] / self.tau)* self.dt
  20. tmpB = self.n_uranium_B[i] + (self.n_uranium_A[i] / self.tau -self.n_uranium_B[i] / self.tau)* self.dt
  21. self.n_uranium_A.append(tmpA)
  22. self.n_uranium_B.append(tmpB)
  23. self.t.append(self.t[i] + self.dt)
  24. def show_results(self):
  25. pl.plot(self.t, self.n_uranium_A,'r')
  26. pl.plot(self.t, self.n_uranium_B,'g',)
  27. pl.xlabel('time ($s$)')
  28. pl.ylabel('Number of Nuclei ')
  29. pl.show()
  30. import math
  31. class exact_results_check(uranium_decay):
  32. def show_results(self):
  33. self.etA = []
  34. self.etB = []
  35. for i in range(len(self.t)):
  36. tempA = 50+50*math.exp(- self.t[i] / self.tau)
  37. tempB = 50-50*math.exp(- self.t[i] / self.tau)
  38. self.etA.append(tempA)
  39. self.etB.append(tempB)
  40. pl.plot(self.t, self.etA)
  41. pl.plot(self.t, self.etB)
  42. pl.plot(self.t, self.n_uranium_A, '*')
  43. pl.plot(self.t, self.n_uranium_B, '*')
  44. pl.xlabel('time ($s$)')
  45. pl.ylabel('Number of Nuclei')
  46. pl.xlim(0, self.time)
  47. pl.show()
  48. a = exact_results_check()
  49. a.calculate()
  50. a.show_results()

QQ截图20161001162613.jpg

clearly,the simulation results is a bit different from the real result.

Improvement

  1. import pylab as pl
  2. class uranium_decay:
  3. def __init__(self, number_of_nuclei_A = 100, number_of_nuclei_B=0, time_constant = 1, time_of_duration = 5, time_step = 0.05):
  4. # unit of time is second
  5. self.n_uranium_A = [number_of_nuclei_A]
  6. self.n_uranium_B = [number_of_nuclei_B]
  7. self.t = [0]
  8. self.tau = time_constant
  9. self.dt = time_step
  10. self.time = time_of_duration
  11. self.nsteps = int(time_of_duration // time_step + 1)
  12. print("Initial number of nuclei A ->", number_of_nuclei_A)
  13. print("Initial number of nuclei B->", number_of_nuclei_B)
  14. print("Time constant ->", time_constant)
  15. print("time step -> ", time_step)
  16. print("total time -> ", time_of_duration)
  17. def calculate(self):
  18. for i in range(self.nsteps):
  19. tmpA = self.n_uranium_A[i] + (self.n_uranium_B[i] / self.tau -self.n_uranium_A[i] / self.tau)* self.dt
  20. tmpB = self.n_uranium_B[i] + (self.n_uranium_A[i] / self.tau -self.n_uranium_B[i] / self.tau)* self.dt
  21. self.n_uranium_A.append(tmpA)
  22. self.n_uranium_B.append(tmpB)
  23. self.t.append(self.t[i] + self.dt)
  24. class diff_step_check(uranium_decay):
  25. def show_results(self, style = 'b'):
  26. pl.plot(self.t, self.n_uranium_A, style)
  27. pl.plot(self.t, self.n_uranium_B, style)
  28. pl.xlabel('time ($s$)')
  29. pl.ylabel('Number of Nuclei')
  30. pl.xlim(0, self.time)
  31. from pylab import *
  32. b = diff_step_check(number_of_nuclei_A=100,number_of_nuclei_B=0, time_constant=1,time_of_duration = 5, time_step = 0.05)
  33. b.calculate()
  34. b.show_results()
  35. c = diff_step_check(number_of_nuclei_A=100,number_of_nuclei_B=0, time_constant=1,time_of_duration = 5, time_step = 0.0001)
  36. c.calculate()
  37. c.show_results('r')
  38. show()

QQ截图20161001171304.jpg
QQ截图20161001171526.jpg

Change the time step didn't change the curve much.But we know this result is different from the real result a lot.So there may be another way to improve the accuracy of numerical results.

Conclusion

The numerical results are consistent with the idea that the system reaches a steady state in which and are constant.d/dt and d/dt vanish as well.

Thanks

Thanks for Caihao's PPT.

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