I'm having some trouble using odeint to solve piece-wise odes when the time limits are very big. I have included here a minimalist example:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
t0 = 1.5e+21
t_end = 4.4e+23
t= np.linspace(t0,t_end,10000)
def DMonly(y,tt):
return 1. if tt>=(t0+t_end)/2. else 0.
plt.semilogx(t,odeint(DMonly,0.,t),marker='.')
plt.show()
The solution should be y=0 for the first half and then increase linearly for the second half yet I get that y=0 always, as in this plot.
If I take the exact same problem but now with different values for t0 and t_end:
t2= np.linspace(1.,100.,10000)
def DMonly2(y,tt):
return 1. if tt>=(1.+100.)/2. else 0.
plt.plot(t2,odeint(DMonly2,0.,t2),marker='.')
plt.xlabel('t')
plt.ylabel('y(t)')
plt.show()
Now the solution is well behaved as in this plot.