I have tried to use dsolve, but when I run my code I get errors. I think I am using the wrong syntax, or setting up the problem wrong. Consider the even simpler two-compartment model at steady state. The following code works fine:
import sympy as sym
fractAB = .1
fractBA = .2
A, B, flowAB, storeB, flowBA = sym.S('A, B, storeB, flowAB, flowBA'.split(','))
equations = [
sym.Eq(A,10),
sym.Eq(flowAB, A*fractAB),
sym.Eq(A, flowBA - flowAB),
sym.Eq(B, storeB + flowAB - flowBA),
sym.Eq(flowBA, B*fractBA)
]
res = sym.solve(equations)
To make fractAB and fract BA functions of time, which is what I am after, I tried the following:
import sympy as sym
t, A = sym.S('t, A'.split(','))
B, flowAB, storeB, flowBA, fractAB, fractBA = sym.symbols(
'B, storeB, flowAB, flowBA, fractAB, fractBA'.split(','), cls=sym.Function)
equations = (
sym.Eq(A,10),
sym.Eq(flowAB(t), A*fractAB(t)),
sym.Eq(A, flowBA(t) - flowAB(t)),
sym.Eq(B(t), storeB(t) + flowAB(t) - flowBA(t)),
sym.Eq(flowBA(t), B(t) * fractBA(t)),
sym.Eq(fractAB(t), .1*t),
sym.Eq(fractAB(t), .2*t)
)
res = sym.dsolve(equations)
But I get this error:
File "/usr/local/lib/python2.7/dist-packages/sympy/solvers/ode.py", line 1349, in classify_sysode
t = list(list(eq[0].atoms(Derivative))[0].atoms(Symbol))[0]
IndexError: list index out of range
Can anyone suggest where I am going wrong? I think my syntax is not right.
Thanks.