Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Runge Kutta for 4 coupled differential equations

  1. Oct 14, 2014 #1
    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)

    Thanks in advance
     
  2. jcsd
  3. Oct 15, 2014 #2

    DrClaude

    User Avatar

    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).
     
  4. Oct 15, 2014 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
     
  5. Oct 15, 2014 #4
    Thanks for the responses !
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Runge Kutta for 4 coupled differential equations
  1. Runge kutta (Replies: 4)

Loading...