I'm using a very simple system of differential equations:
from __future__ import division
import numpy as np
from scipy.integrate import odein
def Comp(state, t, u1, k1, y1, u2, k2, y2):
X1 = state[0]
X2 = state[1]
S = state[2]
dX1 = u1*(S/(k1+S))*X1
dX2 = u2*(S/(k2+S))*X2
dS = -(1/y1)*u1*(S/(k1+S))*X1 -(1/y2)*u2*(S/(k2+S))*X2
return [dX1, dX2, dS]
time = np.linspace(0, 10000, 100000)
states = odeint(Comp, [0.5, 0.5, 365], time, args=(0.25, 2, 0.35, 0.25, 1, 0.7))
print(states[-1])
[ 8.48291791e+01 8.73416418e+01 -7.74542370e-39]
with S
and X
being concentrations. Because of that S should never be negative, but when I solve this system with odeint S
always become negative after some time...
Can I enforce the desired behaviour somehow?