48 template<
class Float,
class integr_fn>
static void rdqagie(integr_fn f,
void *ex,
49 Float *,
int *, Float * , Float *,
int *,
50 Float *, Float *,
int *,
51 int *, Float *, Float *, Float *, Float *,
54 template<
class Float,
class integr_fn>
static void rdqk15i(integr_fn f,
void *ex,
55 Float *,
int *, Float * , Float *,
56 Float *, Float *, Float *, Float *);
58 template<
class Float,
class integr_fn>
static void rdqagse(integr_fn f,
void *ex, Float *, Float *,
59 Float *, Float *,
int *, Float *, Float *,
60 int *,
int *, Float *, Float *, Float *,
61 Float *,
int *,
int *);
63 template<
class Float,
class integr_fn>
static void rdqk21(integr_fn f,
void *ex,
64 Float *, Float *, Float *, Float *, Float *, Float *);
66 template<
class Float>
static void rdqpsrt(
int *,
int *,
int *, Float *, Float *,
int *,
int *);
68 template<
class Float>
static void rdqelg(
int *, Float *, Float *, Float *, Float *,
int *);
70 template<
class Float,
class integr_fn>
71 void Rdqagi(integr_fn f,
void *ex, Float *bound,
int *inf,
72 Float *epsabs, Float *epsrel,
73 Float *result, Float *abserr,
int *neval,
int *ier,
74 int *limit,
int *lenw,
int *last,
75 int *iwork, Float *work)
241 if (*limit < 1 || *lenw < *limit << 2)
return;
247 rdqagie(f, ex, bound, inf, epsabs, epsrel, limit, result, abserr, neval, ier,
248 work, &work[l1], &work[l2], &work[l3], iwork, last);
253 template<
class Float,
class integr_fn>
static
254 void rdqagie(integr_fn f,
void *ex, Float *bound,
int *inf, Float *
255 epsabs, Float *epsrel,
int *limit, Float *result,
256 Float *abserr,
int *neval,
int *ier, Float *
alist,
257 Float *blist, Float *rlist, Float *elist,
int *
265 Float area1, area2, area12;
270 Float a1, a2, b1, b2, defab1, defab2, oflow;
274 int iroff1, iroff2, iroff3;
275 Float res3la[3], error1, error2;
279 Float defabs, epmach, erlarg, abseps, correc, errbnd, resabs;
283 Float erlast, errmax;
287 Float ertest, errsum;
499 epmach = DBL_EPSILON;
514 if (*epsabs <= 0. && (*epsrel <
fmax2(epmach * 50., 5e-29))) *ier = 6;
515 if (*ier == 6)
return;
531 static Float c_b6 = 0.;
532 static Float c_b7 = 1.;
534 rdqk15i(f, ex, &boun, inf, &c_b6, &c_b7, result, abserr, &defabs, &resabs);
542 dres =
fabs(*result);
543 errbnd =
fmax2(*epsabs, *epsrel * dres);
544 if (*abserr <= epmach * 100. * defabs && *abserr > errbnd) *ier = 2;
545 if (*limit == 1) *ier = 1;
546 if (*ier != 0 || (*abserr <= errbnd && *abserr != resabs)
547 || *abserr == 0.)
goto L130;
571 if (dres >= (1. - epmach * 50.) * defabs) {
578 for (*last = 2; *last <= *limit; ++(*last)) {
583 b1 = (alist[maxerr] + blist[maxerr]) * .5;
587 rdqk15i(f, ex, &boun, inf, &a1, &b1, &area1, &error1, &resabs, &defab1);
588 rdqk15i(f, ex, &boun, inf, &a2, &b2, &area2, &error2, &resabs, &defab2);
593 area12 = area1 + area2;
594 erro12 = error1 + error2;
595 errsum = errsum + erro12 - errmax;
596 area = area + area12 - rlist[maxerr];
597 if (!(defab1 == error1 || defab2 == error2)) {
598 if (
fabs(rlist[maxerr] - area12) <=
fabs(area12) * 1e-5 &&
599 erro12 >= errmax * .99) {
605 if (*last > 10 && erro12 > errmax)
609 rlist[maxerr] = area1;
610 rlist[*last] = area2;
611 errbnd =
fmax2(*epsabs, *epsrel *
fabs(area));
615 if (iroff1 + iroff2 >= 10 || iroff3 >= 20)
630 (epmach * 100. + 1.) * (
fabs(a2) + uflow * 1e3))
637 if (error2 <= error1) {
641 elist[maxerr] = error1;
642 elist[*last] = error2;
648 rlist[maxerr] = area2;
649 rlist[*last] = area1;
650 elist[maxerr] = error2;
651 elist[*last] = error1;
658 rdqpsrt(limit, last, &maxerr, &errmax, &elist[1], &iord[1], &nrmax);
659 if (errsum <= errbnd) {
662 if (*ier != 0)
break;
667 rlist2[1] = area;
continue;
672 if (
fabs(b1 - a1) > small) {
680 if (
fabs(blist[maxerr] - alist[maxerr]) > small) {
687 if (ierro != 3 && erlarg > ertest) {
695 if (*last > *limit / 2 + 2) {
696 jupbnd = *limit + 3 - *last;
698 for (k =
id; k <= jupbnd; ++k) {
699 maxerr = iord[nrmax];
700 errmax = elist[maxerr];
701 if (
fabs(blist[maxerr] - alist[maxerr]) > small) {
710 rlist2[numrl2 - 1] = area;
711 rdqelg(&numrl2, rlist2, &reseps, &abseps, res3la, &nres);
713 if (ktmin > 5 && *abserr < errsum * .001) {
716 if (abseps >= *abserr) {
723 ertest =
fmax2(*epsabs, *epsrel *
fabs(reseps));
724 if (*abserr <= ertest) {
738 errmax = elist[maxerr];
750 if (*abserr == oflow) {
753 if (*ier + ierro == 0) {
762 if (*result == 0. || area == 0.) {
763 if (*abserr > errsum)
770 if (*abserr /
fabs(*result) > errsum /
fabs(area)) {
777 if (ksgn == -1 &&
fmax2(
fabs(*result),
fabs(area)) <= defabs * .01) {
780 if (.01 > *result / area || *result / area > 100. || errsum >
fabs(area)) {
789 for (k = 1; k <= *last; ++k)
794 *neval = *last * 30 - 15;
804 template<
class Float,
class integr_fn>
805 void Rdqags(integr_fn f,
void *ex, Float *a, Float *b,
806 Float *epsabs, Float *epsrel,
807 Float *result, Float *abserr,
int *neval,
int *ier,
808 int *limit,
int *lenw,
int *last,
int *iwork, Float *work)
971 if (*limit < 1 || *lenw < *limit *4)
return;
979 rdqagse(f, ex, a, b, epsabs, epsrel, limit, result, abserr, neval, ier,
980 work, &work[l1], &work[l2], &work[l3], iwork, last);
985 template<
class Float,
class integr_fn>
static
986 void rdqagse(integr_fn f,
void *ex, Float *a, Float *b, Float *
987 epsabs, Float *epsrel,
int *limit, Float *result,
988 Float *abserr,
int *neval,
int *ier, Float *
alist,
989 Float *blist, Float *rlist, Float *elist,
int *
997 int iroff1, iroff2, iroff3;
1004 Float abseps, area, area1, area2, area12, dres, epmach;
1005 Float a1, a2, b1, b2, defabs, defab1, defab2, oflow, uflow, resabs, reseps;
1006 Float error1, error2, erro12, errbnd, erlast, errmax, errsum;
1008 Float correc = 0.0, erlarg = 0.0, ertest = 0.0, small = 0.0;
1220 epmach = DBL_EPSILON;
1233 if (*epsabs <= 0. && *epsrel <
fmax2(epmach * 50., 5e-29)) {
1244 rdqk21(f, ex, a, b, result, abserr, &defabs, &resabs);
1248 dres =
fabs(*result);
1249 errbnd =
fmax2(*epsabs, *epsrel * dres);
1254 if (*abserr <= epmach * 100. * defabs && *abserr > errbnd)
1258 if (*ier != 0 || (*abserr <= errbnd && *abserr != resabs)
1259 || *abserr == 0.)
goto L140;
1264 rlist2[0] = *result;
1280 if (dres >= (1. - epmach * 50.) * defabs) {
1287 for (*last = 2; *last <= *limit; ++(*last)) {
1292 b1 = (alist[maxerr] + blist[maxerr]) * .5;
1296 rdqk21(f, ex, &a1, &b1, &area1, &error1, &resabs, &defab1);
1297 rdqk21(f, ex, &a2, &b2, &area2, &error2, &resabs, &defab2);
1302 area12 = area1 + area2;
1303 erro12 = error1 + error2;
1304 errsum = errsum + erro12 - errmax;
1305 area = area + area12 - rlist[maxerr];
1306 if (!(defab1 == error1 || defab2 == error2)) {
1308 if (
fabs(rlist[maxerr] - area12) <=
fabs(area12) * 1e-5 &&
1309 erro12 >= errmax * .99) {
1315 if (*last > 10 && erro12 > errmax)
1318 rlist[maxerr] = area1;
1319 rlist[*last] = area2;
1320 errbnd =
fmax2(*epsabs, *epsrel *
fabs(area));
1324 if (iroff1 + iroff2 >= 10 || iroff3 >= 20)
1330 if (*last == *limit)
1337 (epmach * 100. + 1.) * (
fabs(a2) + uflow * 1e3)) {
1343 if (error2 > error1) {
1347 rlist[maxerr] = area2;
1348 rlist[*last] = area1;
1349 elist[maxerr] = error2;
1350 elist[*last] = error1;
1355 elist[maxerr] = error1;
1356 elist[*last] = error2;
1364 rdqpsrt(limit, last, &maxerr, &errmax, &elist[1], &iord[1], &nrmax);
1366 if (errsum <= errbnd)
goto L115;
1367 if (*ier != 0)
break;
1369 small =
fabs(*b - *a) * .375;
1372 rlist2[1] = area;
continue;
1374 if (noext)
continue;
1377 if (
fabs(b1 - a1) > small) {
1385 if (
fabs(blist[maxerr] - alist[maxerr]) > small) {
1392 if (ierro != 3 && erlarg > ertest) {
1400 if (*last > *limit / 2 + 2) {
1401 jupbnd = *limit + 3 - *last;
1403 for (k =
id; k <= jupbnd; ++k) {
1404 maxerr = iord[nrmax];
1405 errmax = elist[maxerr];
1406 if (
fabs(blist[maxerr] - alist[maxerr]) > small) {
1416 rlist2[numrl2 - 1] = area;
1417 rdqelg(&numrl2, rlist2, &reseps, &abseps, res3la, &nres);
1419 if (ktmin > 5 && *abserr < errsum * .001) {
1422 if (abseps < *abserr) {
1427 ertest =
fmax2(*epsabs, *epsrel *
fabs(reseps));
1428 if (*abserr <= ertest) {
1442 errmax = elist[maxerr];
1455 if (*abserr == oflow)
goto L115;
1456 if (*ier + ierro == 0)
goto L110;
1461 if (*result == 0. || area == 0.) {
1462 if (*abserr > errsum)
goto L115;
1463 if (area == 0.)
goto L130;
1466 if (*abserr /
fabs(*result) > errsum /
fabs(area))
1471 if (ksgn == -1 &&
fmax2(
fabs(*result),
fabs(area)) <= defabs * .01) {
1474 if (.01 > *result / area || *result / area > 100. || errsum >
fabs(area)) {
1481 for (k = 1; k <= *last; ++k)
1482 *result += rlist[k];
1487 *neval = *last * 42 - 21;
1492 template<
class Float,
class integr_fn>
static void rdqk15i(integr_fn f,
void *ex,
1493 Float *boun,
int *inf, Float *a, Float *b,
1495 Float *abserr, Float *resabs, Float *resasc)
1499 static double wg[8] = {
1500 0., .129484966168869693270611432679082,
1501 0., .27970539148927666790146777142378,
1502 0., .381830050505118944950369775488975,
1503 0., .417959183673469387755102040816327 };
1504 static double xgk[8] = {
1505 .991455371120812639206854697526329,
1506 .949107912342758524526189684047851,
1507 .864864423359769072789712788640926,
1508 .741531185599394439863864773280788,
1509 .58608723546769113029414483825873,
1510 .405845151377397166906606412076961,
1511 .207784955007898467600689403773245, 0. };
1512 static double wgk[8] = {
1513 .02293532201052922496373200805897,
1514 .063092092629978553290700663189204,
1515 .104790010322250183839876322541518,
1516 .140653259715525918745189590510238,
1517 .16900472663926790282658342659855,
1518 .190350578064785409913256402421014,
1519 .204432940075298892414161999234649,
1520 .209482141084727828012999174891714 };
1523 Float absc, dinf, resg, resk, fsum, absc1, absc2, fval1, fval2;
1525 Float hlgth, centr, reskh, uflow;
1526 Float tabsc1, tabsc2, fc, epmach;
1527 Float fv1[7], fv2[7], vec[15], vec2[15];
1641 epmach = DBL_EPSILON;
1643 dinf = (double)
imin2(1, *inf);
1645 centr = (*a + *b) * .5;
1646 hlgth = (*b - *a) * .5;
1647 tabsc1 = *boun + dinf * (1. - centr) / centr;
1652 for (j = 1; j <= 7; ++j) {
1653 absc = hlgth * xgk[j - 1];
1654 absc1 = centr - absc;
1655 absc2 = centr + absc;
1656 tabsc1 = *boun + dinf * (1. - absc1) / absc1;
1657 tabsc2 = *boun + dinf * (1. - absc2) / absc2;
1658 vec[(j << 1) - 1] = tabsc1;
1659 vec[j * 2] = tabsc2;
1661 vec2[(j << 1) - 1] = -tabsc1;
1662 vec2[j * 2] = -tabsc2;
1667 if (*inf == 2) f(vec2, 15, ex);
1669 if (*inf == 2) fval1 += vec2[0];
1670 fc = fval1 / centr / centr;
1677 *resabs =
fabs(resk);
1678 for (j = 1; j <= 7; ++j) {
1679 absc = hlgth * xgk[j - 1];
1680 absc1 = centr - absc;
1681 absc2 = centr + absc;
1682 tabsc1 = *boun + dinf * (1. - absc1) / absc1;
1683 tabsc2 = *boun + dinf * (1. - absc2) / absc2;
1684 fval1 = vec[(j << 1) - 1];
1687 fval1 += vec2[(j << 1) - 1];
1690 fval2 += vec2[j * 2];
1692 fval1 = fval1 / absc1 / absc1;
1693 fval2 = fval2 / absc2 / absc2;
1696 fsum = fval1 + fval2;
1697 resg += wg[j - 1] * fsum;
1698 resk += wgk[j - 1] * fsum;
1699 *resabs += wgk[j - 1] * (
fabs(fval1) +
fabs(fval2));
1703 *resasc = wgk[7] *
fabs(fc - reskh);
1704 for (j = 1; j <= 7; ++j) {
1705 *resasc += wgk[j - 1] * (
fabs(fv1[j - 1] - reskh) +
1706 fabs(fv2[j - 1] - reskh));
1709 *result = resk * hlgth;
1712 *abserr =
fabs((resk - resg) * hlgth);
1713 if (*resasc != 0. && *abserr != 0.) {
1714 *abserr = *resasc *
fmin2(1.,
pow(*abserr * 200. / *resasc, 1.5));
1716 if (*resabs > uflow / (epmach * 50.)) {
1717 *abserr =
fmax2(epmach * 50. * *resabs, *abserr);
1722 template<
class Float>
static void rdqelg(
int *n, Float *epstab, Float *
1723 result, Float *abserr, Float *res3la,
int *nres)
1726 int i__, indx, ib, ib2, ie, k1, k2, k3, num, newelm, limexp;
1727 Float delta1, delta2, delta3, e0, e1, e1abs, e2, e3, epmach, epsinf;
1728 Float oflow, ss, res;
1729 Float errA, err1, err2, err3, tol1, tol2, tol3;
1809 epmach = DBL_EPSILON;
1813 *result = epstab[*n];
1818 epstab[*n + 2] = epstab[*n];
1819 newelm = (*n - 1) / 2;
1823 for (i__ = 1; i__ <= newelm; ++i__) {
1826 res = epstab[k1 + 2];
1832 err2 =
fabs(delta2);
1835 err3 =
fabs(delta3);
1837 if (err2 <= tol2 && err3 <= tol3) {
1841 *abserr = err2 + err3;
1849 err1 =
fabs(delta1);
1855 if (err1 > tol1 && err2 > tol2 && err3 > tol3) {
1856 ss = 1. / delta1 + 1. / delta2 - 1. / delta3;
1857 epsinf =
fabs(ss * e1);
1862 if (epsinf > 1e-4) {
1876 errA = err2 +
fabs(res - e2) + err3;
1877 if (errA <= *abserr) {
1887 *n = (limexp / 2 << 1) - 1;
1890 if (num / 2 << 1 == num) ib = 2;
else ib = 1;
1892 for (i__ = 1; i__ <= ie; ++i__) {
1894 epstab[ib] = epstab[ib2];
1898 indx = num - *n + 1;
1899 for (i__ = 1; i__ <= *n; ++i__) {
1900 epstab[i__] = epstab[indx];
1907 *abserr =
fabs(*result - res3la[3]) +
1908 fabs(*result - res3la[2]) +
1909 fabs(*result - res3la[1]);
1910 res3la[1] = res3la[2];
1911 res3la[2] = res3la[3];
1912 res3la[3] = *result;
1914 res3la[*nres] = *result;
1919 *abserr =
fmax2(*abserr, epmach * 5. *
fabs(*result));
1923 template<
class Float,
class integr_fn>
static void rdqk21(integr_fn f,
void *ex, Float *a, Float *b, Float *result,
1924 Float *abserr, Float *resabs, Float *resasc)
1928 static double wg[5] = { .066671344308688137593568809893332,
1929 .149451349150580593145776339657697,
1930 .219086362515982043995534934228163,
1931 .269266719309996355091226921569469,
1932 .295524224714752870173892994651338 };
1933 static double xgk[11] = { .995657163025808080735527280689003,
1934 .973906528517171720077964012084452,
1935 .930157491355708226001207180059508,
1936 .865063366688984510732096688423493,
1937 .780817726586416897063717578345042,
1938 .679409568299024406234327365114874,
1939 .562757134668604683339000099272694,
1940 .433395394129247190799265943165784,
1941 .294392862701460198131126603103866,
1942 .14887433898163121088482600112972,0. };
1943 static double wgk[11] = { .011694638867371874278064396062192,
1944 .03255816230796472747881897245939,
1945 .05475589657435199603138130024458,
1946 .07503967481091995276704314091619,
1947 .093125454583697605535065465083366,
1948 .109387158802297641899210590325805,
1949 .123491976262065851077958109831074,
1950 .134709217311473325928054001771707,
1951 .142775938577060080797094273138717,
1952 .147739104901338491374841515972068,
1953 .149445554002916905664936468389821 };
1957 Float fv1[10], fv2[10], vec[21];
1958 Float absc, resg, resk, fsum, fval1, fval2;
1959 Float hlgth, centr, reskh, uflow;
1960 Float fc, epmach, dhlgth;
2058 epmach = DBL_EPSILON;
2061 centr = (*a + *b) * .5;
2062 hlgth = (*b - *a) * .5;
2063 dhlgth =
fabs(hlgth);
2070 for (j = 1; j <= 5; ++j) {
2072 absc = hlgth * xgk[jtw - 1];
2073 vec[(j << 1) - 1] = centr - absc;
2075 vec[j * 2] = centr + absc;
2077 for (j = 1; j <= 5; ++j) {
2078 jtwm1 = (j << 1) - 1;
2079 absc = hlgth * xgk[jtwm1 - 1];
2080 vec[(j << 1) + 9] = centr - absc;
2081 vec[(j << 1) + 10] = centr + absc;
2085 resk = wgk[10] * fc;
2086 *resabs =
fabs(resk);
2087 for (j = 1; j <= 5; ++j) {
2089 absc = hlgth * xgk[jtw - 1];
2090 fval1 = vec[(j << 1) - 1];
2092 fv1[jtw - 1] = fval1;
2093 fv2[jtw - 1] = fval2;
2094 fsum = fval1 + fval2;
2095 resg += wg[j - 1] * fsum;
2096 resk += wgk[jtw - 1] * fsum;
2097 *resabs += wgk[jtw - 1] * (
fabs(fval1) +
fabs(fval2));
2100 for (j = 1; j <= 5; ++j) {
2101 jtwm1 = (j << 1) - 1;
2102 absc = hlgth * xgk[jtwm1 - 1];
2103 fval1 = vec[(j << 1) + 9];
2104 fval2 = vec[(j << 1) + 10];
2105 fv1[jtwm1 - 1] = fval1;
2106 fv2[jtwm1 - 1] = fval2;
2107 fsum = fval1 + fval2;
2108 resk += wgk[jtwm1 - 1] * fsum;
2109 *resabs += wgk[jtwm1 - 1] * (
fabs(fval1) +
fabs(fval2));
2113 *resasc = wgk[10] *
fabs(fc - reskh);
2114 for (j = 1; j <= 10; ++j) {
2115 *resasc += wgk[j - 1] * (
fabs(fv1[j - 1] - reskh) +
2116 fabs(fv2[j - 1] - reskh));
2119 *result = resk * hlgth;
2122 *abserr =
fabs((resk - resg) * hlgth);
2123 if (*resasc != 0. && *abserr != 0.) {
2124 *abserr = *resasc *
fmin2(1.,
pow(*abserr * 200. / *resasc, 1.5));
2126 if (*resabs > uflow / (epmach * 50.)) {
2127 *abserr =
fmax2(epmach * 50. * *resabs, *abserr);
2132 template<
class Float>
static void rdqpsrt(
int *limit,
int *last,
int *maxerr,
2133 Float *ermax, Float *elist,
int *iord,
int *nrmax)
2136 int i, j, k, ido, jbnd, isucc, jupbn;
2137 Float errmin, errmax;
2212 errmax = elist[*maxerr];
2215 for (i = 1; i <= ido; ++i) {
2216 isucc = iord[*nrmax - 1];
2217 if (errmax <= elist[isucc])
2219 iord[*nrmax] = isucc;
2228 if (*last > *limit / 2 + 2)
2229 jupbn = *limit + 3 - *last;
2233 errmin = elist[*last];
2239 for (i = *nrmax + 1; i <= jbnd; ++i) {
2241 if (errmax >= elist[isucc]) {
2243 iord[i - 1] = *maxerr;
2244 for (j = i, k = jbnd; j <= jbnd; j++, k--) {
2246 if (errmin < elist[isucc]) {
2248 iord[k + 1] = *last;
2251 iord[k + 1] = isucc;
2256 iord[i - 1] = isucc;
2259 iord[jbnd] = *maxerr;
2260 iord[jupbn] = *last;
2264 *maxerr = iord[*nrmax];
2265 *ermax = elist[*maxerr];
static void rdqpsrt(int *, int *, int *, Float *, Float *, int *, int *)
df1_two_variable fabs(const df1_two_variable &x)
static void rdqk15i(integr_fn f, void *ex, Float *, int *, Float *, Float *, Float *, Float *, Float *, Float *)
double fmax2(double a, const dvariable &v)
void Rdqagi(integr_fn f, void *ex, Float *bound, int *inf, Float *epsabs, Float *epsrel, Float *result, Float *abserr, int *neval, int *ier, int *limit, int *lenw, int *last, int *iwork, Float *work)
static void rdqagse(integr_fn f, void *ex, Float *, Float *, Float *, Float *, int *, Float *, Float *, int *, int *, Float *, Float *, Float *, Float *, int *, int *)
void Rdqags(integr_fn f, void *ex, Float *a, Float *b, Float *epsabs, Float *epsrel, Float *result, Float *abserr, int *neval, int *ier, int *limit, int *lenw, int *last, int *iwork, Float *work)
static void rdqelg(int *, Float *, Float *, Float *, Float *, int *)
static void rdqagie(integr_fn f, void *ex, Float *, int *, Float *, Float *, int *, Float *, Float *, int *, int *, Float *, Float *, Float *, Float *, int *, int *)
static void rdqk21(integr_fn f, void *ex, Float *, Float *, Float *, Float *, Float *, Float *)
d3_array pow(const d3_array &m, int e)
Description not yet available.