#include #include #include #include "opt.h" #define Debug 0 #define Static static extern status IntervalReduction(dbl (*f)(), dbl a, dbl b, dbl *z, int timeout, dbl eps) { int k; dbl ya, yb, xp, xm, xc, yc; ya = (*f)(a); yb = (*f)(b); if (fabs(ya) <= eps) { *z = a; return success; } if (fabs(yb) <= eps) { *z = b; return success; } if (ya > 0.00 && yb < 0.00) { xp = a; xm = b; } else if (ya < 0.00 && yb > 0.00) { xm = a; xp = b; } else { fprintf(stderr, "interval [ %lf %lf ]\n", a, b); fprintf(stderr, "%lf and %lf have same sign\n", ya, yb); return failure; } for (k=0; k 0.00) { xp = xc; } else { xm = xc; } } fprintf(stderr, "IntervalReduction timeout\n"); return failure; }