#include #include #include "RK.h" /* d x0 / dt = (a^2 - x0^2 - x1^2) x0 - x1 d x1 / dt = (a^2 - x0^2 - x1^2) x1 + x0 */ #define NumVars 2 #define Radius 2.5 static void differential(int n, double x[], double t, double value[]) { value[0] = ( Radius*Radius - x[0]*x[0] - x[1]*x[1] ) * x[0] - x[1]; value[1] = ( Radius*Radius - x[0]*x[0] - x[1]*x[1] ) * x[1] + x[0]; } main() { int kcnt; double t, dt, tend; double x[NumVars]; char *filename = "rkf-adp-t3.dat"; FILE *fd; if ((fd = fopen(filename,"w")) == NULL) { fprintf(stderr, "cannot open %s\n", filename); exit(1); } kcnt = 50000; dt = 0.0001; tend = 100.00; /* initial values */ t = 0.0; x[0] = 3.0; x[1] = 5.0; RungeKuttaFehlbergAdaptivefprint(fd, NumVars, x, t, dt); // print initial values RungeKuttaFehlbergAdaptive(fd, NumVars, x, differential, &t, &dt, tend, kcnt); fclose(fd); }