I have written the following code to see in which t
my ODE "exponential_decay" crosses the zero line. this is Brent Method
.
odr, hr, dr, cr, m = np.genfromtxt('data.txt',unpack=True)
n=0
with open('RDE_nob_trans.txt', 'w') as d:
for i in range(len(dr)):
c = cr[i]
initp = dr[i]
exponential_decay = lambda t, y: -(1/(1+t)) * (2 *(1-y)* (-2 + (y/c)) + 3 - 3 * y)
t_span = [0, 1] # Interval of integration
y0 = [initp] # Initial state: y(t=t_span[0])=2
desired_answer = odr[i]
sol_ode = solve_ivp(exponential_decay, t_span, y0) # IVP solution
f_sol_ode = interp1d(sol_ode.t, sol_ode.y) # Build interpolated function
ans = brentq(lambda x: f_sol_ode(x) - desired_answer, t_span[0], t_span[1])
d.write("{0} {1} {2} {3} {4}\n".format(hr[i], dr[i], cr[i], m[i], ans))
In this code we know the initial point initp = dr[i]
, we know the value of the differential equation at the zero crossing desired_answer = odr[i]
, and we are willing to find in which t
we have this answer. It is OK and we get the answer by this code. ans
is the t
at the zero crossing.
My problem is what should we do if our answer of ODE which now is desired_answer = odr[i]
is not just a number and is a value in terms of t
.
I mean using odr[i]
we are reading the data file and subsequently reading numbers. Now consider we have someting like odr = 0.1 * t, 0.12 *t, 0.23 *t etc.
which is not a number and is a function in terms of t
.