{ } Raw JSON

bundles / scipy 1.18.0 / scipy / integrate / _rules / _gauss_legendre / GaussLegendreQuadrature

class

scipy.integrate._rules._gauss_legendre:GaussLegendreQuadrature

source: /scipy/integrate/_rules/_gauss_legendre.py:10

Signature

class GaussLegendreQuadrature(npoints, xp = None)

Members

Summary

Gauss-Legendre quadrature.

Parameters

npoints : int

Number of nodes for the higher-order rule.

xp : array_namespace, optional

The namespace for the node and weight arrays. Default is None, where NumPy is used.

Examples

Evaluate a 1D integral. Note in this example that ``f`` returns an array, so the estimates will also be arrays.
import numpy as np
from scipy.integrate import cubature
from scipy.integrate._rules import GaussLegendreQuadrature
def f(x):
    return np.cos(x)
rule = GaussLegendreQuadrature(21) # Use 21-point GaussLegendre
a, b = np.array([0]), np.array([1])
✓
rule.estimate(f, a, b) # True value sin(1), approximately 0.84147
✗
array([0])
rule.estimate_error(f, a, b)
⚠
Traceback (most recent call last):
  File "<doctest scipy.integrate._rules._gauss_legendre:GaussLegendreQuadrature[0]>", line 1, in <module>
    rule.estimate_error(f, a, b)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.7/x64/lib/python3.14/site-packages/scipy/integrate/_rules/_base.py", line 148, in estimate_error
    for a_k, b_k in _split_subregion(a, b):
                    ~~~~~~~~~~~~~~~~^^^^^^
TypeError: _split_subregion() missing 1 required positional argument: 'xp'

Aliases

  • scipy.integrate._rules.GaussLegendreQuadrature