#include <stdio.h> #include <numeric.h> #define NVAR 1 #define POINTS 50 int main() { void func(double t, double y[], double dydt[], void *param); double t0=0, tf=2*M_PI, y0[NVAR]={0}; double t[POINTS], y[POINTS]; int i, points; /* return -1: divergent return >1: ok, num of points */ points = oderk(func, t0, tf, y0, NULL, t, y); printf("points = %d\n", points); if(points > 0) { printf("\n%8s %18s %15s\n","t","oderk()","sin(t)"); for (i=0; i<points; i++) printf("%10.4f %14.6f %14.6f\n", t[i],y[i],sin(t[i])); plotxy(t, y, "result of oderk", "t", "y"); } else printf("oderk() failed\n"); } void func(double t, double y[], double dydt[], void *param) { /* y' = cos(t) */ dydt[0] = cos(t); }
points = 35 t odesolve() sin(t) 0.0000 0.000000 0.000000 0.1647 0.163958 0.163958 0.2930 0.288791 0.288791 0.4373 0.423485 0.423485 0.5945 0.560114 0.560114 0.7633 0.691328 0.691328 0.9435 0.809628 0.809628 1.1361 0.907004 0.907004 1.3441 0.974410 0.974410 1.5755 0.999989 0.999989 1.8381 0.964487 0.964487 2.0552 0.884972 0.884972 2.2800 0.758904 0.758904 2.4850 0.610393 0.610393 2.6762 0.448786 0.448786 2.8559 0.281835 0.281835 3.0246 0.116702 0.116702 3.1814 -0.039813 -0.039813 3.3231 -0.180529 -0.180529 3.4539 -0.307275 -0.307275 3.6002 -0.442691 -0.442691 3.7591 -0.579004 -0.579004 3.9295 -0.708868 -0.708868 4.1113 -0.824733 -0.824733 4.3058 -0.918487 -0.918487 4.5164 -0.980855 -0.980855 4.7526 -0.999192 -0.999192 4.9945 -0.960467 -0.960467 5.2116 -0.877948 -0.877948 5.4347 -0.750252 -0.750252 5.6388 -0.600703 -0.600703 5.8292 -0.438549 -0.438549 6.0082 -0.271508 -0.271508 6.1763 -0.106713 -0.106713 6.2832 0.000000 -0.000000