52 double ave, i0, i1, i2, i3, idiv;
54 double d_ab, i_tot, d_ab2;
58 double a_stack[MAXSTACK];
59 double b_stack[MAXSTACK];
60 double i_stack[MAXSTACK];
68 for (s = 0; s < n; s++) {
69 b = b_stack[s] = (a_stack[s] = a) + d_ab;
72 i_stack[s] = gauss_quad(fn, z, ave, d_ab2);
88 z = (width = (ab - a) / 2) * _CGQ;
89 i1 = gauss_quad(fn, z, ave, width);
93 z = (width = (b - ab) / 2) * _CGQ;
94 i2 = gauss_quad(fn, z, ave, width);
101 if (fabs((i3 - i0) / idiv) > err) {
long gaussianQuadrature(double(*fn)(), double a, double b, long n, double err, double *result)
Integrate a function using recursive Gaussian quadrature.