Solving coupled system of ODEs with python

379 Views Asked by At

I have to numerically solve a coupled system of ODEs of the following form: $$\begin{align} \begin{cases} \dot{c}(t) = R(t)f(t)\\ \dot{R}(t) = R(t)G(t), \end{cases} \end{align}$$ where $c(t), f(t) \in \mathbb{R}^3, R(t), G(t) \in \mathbb{R}^{3 \times 3}$.
I usually solve ODEs with solve_ivp from scipy.integrate and matrix valued ODEs with the wrapper from the odeintw package. Is there a wrapper for coupled systems too?

1

There are 1 best solutions below

0
On BEST ANSWER

Are you thinking about some general wrapper or of how to construct your own wrapper like

def odesystem(t,u):
    c, R = u[:3], u[3:12].reshape([3,3])
    dc = R.dot(f(t))
    dR = G(t).dot(R)
    return np.concatenate([dc, dR.flatten()])

You could also use odeintw with a $4\times 3$ array as state object, where then c is the first row and R the second to fourth row, c,R=u[0],u[1:4].