@XF
2016-10-09T15:39:41.000000Z
字数 1942
阅读 101
用Python语言编写解一个二元一阶齐次常微分方程组的程序,并解决实际问题。
用欧勒法(Euler method)来解常微分方程。对函数N(t)作泰勒展开:
取一阶近似:
对于题目方程:
由欧勒法有:
import pylab as plclass uranium_decay:def __init__(self, number_of_nuclei_A = 100, number_of_nuclei_B=0, time_constant = 1, time_of_duration = 5, time_step = 0.05):# unit of time is secondself.n_uranium_A = [number_of_nuclei_A]self.n_uranium_B = [number_of_nuclei_B]self.t = [0]self.tau = time_constantself.dt = time_stepself.time = time_of_durationself.nsteps = int(time_of_duration // time_step + 1)print("Initial number of nuclei A ->", number_of_nuclei_A)print("Initial number of nuclei B->", number_of_nuclei_B)print("Time constant ->", time_constant)print("time step -> ", time_step)print("total time -> ", time_of_duration)def calculate(self):for i in range(self.nsteps):tmpA = self.n_uranium_A[i] + (self.n_uranium_B[i] / self.tau -self.n_uranium_A[i] / self.tau)* self.dttmpB = self.n_uranium_B[i] + (self.n_uranium_A[i] / self.tau -self.n_uranium_B[i] / self.tau)* self.dtself.n_uranium_A.append(tmpA)self.n_uranium_B.append(tmpB)self.t.append(self.t[i] + self.dt)def show_results(self):pl.plot(self.t, self.n_uranium_A)pl.xlabel('time ($s$)')pl.ylabel('Number of Nuclei A')pl.show()pl.plot(self.t, self.n_uranium_B)pl.xlabel('time ($s$)')pl.ylabel('Number of Nuclei B')pl.show()a = uranium_decay()a.calculate()a.show_results()
最后都趋近于50
最后50
因为都有相同的衰变常数,且A到B和B到A的过程是可逆的,所以最后会趋近于100的中值,即.
感谢蔡老师的PPT 及杜威同学帮我解决了图片上传的问题。