Lab 3 : Euler Radioactive Decay - ChrisPerez13/CompPhys GitHub Wiki
Background
Ordinary Differential Equation
An ordinary differential equation (ODE) is a function that is dependent on a single variable.
Taylor Expansion
A Taylor expansion is a way of approximating complex functions like an ODE. They are important since we can understand the behavior of these complex functions to estimate values and study trends.
Euler Method
The Euler Method is a method of solving ODEs with given initial values. The Euler method is important to learn in code because it allows us to find solutions for ODEs that would be difficult to solve analytically. The general form for the Euler method is:
y[i] = y[i-1] - y[i-1]/x * dt
t[i] = t[i-1] + dt
The Lab
The Euler Method
The Euler Method calculates the decay of Uranium atoms by taking inputs of the time array (t), the array for the number of nuclei(n_nuclei), the time step (dt), and the half-life of nuclei (tau).
def calculate(t,n_nuclei,dt,tau):
for i in range(1,len(t)):
n_nuclei[i] = n_nuclei[i-1] - n_nuclei[i-1]/tau * dt
t[i] = t[i-1] + dt
return t,n_nuclei
Analytical Solution
The analytical solution is easy to find in this example but it still shows how accurate and useful the analytical solution can be.
plt.plot(t,n_nuclei,'ks')
# plot the analytic solution using a solid black line
analytic= No*np.exp((-t/tau))
plt.plot(t,analytic,'k')
Effect of Time Step
The time step (dt) accuracy of the data means the smaller number means a more accurate and precise solution, while the larger time step leads to less accurate solutions. Smaller time steps could cause the code to run slower since more time points are being measured and more computations take place.