- We wish to solve the system of differential equations

- The pseudo-code is:
x - scalar; y, k1, k2, k3, k4, slope are vectors; n number of equations; h is step size.
On exit, both x and y are updated for the next station in marching.
SUB RK4 ( x , y , n , h )
CALL Derivs ( x , y , k1 )
DO i = 1 , n
     ym ( i ) = y ( i ) + k1 ( i ) * h / 2
END DO
xm = x + h / 2
CALL Derivs ( xm , ym , k2 )
DO i = 1 , n
     ym ( i ) = y ( i ) + k2 ( i ) * h / 2
END DO
CALL Derivs ( xm , ym , k3 )
DO i = 1 , n
     ym ( i ) = y ( i ) + k3 ( i ) * h
END DO
xm = x + h
CALL Derivs ( xm , ym , k4 )
DO i = 1 , n
     slope ( i ) = ( k1 ( i ) + 2 * ( k2 ( i) + k3 ( i ) ) + k4 ( i ) ) / 6
     y ( i ) = y ( i ) + slope ( i ) * h
END DO
x = xm
END
SUB Derivs ( x , y , f )
f ( 1 ) = function-1 ( x , y )
f ( 2 ) = function-2 ( x , y )
...
f ( n ) = function-n ( x , y )
END
|