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 of y’s rank. None (the default) means equal spacing dx.

dxfloat, optional

Spacing used when x is 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 of y’s rank less one.

Raises:
IndexError

axis outside y’s rank; or no samples along axis with no x.

ValueError

x neither 1-D nor of y’s rank; x and y of different lengths along axis; no samples along axis with an x.

See also

scipy.integrate.simpson

The scipy routine this mirrors.

Notes

An odd N uses plain composite Simpson. An even N, where the intervals cannot be paired, uses the Cartwright correction on the last interval; N == 2 degenerates 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 x reaches.

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