Radioactivity
import numpy as np
import matplotlib.pyplot as plt
import random
from scipy.integrate import odeint
from scipy.integrate import solve_ivp
Rate of decay of a radioactive nuclei is $$\frac{dN}{dt} = -\lambda N $$
This is a first order differential equation which can be solved by any standard method. But, we must mention initial condition of the decay, i.e. at time $t=0$, what is number of radioactive nuclei $N(0)$ present in the substance? Consider, $$\text{at}~~~ t=0, \hspace{1cm}N(0)=N_0$$
N0 = 1000
T_half = 4.5*60
lamda = 1/ T_half
t_init, t_final, step_size = 0, 1000, 1
t = np.arange(t_init, t_final, step_size)
def model(N, t):
return -lamda*N
sol = odeint(model, N0, t)
N = sol[:, 0]
plt.plot(t, N, ls='--', color='red', label='Parent nucleus')
plt.plot(t, N0 - N, ls='--', color='blue', label='Daughter nucleus')
plt.legend()
plt.show()
def model(t, N): # order of the argument is very important; first independent and then dependent variable
return -lamda*N
sol = solve_ivp(model, t_span=(t[0], t[-1]), y0=([N0]), t_eval= t)
t = sol.t
N = sol.y.T
plt.plot(t, N, ls='--', color='green', label='Parent nucleus')
plt.plot(t, N0 - N, ls='--', color='orange', label='Daughter nucleus')
plt.legend()
plt.show()
P = [] # Parent Nucleus
D = [] # Daughter Nucleus
T_half = 4.5*60 # Half life
lamda = 1/ T_half # Decay constant
N = 1000 # Initial number of Radioactive nuclei
Np, Nd = N, 0
time = np.arange(0, 1000, 1)
for t in time:
P.append(Np)
D.append(Nd)
decay = 0
for n in range(Np):
p = random.random()
if p < lamda:
decay += 1
Np -= decay
Nd += decay
plt.plot(P, linestyle='-', color='red', label='Parent Nucleus')
plt.plot(D, linestyle='-', color='blue', label='Daughter Nucleus')
plt.legend()
plt.xlabel('t', fontsize=14)
plt.ylabel('N(t)', fontsize=14)
plt.show()