How Does the 4th Order Runge-Kutta Method Solve Coupled First Order Linear ODEs?

2 replies · 3K views · last reply
snelson989
Messages
3
Reaction score
0
I just need to know the general form of the 4th order Runge-Kutta method?
For two coupled first order linear ODEs.
I can not find it specifically written online, I need it to write a program for the structure of white dwarfs stars, but I am okay with the Physics, just I have never used the runge-Kutta method.

Thanks.
 
Welcome to PF!

Searching your references for "Runge Kutta 4", or simply "RK4", should provide you with equations that you very easily can turn into a program. If you are not supposed to implement the method yourself, then searching for both RK4 and your favorite language at the same time may even provide you with a code snippet.
 
For one ODE:

To approximate the solution of the initial-value problem
y' = f(t, y), a <t <b, y(a) = y0,
at (N + 1) equally spaced numbers in the interval [a,b]:
INPUT endpoints a, b; integer N; initial condition y0.
OUTPUT approximation w to y at the (N + 1) values of t.
Step 1 Set h = (b - a)/N;
t = a;
w = y0;
OUTPUT (t, w).
Step 2 For i = 1, 2,... , N do Steps 3-5.
Step 3 Set K1=hf(t,w);
K2 = hf(t + h/2,w + K1 /2);
K3 = hf(t+h/2,w + K2/2);
K4 = hf(t + h,w + K3).
Step 4 Set w = w + (K1 + 2K2 + 2K3 + K4)/6; (Compute w_i)
t = a + ih. (Compute t_i)
Step 5 OUTPUT (t, w).