Runge Kutta for 4 coupled differential equations

Click For Summary
SUMMARY

The discussion focuses on implementing the Runge-Kutta 4th order method to solve a system of four coupled differential equations involving functions f(t), g(t), h(t), and w(t). The user seeks guidance on applying this method, as existing references typically address functions with multiple variables. It is established that the user should define a function that takes the current values of the dependent variables and the independent variable t, returning the derivatives. The GNU Scientific Library (GSL) is recommended for C programming, and a simple RK4 integrator can be implemented based on resources like Numerical Recipes in C.

PREREQUISITES
  • Understanding of differential equations and their solutions
  • Familiarity with the Runge-Kutta method, specifically the 4th order
  • Proficiency in C programming and use of the GNU Scientific Library (GSL)
  • Basic knowledge of numerical methods and integration techniques
NEXT STEPS
  • Implement the Runge-Kutta 4th order method using GSL in C
  • Study the Numerical Recipes in C, particularly Chapter 16 on RK4 integrators
  • Explore Python libraries like SciPy for solving differential equations
  • Research techniques for handling coupled differential equations in numerical simulations
USEFUL FOR

Researchers, engineers, and programmers working on numerical solutions for systems of differential equations, particularly those using C or Python for scientific computing.

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
8K
  • · 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
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K