#include #include #define NumVars 2 double fext(double t) { if (0.00 <= t && t <= 10.00) { return 1.00; } else { return 0.00; } } void differential(int n, double x[], double t, double value[]) { /* x[0]:x x[1]:v */ static double m = 0.1; static double b = 0.3; static double k = 0.2; value[0] = x[1]; value[1] = (-k*x[0] - b*x[1] + fext(t))/m; } main() { int kcnt; double t, dt; double x[NumVars]; char *filename = "voigt.dat"; FILE *fd; if ((fd = fopen(filename,"w")) == NULL) { fprintf(stderr, "cannot open %s\n", filename); exit(1); } kcnt = 20000; t = 0.0; dt = 0.001; /* initial values */ x[0] = 0.0; x[1] = 0.0; RungeKutta(fd, NumVars, x, differential, dt, kcnt); fclose(fd); }