intFcnCauchy

../../_images/OpenMP.png

Computes integrals of the form

\[\int_a^b \frac{f(x)}{x-c} dx\]

in the Cauchy principal value sense.

Synopsis

intFcnCauchy (fcn, a, b, c)

Required Arguments

float fcn (float x) (Input)
User-supplied function to be integrated.
float a (Input)
Lower limit of integration.
float b (Input)
Upper limit of integration.
float c (Input)
Singular point, c must not equal a or b.

Return Value

The value of

\[\int_a^b \frac{\mathit{fcn}(x)}{x-c} dx\]

is returned. If no value can be computed, NaN is returned.

Optional Arguments

errAbs, float (Input)

Absolute accuracy desired.

Default: \(\mathit{errAbs} = \sqrt{\varepsilon}\) where ɛ is the machine precision

errRel, float (Input)

Relative accuracy desired.

Default: \(\mathit{errRel} = \sqrt{\varepsilon}\) where ɛ is the machine precision

errEst (Output)
An estimate of the absolute value of the error.
maxSubinter, int (Input)

Number of subintervals allowed.

Default: maxSubinter = 500

nSubinter (Output)
The number of subintervals generated.
nEvals (Output)
The number of evaluations of fcn.

Description

The function intFcnCauchy uses a globally adaptive scheme in an attempt to reduce the absolute error. It computes integrals whose integrands have the special form \(w(x) f(x)\) where \(w(x) = 1∕{(x − c)}\). If c lies in the interval of integration, then the integral is interpreted as a Cauchy principal value. A combination of modified Clenshaw-Curtis and Gauss-Kronrod formulas are employed.

The function intFcnCauchy is an implementation of the subroutine QAWC by Piessens et al. (1983).

Examples

Example 1

The Cauchy principal value of

\[\int_{-1}^{5} \frac{1}{x\left(5x^3+6\right)} dx = \frac{\ln (125/631)}{18}\]

is computed.

from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnCauchy import intFcnCauchy


def fcn(x):
    return 1.0 / (5.0 * x * x * x + 6.0)


# Evaluate the integral
q = intFcnCauchy(fcn, -1.0, 5.0, 0.0)

# Print the result and the exact answer
exact = log(125. / 631.) / 18.
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))

Output

integral  =     -0.090
exact     =     -0.090

Example 2

The Cauchy principal value of

\[\int_{-1}^{5} \frac{1}{x\left(5x^3+6\right)} dx = \frac{\ln (125/631)}{18}\]

is again computed. The values of the actual and estimated error are printed as well. Note that these numbers are machine dependent. Furthermore, the error estimate is usually pessimistic. That is, the actual error is usually smaller than the error estimate, as is the case in this example. The number of function evaluations also are printed.

from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnCauchy import intFcnCauchy

err_est = []
n_evals = []


def fcn(x):
    return 1.0 / (5.0 * x * x * x + 6.0)


# Evaluate the integral
q = intFcnCauchy(fcn, -1.0, 5.0, 0.0,
                 errEst=err_est,
                 nEvals=n_evals)

# Print the result and the exact answer
exact = log(125. / 631.) / 18.
exact_err = fabs(exact - q)
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))
print("error estimate   = %e\nexact error      = %e" %
      (err_est[0], exact_err))
print("The number of function evaluations  =  %d" % n_evals[0])

Output

integral  =     -0.090
exact     =     -0.090
error estimate   = 1.303189e-08
exact error      = 5.787038e-15
The number of function evaluations  =  245

Warning Errors

IMSL_ROUNDOFF_CONTAMINATION Roundoff error, preventing the requested tolerance from being achieved, has been detected.
IMSL_PRECISION_DEGRADATION A degradation in precision has been detected.

Fatal Errors

IMSL_MAX_SUBINTERVALS The maximum number of subintervals allowed has been reached.
IMSL_STOP_USER_FCN

Request from user supplied function to stop algorithm.

User flag = “#”.