# Runge Kutta for 4 coupled differential equations

Tags:
1. Oct 14, 2014

### UberG

Hi,

I'm not a bright programmer , but I have to solve the fallowing equations:

$\frac{df}{dt} = \alpha f -\beta f + \theta g - (f+h)f$

$\frac{dg}{dt} = \psi f- \phi g$

$\frac{dh}{dt} = \xi f+ \mu h -\tau h + \epsilon w- (f+h)h$

$\frac{dw}{dt} = \nu h - \chi h$

Where $f(t)$ , $g(t)$ , $h(t)$ and $w(t)$ are only functions of $t$. Every reference I read for Runge Kutta 4th order Method mentions a function with more than 1 variable (i.e http://www.phy.davidson.edu/FacHome/dmb/py200/RungeKuttaMethod.htm).

My question: how can I implement the Runge-Kutta 4th order method for solve theses equations?

(OBS: I'm familiar with C and Python)

2. Oct 15, 2014

### Staff: Mentor

Don't confuse dependent and independent variables. In your case, you actually have four dependent variables $f,g,h,w$, and one independent $t$. The $y$ and $z$ in the link you gave play the role of, say $f$ and $g$ (if we were to ignore $h$ and $w$), and $x$ is $t$.

In C, I would suggest using GSL. You will basically only need to code a function taking current values of $y_i \in \{f,g,h,w\}$ and $t$ and returning the values $dy_i/dt$. The integrator will then take that and give you back solutions for subsequent times. It is also not very complicated to implement a simple RK4 integrator from scratch, see for instance Numerical Recipes in C (chapter 16).

3. Oct 15, 2014

### HallsofIvy

Staff Emeritus
I would do this as four separate "Runge-Kutta" solvers running simultaneously. That is, do a loop over the t values, calculating the next value of f, g, h, and w as functions of the previous values of all four.

4. Oct 15, 2014

### UberG

Thanks for the responses !