Runge Kutta for 4 coupled differential equations

Click For Summary

Discussion Overview

The discussion revolves around implementing the Runge-Kutta 4th order method to solve a system of four coupled differential equations. Participants explore the application of this numerical method in programming, particularly in C and Python, while addressing the nature of dependent and independent variables in the context of the equations.

Discussion Character

  • Technical explanation, Mathematical reasoning, Homework-related

Main Points Raised

  • One participant seeks guidance on applying the Runge-Kutta 4th order method to a set of equations involving four dependent variables and one independent variable.
  • Another participant clarifies the distinction between dependent and independent variables, suggesting that the dependent variables in the equations are ##f, g, h,## and ##w##, while ##t## is the independent variable.
  • A different approach is proposed, suggesting the use of four separate Runge-Kutta solvers running simultaneously to calculate the next values of the variables based on their previous values.

Areas of Agreement / Disagreement

Participants present differing approaches to implementing the Runge-Kutta method, with no consensus on a single solution or method being established.

Contextual Notes

Participants mention the potential use of libraries like GSL in C and reference resources such as Numerical Recipes in C for implementing the RK4 integrator, but do not resolve specific implementation details or challenges.

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 !
 

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
9K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K