intFcnInf

../../_images/OpenMP.png

Integrates a function over an infinite or semi-infinite interval.

Synopsis

intFcnInf (fcn, bound, interval)

Required Arguments

float fcn (x) (Input)
User-supplied function to be integrated.
float bound (Input)
Finite limit of integration. This argument is ignored if interval has the value INF_INF.
int interval (Input)
Flag indicating integration limits. The following settings are allowed:
interval Integration Limits
INF_BOUND (-∞, bound)
BOUND_INF (bound, ∞)
INF_INF (-∞, ∞)

Return Value

The value of

\[\int_a^b\textit{fcn}(x)dx\]

is returned where a and b are appropriate integration limits. 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 intFcnInf is a special-purpose integrator that uses a globally adaptive scheme to reduce the absolute error. It initially transforms an infinite or semi-infinite interval into the finite interval [0, 1]. It then uses the same strategy as the function intFcnSing.

The function intFcnInf is based on the subroutine QAGI by Piessens et al. (1983).

Examples

Example 1

The value of

\[\int_{0}^{\infty} \frac{\ln(x)}{1+(10x)^2} dx = \frac{-\pi \ln(10)}{20}\]

is computed.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.intFcnInf import intFcnInf, BOUND_INF


def fcn(x):
    z = 10. * x
    return log(x) / (1 + z * z)


pi = constant("pi")

# Evaluate the integral
q = intFcnInf(fcn, 0.0, BOUND_INF)

# Print the result and the exact answer
exact = -pi * log(10.) / 20.
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))

Output

integral  =     -0.362
exact     =     -0.362

Example 2

The value of

\[\int_{0}^{\infty} \frac{\ln x}{1+(10x)^2} dx = \frac{-\pi \ln(10)}{20}\]

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 in this example. The number of function evaluations also are printed.

from __future__ import print_function
from numpy import *
from pyimsl.math.constant import constant
from pyimsl.math.intFcnInf import intFcnInf, BOUND_INF


def fcn(x):
    z = 10. * x
    return log(x) / (1 + z * z)


pi = constant("pi")
err_est = []
n_evals = []

# Evaluate the integral
q = intFcnInf(fcn, 0.0, BOUND_INF,
              errEst=err_est,
              nEvals=n_evals)

# Print the result and the exact answer
exact = -pi * log(10.) / 20.
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.362
exact     =     -0.362
error estimate   = 2.037102e-09
exact error      = 3.286260e-14
The number of function evaluations  =  465

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.
IMSL_EXTRAPOLATION_ROUNDOFF Roundoff error in the extrapolation table, preventing the requested tolerance from being achieved, has been detected.

Fatal Errors

IMSL_DIVERGENT Integral is probably divergent or slowly convergent.
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 = “#”.