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 to cumulative_trapezoid().

xarray_like or None, optional

Sample positions, strictly increasing along axis. Either of y’s shape, or 1-D with y’s length along axis. None (the default) means equal spacing dx. Keyword-only.

dxfloat or array_like, optional

Spacing used when x is None. Either a scalar or an array of y’s shape with length one along axis. 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 along axis. None (the default) omits it. Keyword-only. The addition is a common surprise, since initial shifts the whole curve rather than only inserting a point.

Returns:
resndarray

Running integral, of y’s rank. Along axis its length is N - 1, the integral evaluated at the samples after the first, or N when initial is given.

Raises:
ValueError

axis outside y’s rank; no samples along axis; x neither of y’s shape nor 1-D along axis; x not strictly increasing; dx or initial neither a scalar nor of y’s shape with length one along axis.

See also

scipy.integrate.cumulative_simpson

The 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