'Obtaining coefficient from non linear ODE

I'm trying to solve non-linear ODE in the form of dy/dt = a(y, t) * y(t) with scipy.integrate.ode. I'm getting good results solving this kind of equation, but I wish to optimize my code.

Currently, my function is defined as f(y, t) = a(y, t)*y(t), and returns dy_dt. The problem is that I wish to get a(y,t) as well.

One solution would be to solve the problem, getting y(t) and re-computing a(y, t) for each desired time step. But this isn't highly efficient since a(y, t) has already been computed to solve the problem.

Is there a way I can get both dy_dt and a(y,t) in an efficient way simultaneously?

I've already read the DOC of scipy.integrate.ode, but I can't find any solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source