1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
|
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.54+ (gsl)
from ../gsl-ref.texi -->
<TITLE>GNU Scientific Library -- Reference Manual - Numerical Integration</TITLE>
<!-- <LINK rel="stylesheet" title="Default Style Sheet" href="/css/texinfo.css" type="text/css"> -->
<link href="gsl-ref_17.html" rel=Next>
<link href="gsl-ref_15.html" rel=Previous>
<link href="gsl-ref_toc.html" rel=ToC>
</HEAD>
<BODY>
<p>Go to the <A HREF="gsl-ref_1.html">first</A>, <A HREF="gsl-ref_15.html">previous</A>, <A HREF="gsl-ref_17.html">next</A>, <A HREF="gsl-ref_50.html">last</A> section, <A HREF="gsl-ref_toc.html">table of contents</A>.
<P><HR><P>
<H1><A NAME="SEC248" HREF="gsl-ref_toc.html#TOC248">Numerical Integration</A></H1>
<P>
<A NAME="IDX1332"></A>
<A NAME="IDX1333"></A>
<A NAME="IDX1334"></A>
<A NAME="IDX1335"></A>
</P>
<P>
This chapter describes routines for performing numerical integration
(quadrature) of a function in one dimension. There are routines for
adaptive and non-adaptive integration of general functions, with
specialised routines for specific cases. These include integration over
infinite and semi-infinite ranges, singular integrals, including
logarithmic singularities, computation of Cauchy principal values and
oscillatory integrals. The library reimplements the algorithms used in
QUADPACK, a numerical integration package written by Piessens,
Doncker-Kapenga, Uberhuber and Kahaner. Fortran code for QUADPACK is
available on Netlib.
</P>
<P>
The functions described in this chapter are declared in the header file
<TT>'gsl_integration.h'</TT>.
</P>
<H2><A NAME="SEC249" HREF="gsl-ref_toc.html#TOC249">Introduction</A></H2>
<P>
Each algorithm computes an approximation to a definite integral of the
form,
</P>
<PRE class="example">
I = \int_a^b f(x) w(x) dx
</PRE>
<P>
where w(x) is a weight function (for general integrands w(x)=1).
The user provides absolute and relative error bounds
(epsabs, epsrel) which specify the following accuracy requirement,
</P>
<PRE class="example">
|RESULT - I| <= max(epsabs, epsrel |I|)
</PRE>
<P>
where
RESULT is the numerical approximation obtained by the
algorithm. The algorithms attempt to estimate the absolute error
ABSERR = |RESULT - I| in such a way that the following inequality
holds,
</P>
<PRE class="example">
|RESULT - I| <= ABSERR <= max(epsabs, epsrel |I|)
</PRE>
<P>
The routines will fail to converge if the error bounds are too
stringent, but always return the best approximation obtained up to that
stage.
</P>
<P>
The algorithms in QUADPACK use a naming convention based on the
following letters,
</P>
<PRE class="display">
<CODE>Q</CODE> - quadrature routine
<CODE>N</CODE> - non-adaptive integrator
<CODE>A</CODE> - adaptive integrator
<CODE>G</CODE> - general integrand (user-defined)
<CODE>W</CODE> - weight function with integrand
<CODE>S</CODE> - singularities can be more readily integrated
<CODE>P</CODE> - points of special difficulty can be supplied
<CODE>I</CODE> - infinite range of integration
<CODE>O</CODE> - oscillatory weight function, cos or sin
<CODE>F</CODE> - Fourier integral
<CODE>C</CODE> - Cauchy principal value
</PRE>
<P>
The algorithms are built on pairs of quadrature rules, a higher order
rule and a lower order rule. The higher order rule is used to compute
the best approximation to an integral over a small range. The
difference between the results of the higher order rule and the lower
order rule gives an estimate of the error in the approximation.
</P>
<P>
<A NAME="IDX1336"></A>
The algorithms for general functions (without a weight function) are
based on Gauss-Kronrod rules. A Gauss-Kronrod rule begins with a
classical Gaussian quadrature rule of order m. This is extended
with additional points between each of the abscissae to give a higher
order Kronrod rule of order 2m+1. The Kronrod rule is efficient
because it reuses existing function evaluations from the Gaussian rule.
The higher order Kronrod rule is used as the best approximation to the
integral, and the difference between the two rules is used as an
estimate of the error in the approximation.
</P>
<P>
<A NAME="IDX1337"></A>
<A NAME="IDX1338"></A>
For integrands with weight functions the algorithms use Clenshaw-Curtis
quadrature rules. A Clenshaw-Curtis rule begins with an n-th
order Chebyshev polynomial approximation to the integrand. This
polynomial can be integrated exactly to give an approximation to the
integral of the original function. The Chebyshev expansion can be
extended to higher orders to improve the approximation. The presence of
singularities (or other behavior) in the integrand can cause slow
convergence in the Chebyshev approximation. The modified
Clenshaw-Curtis rules used in QUADPACK separate out several common
weight functions which cause slow convergence. These weight functions
are integrated analytically against the Chebyshev polynomials to
precompute <I>modified Chebyshev moments</I>. Combining the moments with
the Chebyshev approximation to the function gives the desired
integral. The use of analytic integration for the singular part of the
function allows exact cancellations and substantially improves the
overall convergence behavior of the integration.
</P>
<H2><A NAME="SEC250" HREF="gsl-ref_toc.html#TOC250">QNG non-adaptive Gauss-Kronrod integration</A></H2>
<P>
The QNG algorithm is a non-adaptive procedure which uses fixed
Gauss-Kronrod abscissae to sample the integrand at a maximum of 87
points. It is provided for fast integration of smooth functions.
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qng</B> <I>(const gsl_function *<VAR>f</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, double * <VAR>result</VAR>, double * <VAR>abserr</VAR>, size_t * <VAR>neval</VAR>)</I>
<DD><A NAME="IDX1339"></A>
</P>
<P>
This function applies the Gauss-Kronrod 10-point, 21-point, 43-point and
87-point integration rules in succession until an estimate of the
integral of f over (a,b) is achieved within the desired
absolute and relative error limits, <VAR>epsabs</VAR> and <VAR>epsrel</VAR>. The
function returns the final approximation, <VAR>result</VAR>, an estimate of
the absolute error, <VAR>abserr</VAR> and the number of function evaluations
used, <VAR>neval</VAR>. The Gauss-Kronrod rules are designed in such a way
that each rule uses all the results of its predecessors, in order to
minimize the total number of function evaluations.
</DL>
</P>
<H2><A NAME="SEC251" HREF="gsl-ref_toc.html#TOC251">QAG adaptive integration</A></H2>
<P>
The QAG algorithm is a simple adaptive integration procedure. The
integration region is divided into subintervals, and on each iteration
the subinterval with the largest estimated error is bisected. This
reduces the overall error rapidly, as the subintervals become
concentrated around local difficulties in the integrand. These
subintervals are managed by a <CODE>gsl_integration_workspace</CODE> struct,
which handles the memory for the subinterval ranges, results and error
estimates.
</P>
<P>
<DL>
<DT><U>Function:</U> gsl_integration_workspace * <B>gsl_integration_workspace_alloc</B> <I>(size_t <VAR>n</VAR>)</I>
<DD><A NAME="IDX1340"></A>
This function allocates a workspace sufficient to hold <VAR>n</VAR> double
precision intervals, their integration results and error estimates.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> void <B>gsl_integration_workspace_free</B> <I>(gsl_integration_workspace * <VAR>w</VAR>)</I>
<DD><A NAME="IDX1341"></A>
This function frees the memory associated with the workspace <VAR>w</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qag</B> <I>(const gsl_function *<VAR>f</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, int <VAR>key</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double * <VAR>result</VAR>, double * <VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1342"></A>
</P>
<P>
This function applies an integration rule adaptively until an estimate
of the integral of f over (a,b) is achieved within the
desired absolute and relative error limits, <VAR>epsabs</VAR> and
<VAR>epsrel</VAR>. The function returns the final approximation,
<VAR>result</VAR>, and an estimate of the absolute error, <VAR>abserr</VAR>. The
integration rule is determined by the value of <VAR>key</VAR>, which should
be chosen from the following symbolic names,
</P>
<PRE class="example">
GSL_INTEG_GAUSS15 (key = 1)
GSL_INTEG_GAUSS21 (key = 2)
GSL_INTEG_GAUSS31 (key = 3)
GSL_INTEG_GAUSS41 (key = 4)
GSL_INTEG_GAUSS51 (key = 5)
GSL_INTEG_GAUSS61 (key = 6)
</PRE>
<P>
corresponding to the 15, 21, 31, 41, 51 and 61 point Gauss-Kronrod
rules. The higher-order rules give better accuracy for smooth functions,
while lower-order rules save time when the function contains local
difficulties, such as discontinuities.
</P>
<P>
On each iteration the adaptive integration strategy bisects the interval
with the largest error estimate. The subintervals and their results are
stored in the memory provided by <VAR>workspace</VAR>. The maximum number of
subintervals is given by <VAR>limit</VAR>, which may not exceed the allocated
size of the workspace.
</DL>
</P>
<H2><A NAME="SEC252" HREF="gsl-ref_toc.html#TOC252">QAGS adaptive integration with singularities</A></H2>
<P>
The presence of an integrable singularity in the integration region
causes an adaptive routine to concentrate new subintervals around the
singularity. As the subintervals decrease in size the successive
approximations to the integral converge in a limiting fashion. This
approach to the limit can be accelerated using an extrapolation
procedure. The QAGS algorithm combines adaptive bisection with the Wynn
epsilon-algorithm to speed up the integration of many types of
integrable singularities.
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qags</B> <I>(const gsl_function * <VAR>f</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1343"></A>
</P>
<P>
This function applies the Gauss-Kronrod 21-point integration rule
adaptively until an estimate of the integral of f over
(a,b) is achieved within the desired absolute and relative error
limits, <VAR>epsabs</VAR> and <VAR>epsrel</VAR>. The results are extrapolated
using the epsilon-algorithm, which accelerates the convergence of the
integral in the presence of discontinuities and integrable
singularities. The function returns the final approximation from the
extrapolation, <VAR>result</VAR>, and an estimate of the absolute error,
<VAR>abserr</VAR>. The subintervals and their results are stored in the
memory provided by <VAR>workspace</VAR>. The maximum number of subintervals
is given by <VAR>limit</VAR>, which may not exceed the allocated size of the
workspace.
</P>
</DL>
<H2><A NAME="SEC253" HREF="gsl-ref_toc.html#TOC253">QAGP adaptive integration with known singular points</A></H2>
<P>
<A NAME="IDX1344"></A>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qagp</B> <I>(const gsl_function * <VAR>f</VAR>, double *<VAR>pts</VAR>, size_t <VAR>npts</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1345"></A>
</P>
<P>
This function applies the adaptive integration algorithm QAGS taking
account of the user-supplied locations of singular points. The array
<VAR>pts</VAR> of length <VAR>npts</VAR> should contain the endpoints of the
integration ranges defined by the integration region and locations of
the singularities. For example, to integrate over the region
(a,b) with break-points at x_1, x_2, x_3 (where
a < x_1 < x_2 < x_3 < b) the following <VAR>pts</VAR> array should be used
</P>
<PRE class="example">
pts[0] = a
pts[1] = x_1
pts[2] = x_2
pts[3] = x_3
pts[4] = b
</PRE>
<P>
with <VAR>npts</VAR> = 5.
</P>
<P>
If you know the locations of the singular points in the integration
region then this routine will be faster than <CODE>QAGS</CODE>.
</P>
</DL>
<H2><A NAME="SEC254" HREF="gsl-ref_toc.html#TOC254">QAGI adaptive integration on infinite intervals</A></H2>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qagi</B> <I>(gsl_function * <VAR>f</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1346"></A>
</P>
<P>
This function computes the integral of the function <VAR>f</VAR> over the
infinite interval (-\infty,+\infty). The integral is mapped onto the
interval (0,1] using the transformation x = (1-t)/t,
</P>
<PRE class="example">
\int_{-\infty}^{+\infty} dx f(x) =
\int_0^1 dt (f((1-t)/t) + f((-1+t)/t))/t^2.
</PRE>
<P>
It is then integrated using the QAGS algorithm. The normal 21-point
Gauss-Kronrod rule of QAGS is replaced by a 15-point rule, because the
transformation can generate an integrable singularity at the origin. In
this case a lower-order rule is more efficient.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qagiu</B> <I>(gsl_function * <VAR>f</VAR>, double <VAR>a</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1347"></A>
</P>
<P>
This function computes the integral of the function <VAR>f</VAR> over the
semi-infinite interval (a,+\infty). The integral is mapped onto the
interval (0,1] using the transformation x = a + (1-t)/t,
</P>
<PRE class="example">
\int_{a}^{+\infty} dx f(x) =
\int_0^1 dt f(a + (1-t)/t)/t^2
</PRE>
<P>
and then integrated using the QAGS algorithm.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qagil</B> <I>(gsl_function * <VAR>f</VAR>, double <VAR>b</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1348"></A>
This function computes the integral of the function <VAR>f</VAR> over the
semi-infinite interval (-\infty,b). The integral is mapped onto the
region (0,1] using the transformation x = b - (1-t)/t,
</P>
<PRE class="example">
\int_{+\infty}^{b} dx f(x) =
\int_0^1 dt f(b - (1-t)/t)/t^2
</PRE>
<P>
and then integrated using the QAGS algorithm.
</DL>
</P>
<H2><A NAME="SEC255" HREF="gsl-ref_toc.html#TOC255">QAWC adaptive integration for Cauchy principal values</A></H2>
<P>
<A NAME="IDX1349"></A>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qawc</B> <I>(gsl_function *<VAR>f</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>, double <VAR>c</VAR>, double <VAR>epsabs</VAR>, double <VAR>epsrel</VAR>, size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double * <VAR>result</VAR>, double * <VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1350"></A>
</P>
<P>
This function computes the Cauchy principal value of the integral of
f over (a,b), with a singularity at <VAR>c</VAR>,
</P>
<PRE class="example">
I = \int_a^b dx f(x) / (x - c)
</PRE>
<P>
The adaptive bisection algorithm of QAG is used, with modifications to
ensure that subdivisions do not occur at the singular point x = c.
When a subinterval contains the point x = c or is close to
it then a special 25-point modified Clenshaw-Curtis rule is used to control
the singularity. Further away from the
singularity the algorithm uses an ordinary 15-point Gauss-Kronrod
integration rule.
</P>
</DL>
<H2><A NAME="SEC256" HREF="gsl-ref_toc.html#TOC256">QAWS adaptive integration for singular functions</A></H2>
<P>
<A NAME="IDX1351"></A>
The QAWS algorithm is designed for integrands with algebraic-logarithmic
singularities at the end-points of an integration region. In order to
work efficiently the algorithm requires a precomputed table of
Chebyshev moments.
</P>
<P>
<DL>
<DT><U>Function:</U> gsl_integration_qaws_table * <B>gsl_integration_qaws_table_alloc</B> <I>(double <VAR>alpha</VAR>, double <VAR>beta</VAR>, int <VAR>mu</VAR>, int <VAR>nu</VAR>)</I>
<DD><A NAME="IDX1352"></A>
</P>
<P>
This function allocates space for a <CODE>gsl_integration_qaws_table</CODE>
struct and associated workspace describing a singular weight function
W(x) with the parameters (\alpha, \beta, \mu, \nu),
</P>
<PRE class="example">
W(x) = (x-a)^alpha (b-x)^beta log^mu (x-a) log^nu (b-x)
</PRE>
<P>
where \alpha > -1, \beta > -1, and \mu = 0, 1,
\nu = 0, 1. The weight function can take four different forms
depending on the values of \mu and \nu,
</P>
<PRE class="example">
W(x) = (x-a)^alpha (b-x)^beta (mu = 0, nu = 0)
W(x) = (x-a)^alpha (b-x)^beta log(x-a) (mu = 1, nu = 0)
W(x) = (x-a)^alpha (b-x)^beta log(b-x) (mu = 0, nu = 1)
W(x) = (x-a)^alpha (b-x)^beta log(x-a) log(b-x) (mu = 1, nu = 1)
</PRE>
<P>
The singular points (a,b) do not have to be specified until the
integral is computed, where they are the endpoints of the integration
range.
</P>
<P>
The function returns a pointer to the newly allocated
<CODE>gsl_integration_qaws_table</CODE> if no errors were detected, and 0 in
the case of error.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qaws_table_set</B> <I>(gsl_integration_qaws_table * <VAR>t</VAR>, double <VAR>alpha</VAR>, double <VAR>beta</VAR>, int <VAR>mu</VAR>, int <VAR>nu</VAR>)</I>
<DD><A NAME="IDX1353"></A>
This function modifies the parameters (\alpha, \beta, \mu, \nu) of
an existing <CODE>gsl_integration_qaws_table</CODE> struct <VAR>t</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> void <B>gsl_integration_qaws_table_free</B> <I>(gsl_integration_qaws_table * <VAR>t</VAR>)</I>
<DD><A NAME="IDX1354"></A>
This function frees all the memory associated with the
<CODE>gsl_integration_qaws_table</CODE> struct <VAR>t</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qaws</B> <I>(gsl_function * <VAR>f</VAR>, const double <VAR>a</VAR>, const double <VAR>b</VAR>, gsl_integration_qaws_table * <VAR>t</VAR>, const double <VAR>epsabs</VAR>, const double <VAR>epsrel</VAR>, const size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1355"></A>
</P>
<P>
This function computes the integral of the function f(x) over the
interval (a,b) with the singular weight function
(x-a)^\alpha (b-x)^\beta \log^\mu (x-a) \log^\nu (b-x). The parameters
of the weight function (\alpha, \beta, \mu, \nu) are taken from the
table <VAR>t</VAR>. The integral is,
</P>
<PRE class="example">
I = \int_a^b dx f(x) (x-a)^alpha (b-x)^beta log^mu (x-a) log^nu (b-x).
</PRE>
<P>
The adaptive bisection algorithm of QAG is used. When a subinterval
contains one of the endpoints then a special 25-point modified
Clenshaw-Curtis rule is used to control the singularities. For
subintervals which do not include the endpoints an ordinary 15-point
Gauss-Kronrod integration rule is used.
</P>
</DL>
<H2><A NAME="SEC257" HREF="gsl-ref_toc.html#TOC257">QAWO adaptive integration for oscillatory functions</A></H2>
<P>
<A NAME="IDX1356"></A>
The QAWO algorithm is designed for integrands with an oscillatory
factor, \sin(\omega x) or \cos(\omega x). In order to
work efficiently the algorithm requires a table of Chebyshev moments
which must be pre-computed with calls to the functions below.
</P>
<P>
<DL>
<DT><U>Function:</U> gsl_integration_qawo_table * <B>gsl_integration_qawo_table_alloc</B> <I>(double <VAR>omega</VAR>, double <VAR>L</VAR>, enum gsl_integration_qawo_enum <VAR>sine</VAR>, size_t <VAR>n</VAR>)</I>
<DD><A NAME="IDX1357"></A>
</P>
<P>
This function allocates space for a <CODE>gsl_integration_qawo_table</CODE>
struct and its associated workspace describing a sine or cosine weight
function W(x) with the parameters (\omega, L),
</P>
<PRE class="example">
W(x) = sin(omega x)
W(x) = cos(omega x)
</PRE>
<P>
The parameter <VAR>L</VAR> must be the length of the interval over which the
function will be integrated L = b - a. The choice of sine or
cosine is made with the parameter <VAR>sine</VAR> which should be chosen from
one of the two following symbolic values:
</P>
<PRE class="example">
GSL_INTEG_COSINE
GSL_INTEG_SINE
</PRE>
<P>
The <CODE>gsl_integration_qawo_table</CODE> is a table of the trigonometric
coefficients required in the integration process. The parameter <VAR>n</VAR>
determines the number of levels of coefficients that are computed. Each
level corresponds to one bisection of the interval L, so that
<VAR>n</VAR> levels are sufficient for subintervals down to the length
L/2^n. The integration routine <CODE>gsl_integration_qawo</CODE>
returns the error <CODE>GSL_ETABLE</CODE> if the number of levels is
insufficient for the requested accuracy.
</P>
</DL>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qawo_table_set</B> <I>(gsl_integration_qawo_table * <VAR>t</VAR>, double <VAR>omega</VAR>, double <VAR>L</VAR>, enum gsl_integration_qawo_enum <VAR>sine</VAR>)</I>
<DD><A NAME="IDX1358"></A>
This function changes the parameters <VAR>omega</VAR>, <VAR>L</VAR> and <VAR>sine</VAR>
of the existing workspace <VAR>t</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qawo_table_set_length</B> <I>(gsl_integration_qawo_table * <VAR>t</VAR>, double <VAR>L</VAR>)</I>
<DD><A NAME="IDX1359"></A>
This function allows the length parameter <VAR>L</VAR> of the workspace
<VAR>t</VAR> to be changed.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> void <B>gsl_integration_qawo_table_free</B> <I>(gsl_integration_qawo_table * <VAR>t</VAR>)</I>
<DD><A NAME="IDX1360"></A>
This function frees all the memory associated with the workspace <VAR>t</VAR>.
</DL>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qawo</B> <I>(gsl_function * <VAR>f</VAR>, const double <VAR>a</VAR>, const double <VAR>epsabs</VAR>, const double <VAR>epsrel</VAR>, const size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, gsl_integration_qawo_table * <VAR>wf</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1361"></A>
</P>
<P>
This function uses an adaptive algorithm to compute the integral of
f over (a,b) with the weight function
\sin(\omega x) or \cos(\omega x) defined
by the table <VAR>wf</VAR>,
</P>
<PRE class="example">
I = \int_a^b dx f(x) sin(omega x)
I = \int_a^b dx f(x) cos(omega x)
</PRE>
<P>
The results are extrapolated using the epsilon-algorithm to accelerate
the convergence of the integral. The function returns the final
approximation from the extrapolation, <VAR>result</VAR>, and an estimate of
the absolute error, <VAR>abserr</VAR>. The subintervals and their results are
stored in the memory provided by <VAR>workspace</VAR>. The maximum number of
subintervals is given by <VAR>limit</VAR>, which may not exceed the allocated
size of the workspace.
</P>
<P>
Those subintervals with "large" widths d, d\omega > 4 are
computed using a 25-point Clenshaw-Curtis integration rule, which handles the
oscillatory behavior. Subintervals with a "small" width
d\omega < 4 are computed using a 15-point Gauss-Kronrod integration.
</P>
</DL>
<H2><A NAME="SEC258" HREF="gsl-ref_toc.html#TOC258">QAWF adaptive integration for Fourier integrals</A></H2>
<P>
<A NAME="IDX1362"></A>
</P>
<P>
<DL>
<DT><U>Function:</U> int <B>gsl_integration_qawf</B> <I>(gsl_function * <VAR>f</VAR>, const double <VAR>a</VAR>, const double <VAR>epsabs</VAR>, const size_t <VAR>limit</VAR>, gsl_integration_workspace * <VAR>workspace</VAR>, gsl_integration_workspace * <VAR>cycle_workspace</VAR>, gsl_integration_qawo_table * <VAR>wf</VAR>, double *<VAR>result</VAR>, double *<VAR>abserr</VAR>)</I>
<DD><A NAME="IDX1363"></A>
</P>
<P>
This function attempts to compute a Fourier integral of the function
<VAR>f</VAR> over the semi-infinite interval [a,+\infty).
</P>
<PRE class="example">
I = \int_a^{+\infty} dx f(x) sin(omega x)
I = \int_a^{+\infty} dx f(x) cos(omega x)
</PRE>
<P>
The parameter \omega is taken from the table <VAR>wf</VAR> (the length
<VAR>L</VAR> can take any value, since it is overridden by this function to a
value appropriate for the fourier integration). The integral is computed
using the QAWO algorithm over each of the subintervals,
</P>
<PRE class="example">
C_1 = [a, a + c]
C_2 = [a + c, a + 2 c]
... = ...
C_k = [a + (k-1) c, a + k c]
</PRE>
<P>
where
c = (2 floor(|\omega|) + 1) \pi/|\omega|. The width c is
chosen to cover an odd number of periods so that the contributions from
the intervals alternate in sign and are monotonically decreasing when
<VAR>f</VAR> is positive and monotonically decreasing. The sum of this
sequence of contributions is accelerated using the epsilon-algorithm.
</P>
<P>
This function works to an overall absolute tolerance of
<VAR>abserr</VAR>. The following strategy is used: on each interval
C_k the algorithm tries to achieve the tolerance
</P>
<PRE class="example">
TOL_k = u_k abserr
</PRE>
<P>
where
u_k = (1 - p)p^{k-1} and p = 9/10.
The sum of the geometric series of contributions from each interval
gives an overall tolerance of <VAR>abserr</VAR>.
</P>
<P>
If the integration of a subinterval leads to difficulties then the
accuracy requirement for subsequent intervals is relaxed,
</P>
<PRE class="example">
TOL_k = u_k max(abserr, max_{i<k}{E_i})
</PRE>
<P>
where E_k is the estimated error on the interval C_k.
</P>
<P>
The subintervals and their results are stored in the memory provided by
<VAR>workspace</VAR>. The maximum number of subintervals is given by
<VAR>limit</VAR>, which may not exceed the allocated size of the workspace.
The integration over each subinterval uses the memory provided by
<VAR>cycle_workspace</VAR> as workspace for the QAWO algorithm.
</P>
</DL>
<H2><A NAME="SEC259" HREF="gsl-ref_toc.html#TOC259">Error codes</A></H2>
<P>
In addition to the standard error codes for invalid arguments the
functions can return the following values,
</P>
<DL COMPACT>
<DT><CODE>GSL_EMAXITER</CODE>
<DD>
the maximum number of subdivisions was exceeded.
<DT><CODE>GSL_EROUND</CODE>
<DD>
cannot reach tolerance because of roundoff error,
or roundoff error was detected in the extrapolation table.
<DT><CODE>GSL_ESING</CODE>
<DD>
a non-integrable singularity or other bad integrand behavior was found
in the integration interval.
<DT><CODE>GSL_EDIVERGE</CODE>
<DD>
the integral is divergent, or too slowly convergent to be integrated
numerically.
</DL>
<H2><A NAME="SEC260" HREF="gsl-ref_toc.html#TOC260">Examples</A></H2>
<P>
The integrator <CODE>QAGS</CODE> will handle a large class of definite
integrals. For example, consider the following integral, which has a
algebraic-logarithmic singularity at the origin,
</P>
<PRE class="example">
\int_0^1 x^{-1/2} log(x) dx = -4
</PRE>
<P>
The program below computes this integral to a relative accuracy bound of
<CODE>1e-7</CODE>.
</P>
<PRE class="example">
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
double f (double x, void * params) {
double alpha = *(double *) params;
double f = log(alpha*x) / sqrt(x);
return f;
}
int
main (void)
{
gsl_integration_workspace * w
= gsl_integration_workspace_alloc (1000);
double result, error;
double expected = -4.0;
double alpha = 1.0;
gsl_function F;
F.function = &f;
F.params = &alpha;
gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
w, &result, &error);
printf ("result = % .18f\n", result);
printf ("exact result = % .18f\n", expected);
printf ("estimated error = % .18f\n", error);
printf ("actual error = % .18f\n", result - expected);
printf ("intervals = %d\n", w->size);
return 0;
}
</PRE>
<P>
The results below show that the desired accuracy is achieved after 8
subdivisions.
</P>
<PRE class="example">
bash$ ./a.out
result = -3.999999999999973799
exact result = -4.000000000000000000
estimated error = 0.000000000000246025
actual error = 0.000000000000026201
intervals = 8
</PRE>
<P>
In fact, the extrapolation procedure used by <CODE>QAGS</CODE> produces an
accuracy of almost twice as many digits. The error estimate returned by
the extrapolation procedure is larger than the actual error, giving a
margin of safety of one order of magnitude.
</P>
<H2><A NAME="SEC261" HREF="gsl-ref_toc.html#TOC261">References and Further Reading</A></H2>
<P>
The following book is the definitive reference for QUADPACK, and was
written by the original authors. It provides descriptions of the
algorithms, program listings, test programs and examples. It also
includes useful advice on numerical integration and many references to
the numerical integration literature used in developing QUADPACK.
</P>
<UL class="itemize">
<LI>
R. Piessens, E. de Doncker-Kapenga, C.W. Uberhuber, D.K. Kahaner.
<CITE>QUADPACK A subroutine package for automatic integration</CITE>
Springer Verlag, 1983.
</UL>
<P>
</P>
<P><HR><P>
<p>Go to the <A HREF="gsl-ref_1.html">first</A>, <A HREF="gsl-ref_15.html">previous</A>, <A HREF="gsl-ref_17.html">next</A>, <A HREF="gsl-ref_50.html">last</A> section, <A HREF="gsl-ref_toc.html">table of contents</A>.
</BODY>
</HTML>
|