trapezoid#
- class brainunit.math.trapezoid(y, x=None, dx=1.0, axis=-1)#
Integrate along the given axis using the composite trapezoidal rule.
The resulting unit is
y.unit * x.unit(ory.unit * dx.unitwhenxis not given), as expected for an integral ofyoverx.- Parameters:
y (saiunit.Quantity |
Array|ndarray|number|bool) – Input array to integrate.x (saiunit.Quantity |
Array|ndarray|number|bool|None) – The sample points corresponding to the y values. IfNone(default), the sample points are assumed to be evenly spaceddxapart.dx (saiunit.Quantity |
Array|ndarray|number|bool|float) – The spacing between sample points when x isNone. Default 1.axis (
int) – The axis along which to integrate. Default -1.
- Returns:
out – Definite integral as approximated by the trapezoidal rule, with unit
y.unit * x.unit(ory.unit * dx.unit).- Return type:
saiunit.Quantity |
Array|ndarray|number|bool
Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> y = jnp.array([1.0, 2.0, 3.0]) * u.mV >>> x = jnp.array([0.0, 1.0, 2.0]) * u.second >>> u.math.trapezoid(y, x) # unit is mV * s