Assignment 8
Assignment 8
# Parameters
a = 10.0
b = 1.0
dt = 0.01 # time step
T = 10.0 # total time for simulation
N = int(T / dt) # number of steps
1
[36]: import numpy as np
import matplotlib.pyplot as plt
# Parameters
tau = 1.0
dt = 0.01 # time step (s)
T = 5.0 # total time (s)
steps = int(T/dt)
# Initialize arrays
time = np.linspace(0, T, steps+1)
N_A = np.zeros(steps+1)
N_B = np.zeros(steps+1)
# Euler integration
for i in range(steps):
dN_A = (N_B[i] - N_A[i]) / tau
dN_B = (N_A[i] - N_B[i]) / tau
N_A[i+1] = N_A[i] + dt * dN_A
N_B[i+1] = N_B[i] + dt * dN_B
2
N_avg = 50
plt.axhline(y=N_avg, color='r', linestyle='--', label=f'equilibrium')
# Plotting results
plt.plot(time, N_A, label=r'$N_A(t)$')
plt.plot(time, N_B, label=r'$N_B(t)$')
plt.xlabel('Time (s)')
plt.ylabel('Number of Nuclei')
plt.title('Radioactive Decay: Two-Step Process')
plt.legend()
plt.grid(True)
plt.show()
3
# Create a one-variable function
f = lambda x: Lagrange(z, T, x)
# Derivative at z = 0
dTdz_0 = central_diff(f, 0, h=1e-3)