scijit.integrate.simpson¶
- scijit.integrate.simpson(y, x=None, *, dx=1.0, axis=-1)¶
Composite Simpson’s rule over samples.
Takes NO callback of either style: it integrates samples.
- Parameters:
- yarray_like
Samples to integrate, of any rank. An integer or boolean array is promoted to float64 and a complex one stays complex. Copied to a contiguous buffer, so strided views are safe.
- xarray_like or None, optional
Sample positions, which may be non-uniform. Either 1-D along
axis, or ofy’s rank.None(the default) means equal spacingdx.- dxfloat, optional
Spacing used when
xis None. Default 1.0. Keyword-only, from both entry points.- axisint, optional
Axis to integrate along. Default -1, the last axis. Keyword-only.
- Returns:
- totalfloat or ndarray
The integral. A scalar for a 1-D
y, otherwise an array ofy’s rank less one.
- Raises:
- IndexError
axisoutsidey’s rank; or no samples alongaxiswith nox.- ValueError
xneither 1-D nor ofy’s rank;xandyof different lengths alongaxis; no samples alongaxiswith anx.
See also
scipy.integrate.simpsonThe scipy routine this mirrors.
Notes
An odd
Nuses plain composite Simpson. An evenN, where the intervals cannot be paired, uses the Cartwright correction on the last interval;N == 2degenerates to the trapezoid.A zero spacing leaves six divisions singular, and each substitutes 0.0 for the quotient. A repeated sample is not rejected, so this is the path a non-increasing
xreaches.Pure
@njit, no state, so prange-safe.Examples
>>> import numpy as np >>> from numba import njit >>> import scijit.integrate as si >>> x = np.linspace(0.0, np.pi, 65) >>> @njit ... def run(x): ... return si.simpson(np.sin(x), x) >>> run(x) 2.000000064530002