I want to solve a system of 4 coupled differential equations with python (sympy):
eqs = [Eq(cP1(t).diff(t), k1*cE1(t)**3), Eq(cE1(t).diff(t), -k1 * cE1(t)**3 + k6 * cE3(t)**2), Eq(cE2(t).diff(t), -k8 * cE2(t)), Eq(cE3(t).diff(t), k8 * cE2(t) - k6 * cE3(t)**2)]
When I try to solve the system with "dsolve_system":
solution = dsolve_system(eqs, ics={cP1(0): 0, cE1(0): cE1_0, cE2(0):cE2_0, cE3(0):cE3_0})
I get the answer: "NotImplementedError:
The system of ODEs passed cannot be solved by dsolve_system."
Does anyone know, whats the problem? Or is there a better way of solving this system of Differential equations in Sympy?
Thanks a lot!
It's generally nice and friendly to show the complete code:
This means that
dsolvecan not yet handle this particular type of system. Note that in general nonlinear systems of ODEs are very unlikely to have analytic solutions (dsolveis for finding analytic solutions, if you want numerical solutions use something like scipy'sodeint).As nonlinear systems go this one is relatively friendly so it might be possible to solve it. Let's see...
Firstly there is a conserved quantity (the sum of all 4 variables) that we can use to eliminate one equation. Actually that doesn't help as much because the first equation is already isolated from the others: if we knew
cE1we could just integrate but the conserved quantity gives it more easily if the other variables are known.The structure of the system is like:
implying that it can be solved as a sequence of ODEs where we solve the 3rd equation for cE2 and then the 4th equation for cE3 and then use that for cE1 and so on. So we can reduce this to a problem involving a sequence of mostly nonlinear single ODEs. That also is very unlikely to have an analytic solution but let's give it a try:
At this point in principle we could solve for
cE3here but sympy doesn't have any way of solving this particular nonlinear ODE sodsolvegives a series solution (I don't think that's what you want) and the only other solver that might handle this islie_groupbut that actually fails.Since we can't get an expression for the solution for
cE3we also can't go on to solve for cE1 and cP1. The ODE that fails there is a Riccati equation but this particular type of Ricatti equation is not yet implemented indsolve. It looks like Wolfram Alpha gives an answer in terms of Bessel functions: https://www.wolframalpha.com/input/?i=solve+dx%2Fdt+%3D+e%5E-t+-+x%5E2Judging from that I guess it's unlikely that we would be able to solve the next equation. At that point Wolfram Alpha also gives up and says "classification: System of nonlinear differential equations": https://www.wolframalpha.com/input/?i=solve+dx%2Fdt+%3D+e%5E-t+-+x%5E2%2C+dy%2Fdt+%3D+-y%5E3+%2B+x%5E2
I suspect that there is no analytic solution for your system but you could try numerical solutions or otherwise a more qualitative analysis.