38 double T, R, BB, S, H, S1, S0, err, result;
40 static double *RM = NULL;
41 long K, K1, N, N0, N1, KK, KKK, K0, J, L, K2;
43 T = (b - a) * (func(a) + func(b)) * .5;
44 if (RM == NULL || maxe > MAXE) {
47 RM = malloc(
sizeof(*RM) * (maxe + 2));
50 RM[1] = (b - a) * func((a + b) * 0.5);
54 for (K = 1; K <= maxe; K++) {
55 BB = (R * 0.5 - 1.0) / (R - 1.0);
57 T = RM[1] + BB * (T - RM[1]);
61 H = (b - a) / (N * 1.0);
65 }
else if (N <= 512) {
72 for (K2 = 1; K2 <= N; K2 += 512) {
75 for (K1 = K2; K1 <= KK; K1 += 32) {
78 for (K0 = K1; K0 <= KKK; K0 += 2)
79 S0 += func(a + K0 * H);
84 RM[K + 1] = 2.0 * H * S;
87 for (J = 1; J <= K; J++) {
89 RM[L] = RM[L + 1] + (RM[L + 1] - RM[L]) / (R - 1.0);
92 err = fabs(T - RM[1]) * 0.5;
95 result = (T + RM[1]) * 0.5;
100 fprintf(stderr,
"too many qrom steps\n");
double qromb(double(*func)(), long maxe, double a, double b, double eps)
Computes the definite integral of a function using Romberg's method.