scijit.integrate.trapezoid¶
- scijit.integrate.trapezoid(y, x=None, dx=1.0, axis=-1)¶
Composite trapezoidal rule over samples.
Takes NO callback of either style: it integrates samples, not a function. For a function use
fixed_quad()orquad().- Parameters:
- yarray_like
Samples to integrate, of any rank. A list or a tuple is converted, an integer or boolean array is promoted to float64, and a complex one stays complex.
- xarray_like or None, optional
Sample positions, which may be non-uniform. Either 1-D along
axis, or ofy’s shape.None(the default) means equal spacingdx.- dxfloat, optional
Spacing used when
xis None. Default 1.0.- axisint, optional
Axis to integrate along. Default -1, the last axis.
- Returns:
- totalfloat or ndarray
The integral. A scalar for a 1-D
y, otherwise an array ofy’s rank less one. Fewer than two samples gives 0.0.
- Raises:
- IndexError
axisoutsidey’s rank.- ValueError
The spacings and the sample pairs do not broadcast along
axis, with numpy’s own message;xneither 1-D nor ofy’s shape.
See also
scipy.integrate.trapezoidThe scipy routine this mirrors.
Notes
The number of spacings and the number of sample pairs do not have to agree. The spacings
x[1:] - x[:-1]are multiplied against the pairsy[1:] + y[:-1]and broadcast, so either may be 1 and repeat against the other:len(x) == 2withlen(y) == 4integrates with one repeated spacing, andlen(y) == 1withlen(x) == 3raises.np.trapezoidcomputes the same value inside@njitbut takes noaxisargument.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.trapezoid(np.sin(x), x) >>> run(x) 1.9995983886400375