Copy (carefully) the numerical recipes routine ``rk4'' from NR 16.1 to a file named ``p480.c'' and modify it to produce a function of the following form:
void rk4p480(double y[], double dydx[], int n, double x, double h, double yout[], void (*derivs)(double, double [], double [], int, double [], double [], double [], int), int k, int dk, double f[], double r[], double dr[], int N)Output:
- yout[]: Vector solution of ODE advanced one step according to Runge-Kutta.
Input:
- y[]: Value of initial vector.
- dydx[]: space to store evaluation of derivative vector returned by routine ``derivs()''.
- n: dimensionality of the ODE.
- x: initial value of independent variable in ODE.
- h: interval width.
- derivs: pointer to routine which evaluates derivative vector.
- k: index of arrays f[], r[], dr[] which corresponds to x (k=N x).
- dk: change in array index corresponding to h (dk=N h).
- f[]: array of function values which may enter ODE.
- r[], dr[], N: change of variables information as in Problem Set #1.
Notes:
Be certain to modify ``rk4'' to function entirely in double precision. For this, you must not only declare all variables double precision, but also must replace the calls to ``vector()'' and ``free_vector()'' with calls to to ``dvector()'' and ``free_dvector()'', repectively.
To be able to access the input arrays f[], r[], dr[] properly, treat the indices k and dk as integer versions of x and h: (1) when ``rk4p480()'' defines xh=x+hh with hh=h/2, define kh=k+dk/2; (2) whenever ``rk4p480()'' calls ``derivs()'', add five new appropriate arguments to the call (k,f,r,dr,N); (3) make sure that the appropriate value for k (either k, kh or k+dk) is passed to each call to ``derivs()'', paralleling how rk4p480 treats x.