1

I have two differential equations:

\begin{align}\frac{dx}{dt} &= 1 -(1+b)x+ax^2y\\ \frac{dy}{dt} &= bx - ax^2y\end{align}

I have been asked to solve them on Python using the Runge Kutta (4th order) method. I know how to solve a single ODE using this method, but don't know how to extend it to a system of ODEs.

Any help (or pointers) would be greatly appreciated,

Jack

Jack
  • 645

1 Answers1

1

HINT

You can reduce your system using the first equation: $$ ax^2y = x' - 1+b+bx $$ and so $$ y = \frac{x' - 1+b+bx}{ax^2} $$ (assuming $a \ne 0$) and now your ODE system will become a 2nd order ODE.

gt6989b
  • 54,930
  • Thanks! Do I just substitute y from above into the bottom ode in my question? And then apply Runge Kutta? – Jack Mar 16 '17 at 15:59
  • @Jack yes, don't forget to compute $y'$ first :) Note that if you just add your equations, you get $x' + y' = 1-x$... – gt6989b Mar 16 '17 at 16:00
  • However, this helps you nothing with Runge-Kutta, as most numerical methods are formulated for first order systems. And if you wanted to reduce complexity, you would see that in the sum of both equations $x'+y'=1$ so that $x+y=t+C$. – Lutz Lehmann Mar 16 '17 at 16:11
  • 1
    Actually, converting nice smooth system of ODEs to a first order ODE with singularities is a bad idea when using numerical methods. – Evgeny Mar 16 '17 at 17:08
  • @Evgeny i agree, but if the only thing OP known how to implement is this, why not let him implement it in an unstable way instead of implementing nothing or spending a week reading up? – gt6989b Mar 17 '17 at 18:14
  • @gt6989b I agree that something here is slightly better than nothing :) but seriously, rewriting Runge-Kutta for systems of ODEs doesn't take a week reading up -- it's a matter of few hours at worst and ten minutes at best. Sometimes your suggestion is useful (see Henon trick which is used for refining Poincare map). – Evgeny Mar 17 '17 at 18:36