#include #include #include "RK.h" /* Runge-Kutta method solve an ordinary differential equation dx/dt = f(x,t) where x is an n-dimensional vector consisting of n variables. you can find how to use this function in rungekutta-t0.c rungekutta-t1.c rungekutta-t2.c */ /* solve an ordinary differential equation dx/dt = f(x,t) from the k-th time step to the (k+1)-th time step input: n dimension of vector x x[] value of vector x at the k-th time step diff() procedure to compute f(x,t) *pt time at the k-th time step dt time step (interval) procedure diff() should be in the following form: diff(int n, double x[], double t, double v[]) n dimension of vector x x[] vector (n-dimensional array) t time v[] array where value of f(x,t) is stored (n-dimensional array) output: x[] value of vector x at the (k+1)-th time step *pt time at the (k+1)-th time step */ extern void RungeKuttaOneStep(int n, double x[], void diff(int, double *, double, double *), double *pt, double dt) { int i; double x1[MaxVars], x2[MaxVars], x3[MaxVars]; double d1[MaxVars], d2[MaxVars], d3[MaxVars], d4[MaxVars]; diff(n, x, *pt, d1); /* comp. d1 */ for(i=0;i MaxVars) { fprintf(stderr, "%d exceeds MaxVars (%d)\n", n, MaxVars); fprintf(stderr, "increase MaxVars in opt.h and recompile all\n"); exit(1); } for(k=1; k<=kcnt; k++) { #if DEBUG printf("<<<<< count = %d >>>>>\n", k); #endif RungeKuttaOneStep(n, x, diff, pt, dt); RungeKuttafprint(fd, n, x, *pt); //fprintf(fd, format, *pt); //for(i=0;i