intFcnAlgLog

../../_images/OpenMP.png

Integrates a function with algebraic-logarithmic singularities.

Synopsis

intFcnAlgLog (fcn, a, b, weight, alpha, beta)

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.
int weight, float alpha, float beta (Input)
These three parameters are used to describe the weight function that may have algebraic or logarithmic singularities at the endpoints. The parameter weight can take on four values as described below. The parameters alpha = α and beta = β specify the strength of the singularities at a or b and hence, must be greater than −1.
Weight Integration Weight
ALG \((x - a)^a (b - x)^b\)
ALG_LEFT_LOG \((x - a)^a (b - x)^b \log(x - a)\)
ALG_RIGHT_LOG \((x - a)^a (b - x)^b \log(b - x)\)
ALG_LOG \((x - a)^a (b - x)^b \log(x - a) \log (b - x)\)

Return Value

The value of

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

is returned where w(x) is one of the four weights above. If no value can be computed, then 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 intFcnAlgLog is a special-purpose integrator that uses a globally adaptive scheme to reduce the absolute error. It computes integrals whose integrands have the special form w(x)f(x) where w(x) is a weight function described above. A combination of modified Clenshaw-Curtis and Gauss-Kronrod formulas is employed. This function is based on the subroutine QAWS, which is fully documented by Piessens et al. (1983).

Examples

Example 1

The value of

\[\int_0^1 \left[(1+x)(1-x)\right]^{1/2} x \ln(x)dx = \frac{3 \ln(2) - 4}{9}\]

is computed.

from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnAlgLog import intFcnAlgLog, ALG_LEFT_LOG


def fcn(x):
    return sqrt(1 + x)


# Evaluate the integral
err_est = []
n_evals = []
q = intFcnAlgLog(fcn, 0.0, 1.0, ALG_LEFT_LOG, 1.0, 0.5)

# Print the result and the exact answer
exact = (3. * log(2.) - 4.) / 9.
print("integral  = %10.3f\nexact     = %10.3f" % (q, exact))

Output

integral  =     -0.213
exact     =     -0.213

Example 2

The value of

\[\int_0^1 \left[(1+x)(1-x)\right]^{1/2} x \ln(x)dx = \frac{3 \ln(2) - 4}{9}\]

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.intFcnAlgLog import intFcnAlgLog, ALG_LEFT_LOG


def fcn(x):
    return sqrt(1 + x)


# Evaluate the integral
err_est = []
n_evals = []
q = intFcnAlgLog(fcn, 0.0, 1.0, ALG_LEFT_LOG, 1.0, 0.5,
                 errEst=err_est,
                 nEvals=n_evals)

# Print the result and the exact answer
exact = (3. * log(2.) - 4.) / 9.
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.213
exact     =     -0.213
error estimate   = 1.083073e-15
exact error      = 2.775558e-17
The number of function evaluations  =  50

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 = “#”.