archimedes.quadrature.integralΒΆ
- archimedes.quadrature.integral(
- func: Callable[[...], ndarray],
- a: float,
- b: float,
- n: int = 20,
- rule: str = 'legendre',
- axis: int = -1,
- args: Sequence[Any] | None = None,
Approximate the definite integral of
funcover[a, b].\[\int_a^b f(x) \, dx \approx \sum_{i=1}^n w_i f(x_i)\]using a fixed-order Gauss quadrature rule (by default Gauss-Legendre quadrature).
This is a convenience wrapper around the
rule(n).integrate(f, a, b)pattern (seeQuadratureRule.integrate()) for one-off integrals on a finite interval; for repeated evaluation of the same rule (e.g. inside a loop or a function decorated witharchimedes.compile()), build theQuadratureRuleonce withgauss_legendre(),gauss_radau(),gauss_lobatto(), orclenshaw_curtis()and call.integratedirectly instead.- Parameters:
func (callable) β Integrand. Called once as
func(x, *args)on the full array of quadrature nodes, so must be vectorized. Must return values with the nodes alongaxis.a (float) β Bounds of integration. Must both be finite (see Notes).
b (float) β Bounds of integration. Must both be finite (see Notes).
n (int, optional) β Number of quadrature nodes. Default 20.
rule ({"legendre", "radau_left", "radau_right", "lobatto", "clenshaw_curtis"}, optional) β Quadrature family to use, all defined on
[a, b]with uniform weight. Default"legendre"(no fixed endpoints, exact to degree2n - 1). Use"radau_left"/"radau_right"to fix the left/right endpoint as a node, or"lobatto"to fix both; seegauss_radau()andgauss_lobatto()for the accompanying loss of exactness.axis (int, optional) β Axis holding the nodes in the output of
func. Default -1.args (tuple, optional) β Extra arguments passed to
funcafterx.
- Returns:
value β Approximated integral. Shape (m,) for vector-valued integrands, or () for scalar integrands.
- Return type:
ndarray
- Raises:
ValueError β If
ruleis not one of the supported names, or ifa/bare not finite.
Notes
This function only supports finite
[a, b]. Unlikescipy.integrate.quad, it does not adapt the node count or use a variable transformation to reach infinite/semi-infinite intervals β it is a thin wrapper around a single fixed-order rule. Gauss-Laguerre and Gauss-Hermite quadrature can integrate over semi-infinite and infinite intervals, but only the weighted integral \(\int f(x) e^{-x} \, dx\) or \(\int f(x) e^{-x^2} \, dx\) respectively β correcting for the weight by evaluating \(f(x) e^{x}\) (or \(e^{x^2}\)) at the nodes reintroduces the overflow/cancellation problems Gauss quadrature exists to avoid, so this is not done automatically. If your integrand already has the appropriate decay, construct aQuadratureRuledirectly with anLaguerreMeasureorHermiteMeasureinstead of using this function.See also
QuadratureRule.integrateUnderlying integration method.
gauss_legendre,gauss_radau,gauss_lobatto,clenshaw_curtisscipy.integrate.quadAdaptive quadrature, including infinite and semi-infinite intervals.