scijit.integrate.cumulative_simpson¶
- scijit.integrate.cumulative_simpson(y, *, x=None, dx=1.0, axis=-1, initial=None)¶
Running integral by composite Simpson’s 1/3 rule.
Takes NO callback of either style: it integrates samples.
- Parameters:
- yarray_like
Samples to integrate, of any rank. At least one point is required along
axis. Two or fewer fall back tocumulative_trapezoid().- xarray_like or None, optional
Sample positions, strictly increasing along
axis. Either ofy’s shape, or 1-D withy’s length alongaxis.None(the default) means equal spacingdx. Keyword-only.- dxfloat or array_like, optional
Spacing used when
xis None. Either a scalar or an array ofy’s shape with length one alongaxis. Default 1.0. Keyword-only.- axisint, optional
Axis to integrate along. Default -1, the last axis. Keyword-only.
- initialfloat or array_like or None, optional
Value to prepend, and to add to every other element. Either a scalar or an array of
y’s shape with length one alongaxis.None(the default) omits it. Keyword-only. The addition is a common surprise, sinceinitialshifts the whole curve rather than only inserting a point.
- Returns:
- resndarray
Running integral, of
y’s rank. Alongaxisits length isN - 1, the integral evaluated at the samples after the first, orNwheninitialis given.
- Raises:
- ValueError
axisoutsidey’s rank; no samples alongaxis;xneither ofy’s shape nor 1-D alongaxis;xnot strictly increasing;dxorinitialneither a scalar nor ofy’s shape with length one alongaxis.
See also
scipy.integrate.cumulative_simpsonThe scipy routine this mirrors.
Notes
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.cumulative_simpson(np.sin(x), x=x, initial=0.0)[-1] >>> run(x) 2.0000000645300022