I need help solving this coupled differential equation on Python. I keep getting
ID: 3741894 • Letter: I
Question
I need help solving this coupled differential equation on Python. I keep getting the following error.
File "C:/Users/Aus/Documents/PHYS639/Radioactivedecay1.py", line 24, in <module>
N = odeint(decay,N0,t)
File "C:UsersAusAnaconda3libsite-packagesscipyintegrateodepack.py", line 233, in odeint
int(bool(tfirst)))
RuntimeError: The size of the array returned by func (2) does not match the size of y0 (1).
Thanks for your help.
----------------------------------------------------------------------
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def decay(N,t):
alpha = 4
beta = 0.05
dadt = -alpha/t
dbdt = -alpha/t - beta/t
return([dadt,dbdt])
N0 = 1e7
t = np.linspace(1,1e9,10000)
N = odeint(decay,N0,t)
alpha = N[:,0]
beta = N[:,1]
plt.semilogy(t,alpha)
plt.semilogy(t,beta)
Explanation / Answer
You are seeing this error because the size of N0 does not match the size of the array returned by decay().
To solve the problem, you would need to make sure that the size of N0 array and array returned by decay() function are same.
NOTE: I cannot provide you the exact solution, since it depends on your requirements.
http://scipy-cookbook.readthedocs.org/items/numpy_scipy_ordinary_differential_equations.html
http://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.odeint.html
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.