function uses the fourth-order
Runge-Kutta method to advance a solution to a system of
ordinary differential equations one time-step
, given values for the variables
and their derivatives
RK4 is based on the routine
described in section 16.1 of
Numerical Recipes in C: The Art of Scientific Computing
(Second Edition), published by Cambridge University Press, and is used by permission.
Result = RK4(
Y, Dydx, X, H, Derivs
A vector of values for
A vector of derivatives for
A scalar value for the initial condition.
A scalar value giving interval length or step size.
A scalar string specifying the name of a user-supplied IDL function that calculates the values of the derivatives
. This function must accept two arguments: A scalar floating value
, and one
. It must return an
-element vector result.
For example, suppose the values of the derivatives are defined by the following relations:
= 4.0 - 0.3
We can write a function DIFFERENTIAL to express these relationships in the IDL language:
FUNCTION differential, X, Y
RETURN, [-0.5 * Y, 4.0 - 0.3 * Y - 0.1 * Y]
Set this keyword to force the computation to be done in double-precision arithmetic.
To integrate the example system of differential equations for one time step, H:
H = 0.5
X = 0.0
Y = [4.0, 6.0]
dydx = DIFFERENTIAL(X,Y)
result = RK4(Y, dydx, X, H, 'differential')
This is the exact solution vector to five-decimal precision.