/* * A open interval Romberg integrator * Originally written for the cosmo module in PKDGRAV by Tom Quinn */ #include #include #include #include #include #include "romberg.h" #define MAXLEV 13 /* ** Romberg integrator for an open interval. */ double dRombergO(const void *CTX,double (*func)(const void *, double),double a,double b, double eps) { double tllnew; double tll; double tlk[MAXLEV+1]; int n = 1; int nsamples = 1; tlk[0] = tllnew = (b-a)*(*func)(CTX, 0.5*(b+a)); if(a == b) return tllnew; tll = DBL_MAX; while((n == 1) || ((fabs((tllnew-tll)/tllnew) > eps) && (n < MAXLEV))) { /* * midpoint rule. */ double deltax; double tlktmp; int i; nsamples *= 3; deltax = (b-a)/nsamples; tlktmp = tlk[0]; tlk[0] = tlk[0]/3.0; for(i=0;i eps) && (n < MAXLEV))) { /* * midpoint rule. */ double deltax; double tlktmp; int i; nsamples *= 2; deltax = (b-a)/nsamples; tlktmp = tlk[0]; tlk[0] = tlk[0]/2.0; for(i=0;i