#include <stdio.h> #include <float.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]; double tol; int i, points; tol = FLT_EPSILON; /* default tolerance is 1e-8 */ points = oderk(func, t0, tf, y0, NULL, t, y, tol); printf("points = %d\n", points); 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"); } void func(double t, double y[], double dydt[], void *param) { /* y' = cos(t) */ dydt[0] = cos(t); }
points = 22 t odesolve() sin(t) 0.0000 0.000000 0.000000 0.2319 0.229803 0.229803 0.4576 0.441772 0.441772 0.7181 0.657918 0.657918 1.0080 0.845762 0.845762 1.3295 0.971026 0.971026 1.6979 0.991935 0.991935 2.0250 0.898604 0.898604 2.3583 0.705591 0.705591 2.6974 0.429731 0.429730 3.0073 0.133918 0.133918 3.2598 -0.117907 -0.117907 3.5128 -0.362780 -0.362781 3.7617 -0.581135 -0.581135 4.0411 -0.783034 -0.783034 4.3504 -0.935198 -0.935198 4.6982 -0.999900 -0.999900 5.1342 -0.912350 -0.912350 5.4667 -0.728744 -0.728744 5.8095 -0.456146 -0.456146 6.1219 -0.160581 -0.160581 6.2832 0.000000 0.000000