Runge Kutta for 4 coupled differential equations

UberG
Messages
2
Reaction score
0
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
 
Physics news on Phys.org
UberG said:
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).
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).
 
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.
 
Thanks for the responses !
 
Are there any good visualization tutorials, written or video, that show graphically how separation of variables works? I particularly have the time-independent Schrodinger Equation in mind. There are hundreds of demonstrations out there which essentially distill to copies of one another. However I am trying to visualize in my mind how this process looks graphically - for example plotting t on one axis and x on the other for f(x,t). I have seen other good visual representations of...
Back
Top