bundles / scipy latest / scipy / integrate / _rules / _gauss_kronrod / GaussKronrodQuadrature
class
scipy.integrate._rules._gauss_kronrod:GaussKronrodQuadrature
Signature
class GaussKronrodQuadrature ( npoints , xp = None ) Members
Summary
Gauss-Kronrod quadrature.
Extended Summary
Gauss-Kronrod rules consist of two quadrature rules, one higher-order and one lower-order. The higher-order rule is used as the estimate of the integral and the difference between them is used as an estimate for the error.
Gauss-Kronrod is a 1D rule. To use it for multidimensional integrals, it will be necessary to use ProductNestedFixed and multiple Gauss-Kronrod rules. See Examples.
For n-node Gauss-Kronrod, the lower-order rule has n//2 nodes, which are the ordinary Gauss-Legendre nodes with corresponding weights. The higher-order rule has n nodes, n//2 of which are the same as the lower-order rule and the remaining nodes are the Kronrod extension of those nodes.
Parameters
npoints: intNumber of nodes for the higher-order rule.
xp: array_namespace, optionalThe namespace for the node and weight arrays. Default is None, where NumPy is used.
Attributes
lower: RuleLower-order rule.
Examples
Evaluate a 1D integral. Note in this example that ``f`` returns an array, so the estimates will also be arrays, despite the fact that this is a 1D problem.import numpy as np from scipy.integrate import cubature from scipy.integrate._rules import GaussKronrodQuadrature def f(x): return np.cos(x) rule = GaussKronrodQuadrature(21) # Use 21-point GaussKronrod a, b = np.array([0]), np.array([1])✓
rule.estimate(f, a, b) # True value sin(1), approximately 0.84147 rule.estimate_error(f, a, b)✗
import numpy as np from scipy.integrate import cubature from scipy.integrate._rules import ( ProductNestedFixed, GaussKronrodQuadrature ) def f(x): # f(x) = cos(x_1) + cos(x_2) return np.sum(np.cos(x), axis=-1) rule = ProductNestedFixed( [GaussKronrodQuadrature(15), GaussKronrodQuadrature(15)] ) # Use 15-point Gauss-Kronrod a, b = np.array([0, 0]), np.array([1, 1])✓
rule.estimate(f, a, b) # True value 2*sin(1), approximately 1.6829 rule.estimate_error(f, a, b)✗
Aliases
-
scipy.integrate._cubature.GaussKronrodQuadrature