bundles / scipy latest / scipy / integrate / _quad_vec / quad_vec
function
scipy.integrate._quad_vec:quad_vec
Signature
def quad_vec ( f , a , b , epsabs = 1e-200 , epsrel = 1e-08 , norm = 2 , cache_size = 100000000.0 , limit = 10000 , workers = 1 , points = None , quadrature = None , full_output = False , * , args = () ) Summary
Adaptive integration of a vector-valued function.
Parameters
f: callableVector-valued function f(x) to integrate.
a: floatInitial point.
b: floatFinal point.
epsabs: float, optionalAbsolute tolerance.
epsrel: float, optionalRelative tolerance.
norm: {'max', '2'}, optionalVector norm to use for error estimation.
cache_size: int, optionalNumber of bytes to use for memoization.
limit: float or int, optionalAn upper bound on the number of subintervals used in the adaptive algorithm.
workers: int or map-like callable, optionalIf
workersis an integer, part of the computation is done in parallel subdivided to this many tasks (usingpython:multiprocessing.pool.Pool). Supply-1to use all cores available to the Process. Alternatively, supply a map-like callable, such aspython:multiprocessing.pool.Pool.mapfor evaluating the population in parallel. This evaluation is carried out asworkers(func, iterable).points: list, optionalList of additional breakpoints.
quadrature: {'gk21', 'gk15', 'trapezoid'}, optionalQuadrature rule to use on subintervals. Options: 'gk21' (Gauss-Kronrod 21-point rule), 'gk15' (Gauss-Kronrod 15-point rule), 'trapezoid' (composite trapezoid rule). Default: 'gk21' for finite intervals and 'gk15' for (semi-)infinite.
full_output: bool, optionalReturn an additional
infoobject.args: tuple, optionalExtra arguments to pass to function, if any.
Returns
res: {float, array-like}Estimate for the result
err: floatError estimate for the result in the given norm
info: objectReturned only when
full_output=True. Result object with the attributes:success
success
status
status
neval
neval
intervals
intervals
integrals
integrals
errors
errors
Notes
The algorithm mainly follows the implementation of QUADPACK's DQAG* algorithms, implementing global error control and adaptive subdivision.
The algorithm here has some differences to the QUADPACK approach:
Instead of subdividing one interval at a time, the algorithm subdivides N intervals with largest errors at once. This enables (partial) parallelization of the integration.
The logic of subdividing "next largest" intervals first is then not implemented, and we rely on the above extension to avoid concentrating on "small" intervals only.
The Wynn epsilon table extrapolation is not used (QUADPACK uses it for infinite intervals). This is because the algorithm here is supposed to work on vector-valued functions, in an user-specified norm, and the extension of the epsilon algorithm to this case does not appear to be widely agreed. For max-norm, using elementwise Wynn epsilon could be possible, but we do not do this here with the hope that the epsilon extrapolation is mainly useful in special cases.
Array API Standard Support
quad_vec has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
We can compute integrations of a vector-valued function:from scipy.integrate import quad_vec import numpy as np import matplotlib.pyplot as plt alpha = np.linspace(0.0, 2.0, num=30) f = lambda x: x**alpha x0, x1 = 0, 2 y, err = quad_vec(f, x0, x1)✓
plt.plot(alpha, y) plt.xlabel(r"$\alpha$") plt.ylabel(r"$\int_{0}^{2} x^\alpha dx$")✗
plt.show()
✓
Aliases
-
scipy.integrate.quad_vec