trapezoid

Contents

trapezoid#

class saiunit.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 (or y.unit * dx.unit when x is not given), as expected for an integral of y over x.

Parameters:
  • y (Union[saiunit.Quantity, Array, ndarray, number, bool]) – Input array to integrate.

  • x (Union[Array, ndarray, number, bool, saiunit.Quantity, None]) – The sample points corresponding to the y values. If None (default), the sample points are assumed to be evenly spaced dx apart.

  • dx (Union[saiunit.Quantity, Array, ndarray, number, bool, float]) – The spacing between sample points when x is None. 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 (or y.unit * dx.unit).

Return type:

Union[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