#include #include #include #include "rk.h" /* solve \ddot{x} - 2 (1 - x^2) \dot{x} + x = 0 canonical form \dot{x} = v \dot{v} = 2 (1 - x^2) v - x */ static void van_del_Pol(double t, int n, double q[], double dotq[]) { double x, v; x = q[0]; v = q[1]; dotq[0] = v; dotq[1] = 2 * (1 - x*x)*v - x; } #define NumVars 2 main() { double dt = 0.001; const int cnt = 10000; const double tend = 10.00; double t, q[NumVars]; char *filename = "van_der_Pol_rkf.dat"; FILE *fd; if ((fd = fopen(filename,"w")) == NULL) { fprintf(stderr, "cannot open %s\n", filename); exit(1); } /* initial values */ t = 0.00; q[0] = 2.00; q[1] = 0.00; RKFadaptivefprint(fd, t, dt, NumVars, q); // print initial values RKFadaptive(fd, &t, &dt, tend, cnt, NumVars, q, van_del_Pol); fclose(fd); }