intFcnSmooth¶
Integrates a smooth function using a nonadaptive rule.
Synopsis¶
intFcnSmooth (fcn, a, b)
Required Arguments¶
- float
fcn
(x
) (Input) - User-supplied function to be integrated.
- float
a
(Input) - Lower limit of integration.
- float
b
(Input) - Upper limit of integration.
Return Value¶
The value of
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.
Description¶
The function intFcnSmooth
is designed to integrate smooth functions. It
implements a nonadaptive quadrature procedure based on nested Paterson rules
of order 10, 21, 43, and 87. These rules are positive quadrature rules with
degree of accuracy 19, 31, 64, and 130, respectively. The function
intFcnSmooth
applies these rules successively, estimating the error,
until either the error estimate satisfies the user-supplied constraints or
the last rule is applied.
This function is not very robust, but for certain smooth functions it can be
efficient. If intFcnSmooth
should not perform well, we recommend the use
of the function intFcnSing.
The function intFcnSmooth
is based on the subroutine QNG by Piessens et
al. (1983).
Examples¶
Example 1¶
The value of
is computed.
from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnSmooth import intFcnSmooth
def fcn(x):
return x * exp(x)
# Evaluate the integral
q = intFcnSmooth(fcn, 0.0, 2.0)
# Print the result and the exact answer
exact = exp(2.0) + 1.0
print("integral = %10.3f\nexact = %10.3f" % (q, exact))
Output¶
integral = 8.389
exact = 8.389
Example 2¶
The value of
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.
from __future__ import print_function
from numpy import *
from pyimsl.math.intFcnSmooth import intFcnSmooth
def fcn(x):
return x * exp(x)
# Evaluate the integral
err_est = []
n_evals = []
q = intFcnSmooth(fcn, 0.0, 2.0,
errEst=err_est)
# Print the result and the exact answer
exact = exp(2.0) + 1.0
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))
Output¶
integral = 8.389
exact = 8.389
error estimate = 9.313723e-14
exact error = 1.776357e-15
Fatal Errors¶
IMSL_MAX_STEPS |
The maximum number of steps allowed have been taken. The integrand is too difficult for this routine. |
IMSL_STOP_USER_FCN |
Request from user supplied function to stop algorithm. User flag = “#”. |