bundles / scipy latest / scipy / integrate / _quadrature / simpson
function
scipy.integrate._quadrature:simpson
source: build-install/usr/lib/python3.14/site-packages/scipy/integrate/_quadrature.py:392
Signature
def simpson(y, x = None, *, dx = 1.0, axis = -1)Summary
Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed.
Parameters
y: array_likeArray to be integrated.
x: array_like, optionalIf given, the points at which
yis sampled.dx: float, optionalSpacing of integration points along axis of
x. Only used whenxis None. Default is 1.axis: int, optionalAxis along which to integrate. Default is the last axis.
Returns
: floatThe estimated integral computed with the composite Simpson's rule.
Notes
For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less.
Examples
from scipy import integrate import numpy as np x = np.arange(0, 10) y = np.arange(0, 10)✓
integrate.simpson(y, x=x)
✗np.float64(40.5)
y = np.power(x, 3)
✓integrate.simpson(y, x=x)
✗np.float64(1640.5)
integrate.quad(lambda x: x**3, 0, 9)[0]
✓1640.25
See also
- cumulative_simpson
cumulative integration using Simpson's 1/3 rule
- cumulative_trapezoid
cumulative integration for sampled data
- dblquad
double integrals
- fixed_quad
fixed-order Gaussian quadrature
- quad
adaptive quadrature using QUADPACK
- romb
integrators for sampled data
- tplquad
triple integrals
Aliases
scipy.integrate.simpson