{ } Raw JSON

bundles / scipy 1.17.1 / scipy / integrate / _rules / _base / FixedRule

class

scipy.integrate._rules._base:FixedRule

source: /scipy/integrate/_rules/_base.py :154

Signature

class   FixedRule ( )

Members

Summary

A rule implemented as the weighted sum of function evaluations at fixed nodes.

Attributes

nodes_and_weights : (ndarray, ndarray)

A tuple (nodes, weights) of nodes at which to evaluate f and the corresponding weights. nodes should be of shape (num_nodes,) for 1D cubature rules (quadratures) and more generally for N-D cubature rules, it should be of shape (num_nodes, ndim). weights should be of shape (num_nodes,). The nodes and weights should be for integrals over .

Examples

Implementing Simpson's 1/3 rule:
import numpy as np
from scipy.integrate._rules import FixedRule
class SimpsonsQuad(FixedRule):
    @property
    def nodes_and_weights(self):
        nodes = np.array([-1, 0, 1])
        weights = np.array([1/3, 4/3, 1/3])
        return (nodes, weights)
rule = SimpsonsQuad()
rule.estimate(
    f=lambda x: x**2,
    a=np.array([0]),
    b=np.array([1]),
)

See also

GaussKronrodQuadrature
GaussLegendreQuadrature
GenzMalikCubature

Aliases

  • scipy.integrate._rules.FixedRule