intFcnSing2d¶
Integrates a function of two variables with a possible internal or endpoint singularity.
Synopsis¶
intFcnSing2d (fcn, a, b, gcn, hcn)
Required Arguments¶
- float
fcn
(x
,y
) (Input/Output) - User-supplied function to be integrated.
- float
a
(Input) - Lower limit of integration for outer dimension.
- float
b
(Input) - Upper limit of integration for outer dimension. The relative values of
a
andb
are interpreted properly. Thus if one exchangesa
andb
, the sign of the answer is changed. When the integrand is positive, the sign of the result is the same as the sign ofb
–
a
. - float
gcn
(x
) (Input/Output) - User-supplied function to compute the lower limit of integration for the inner dimension.
- float
hcn
(x
) (Input/Output) - User-supplied function to compute the upper limit of integration for the inner dimension.
Return Value¶
An estimate of
Optional Arguments¶
errAbs
, float (Input)Absolute error tolerance. See Remark 1 for a discussion on the error tolerances.
Default:
errAbs
= 0.0errFrac
, float (Input)A fraction expressing the (number of correct digits of accuracy desired)/(number of digits of achievable precision). See Remark 1 for a discussion on accuracy.
Default:
errFrac
= 0.75errRel
, float (Input)The error tolerance relative to the value of the integral. See Remark 1 for a discussion on the error tolerances.
Default:
errRel
= 0.0errPrior
, float (Input)An a priori estimate of the absolute value of the relative error expected to be committed while evaluating the integrand. Changes to this value are not detected during evaluation of the integral.
Default: Default:
errPrior
=machine(4)
maxEvals
, int (Input)The maximum number of function evaluations to use to compute the integral.
Default: The number of function values is not bounded.
singularity
, floatsingularity
, intsingularityType
(Input)singularity
is the real part of the abscissa of a singularity or discontinuity in the innermost integrand.singularityType
is a signed integer specifying the type of singularity which occurs in the integrand. If the singularity has a leading term of the form \(x^\alpha\) where α is not an integer, if α is “large” or has the form \(\alpha = (2 * n * -1)/2\) where n is a nonnegative integer, or the singularity is well outside the interval, setsingularityType
to a positive integer. Otherwise, setsingularityType
to a negative integer. Also see Remark 2.Default: It is assumed that there is no singularity in the innermost integrand sosingularity
andsingularityType
are not set.nEvals
(Output)- Number of function evaluations used to calculate the integral.
errEst
(Output)- An estimate of the upper bound of the magnitude of the difference between
the value returned by
intFcnSing2d
and the true value of the integral. iStatus
(Output)- A status flag indicating the error criteria which was satisfied on exit.
iStatus |
Description |
---|---|
-2 | Indicates normal termination with either the absolute or relative error tolerance criteria satisfied. |
-3 | Indicates normal termination with neither the absolute nor the relative error tolerance criteria satisfied, but the error tolerance based on the locally achievable precision is satisfied. |
-4 | Indicates normal termination with none of the error tolerance criteria satisfied. |
Other | Any value other than the above indicates abnormal termination due to an error condition. |
Description¶
The function intFcnSing2d
, based on the JPL Library routine SINTM
,
approximates an iterated two-dimensional integral of the form
The integral over two dimensions is computed by repeated integration over one dimension. The integration over one dimension is estimated using quadrature formulae due to T. N. L. Patterson (1968). Patterson described a family of formulae in which the \(k^{th}\) formula used all the integrand values used in the \(k‑1^{st}\) formula, and added \(2^{k-1}\) new integrand values in an optimal way. The first formula is the midpoint rule, the second is the three point Gauss formula, and the third is the seven point Kronrod formula. Formulae of this family of higher degree had not previously been described. This program uses formulae up to \(k = 8\).
An error estimate is obtained by comparing the values of the integral estimated by two adjacent formulae, examining differences up to the fifteenth order, integrating round-off error, integrating error declared to have been committed during computation of the integrand, integrating a first order estimate of the effect round-off error in the abscissa has on integrand values, and including errors in the limits. The latter four methods are also used to derive a bound on the achievable precision.
If the integral over an interval cannot be estimated with sufficient accuracy, the interval is subdivided. The difference table is used to discover whether the integral is difficult to compute because the integrand is too complex or has singular behavior. In the former case, the estimated error, requested error tolerance, and difference table are used to choose a step size.
In the latter case, the difference table is used in a search algorithm to find the abscissa of the singular behavior. If the singular behavior is discovered on the end of an interval, a change of independent variable is applied to reduce the strength of the singularity.
The program also uses the difference table to detect nonintegrable singularities, jump discontinuities, and computational noise.
Remarks¶
Remark 1
The user provides the absolute error tolerance through optional argument
errAbs
. Optional argument errFrac
represents the ratio of the
(number of correct digits of accuracy desired) to (number of digits of
achievable precision). Optional argument errRel
represents the error
tolerance relative to the value of the integral. The internal value for
errFrac
is bounded between 0.5 and 1. By default, errAbs
and
errRel
are set to 0.0 and errFrac
is set to 0.75. These default
values usually provide all the accuracy that can be obtained efficiently.
The error tolerance relative to the value of the integral is applied globally (over the entire region of integration) rather than locally (one step at a time). This policy provides true control of error relative to the value of the integral when the integrand is not sign definite, as well as when the integrand is sign definite. To apply the criterion of error tolerance relative to the value of the integral, the value of the integral over the entire region, estimated without refinement of the region, is used to derive an absolute error tolerance that may be applied locally. If the preliminary estimate of the value of the integral is significantly in error, and the least restrictive error tolerance is relative to the value of the integral, the cost of computing the integral will be larger than the cost of computing the integral to the same degree of accuracy using appropriate values of either of the other tolerance criteria. The preliminary estimate of the integral may be significantly in error if the integrand is not sign definite or has large variation.
Remark 2
Optional argument singularity
provides the user with a means to give the
routine information about the location and type of any known singularity of
the innermost integrand. When an integrand appears to have singular behavior
at the end of the interval, a transformation of the variable of integration
is applied to reduce the strength of the singularity. When an integrand
appears to have singular behavior inside the interval, the abscissa of the
singularity is determined as precisely as necessary, depending on the error
tolerance, and the interval is subdivided. The discovery of singular
behavior and determination of the abscissa of singular behavior are
expensive. If the user knows of the existence of a singularity, the
efficiency of computation of the integral may be improved by requesting an
immediate transformation of the independent variable or subdivision of the
interval. It is recommended that the user select these optional arguments
for all singularities, even those outside [a
, b
]. If the singularity
has a leading term of the form \(x^\alpha\) where α is not an integer, if
α is “large” or has the form \(\alpha = (2n ‑ 1)/2\) where n is a
nonnegative integer, or the singularity is well outside the interval, set
singularityType
to a positive value. Otherwise, set singularityType
to a negative value. The meaning of “large” depends on the rest of the
integrand and the length of the interval. For the typical case, a value of
about 2 is considered “large”. For a singularity of the form \(x^\alpha
\log x\) use the above rule, even if α is an integer. For other types of
singularities make a reasonable guess based on the above. If several similar
integrals are to be computed, some experimentation may be useful.
When singularityType
is positive, a transformation of the form \(T =
TA + (X ‑ TA)^2 / (TB – TA)\) is applied, where TA is the abscissa of the
singularity and TB is the end of the interval. If TA is outside the
interval, TB will be the end of the interval farthest from
TA. If TA is inside the interval, the interval will immediately be
subdivided at TA, and both parts will be separately integrated with TB
equal to each end of the original interval, respectively. When
singularityType
is negative, a transformation of the form \(T = TA +
(X – TA)^4 / (TB – TA)^3\) is applied, with TA and TB as above.
If the integrand has singularities at more than one abscissa within the region, or more than one pole near the real axis such that the real parts are within the region of integration, then the interval should be subdivided at the abscissa of the singularities or the real parts of the poles, and the integrals should be computed as separate problems, with the results summed.
Example¶
The value of
is estimated.
from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnSing2d import intFcnSing2d
def fcn(x, y):
return y * cos(x + y * y)
def gcn(x):
return 1.0
def hcn(x):
return 3.0
errest = []
q = intFcnSing2d(fcn, 0.0, 1.0, gcn, hcn, errEst=errest)
print("The approximation to the integral is %f" % q)
print("The estimated error is %6.1e" % errest[0])
Output¶
The approximation to the integral is -0.514254
The estimated error is 5.9e-15
Fatal Errors¶
IMSL_NONINTEGRABLE |
The integrand apparently contains a nonintegrable singularity. The abscissa of the singularity is near #. The result has been set to NaN. |
IMSL_MAX_FCN_EVAL_EXCEEDED_NAN |
The maximum number of function
evaluations allowed,
“maxEvals ”, has been
exceeded. “maxEvals ” is
currently set to a value of #.
The result has been set to NaN. |
IMSL_CRITERIA_NOT_SATISFIED |
The algorithm has terminated without satisfying any of the error tolerance criteria. The error estimate is #. |
IMSL_STOP_USER_FCN |
Request from user supplied function to stop algorithm. User flag = “#”. |