Computing integrals with weighting functions
In the following sections, we will look at how to compute integrals with weight functions.
Getting ready
The proper function needs to be executed using the equations in each case.
How to do it...
- Weighted functions can be realized as products of the f(x)w(x) kind for some smooth function f(x) with a non-negative weight function w(x) containing singularities.
- An illustrative example is given by cos(πx/2)/√x. We could regard this case as the product of cos(πx/2) with w(x)=1/√x. The weight presents a single singularity of x=0, and is smooth otherwise.
- The usual way to treat these integrals is by means of weighted Gaussian quadrature formulas. For example, to perform principal value integrals of functions of the form f(x)/(x-c), we issue quad with the
weight='cauchy'
andwvar=c
arguments. This calls the routine QAWC from QUADPACK.
Let's experiment with the Fresnel-type sine integral of g(x) = sin(x)/x on the [-1,1] interval and compare it with romberg
:
In...