I have been trying to solve the following system of three coupled differential equations using odeint and solve_ivp. (This is not the exact system. I have modified it just to improve the readability of the question.)
def model(x,t): # x is a list containing the values of u,v,w as they change with time t
u = x[0]
v = x[1]
w = x[2]
dudt = u - u*v
dvdt = -v + u*v - v*w**2
dwdt = -w + 2*v*w
return [dudt, dvdt, dwdt]
This works fine. But now I want to modify this in the following way: whenever either of u,v or w goes below a threshold, it is reset to zero, and then let the system evolve. This should happen every time any of these three goes before the threshold automatically. The 'rules' of evolving the system remain the same.
I have tried modifying the code by doing this:
def model(x,t): # x is a list containing the values of u,v,w as they change with time t
u = x[0]
v = x[1]
w = x[2]
if u < u_threshold:
x[0] = 0
dudt = u - u*v
dvdt = -v + u*v - vw**2
dwdt = -w + 2*v*w
return [dudt, dvdt, dwdt]
I have shown it only for u, but you get the idea. This does not seem to work.
Please note that I cannot afford to stop the simulation every time any variable hits the threshold value, as this is only a toy-model. Later on, I will generalise this to systems of hundreds of coupled equations.