quadax.cumulative_trapezoid
- quadax.cumulative_trapezoid(y: Array | ndarray | bool | number | bool | int | float | complex, *, x: None | Array | ndarray | bool | number | bool | int | float | complex = None, dx: Array | ndarray | bool | number | bool | int | float | complex = 1.0, axis: int = -1, initial: Array | ndarray | bool | number | bool | int | float | complex | None = None) ArraySource
Cumulatively integrate y(x) using the composite trapezoidal rule.
- Parameters:
y (array_like) – Values to integrate.
x (array_like, optional) – The coordinate to integrate along. If None (default), use spacing dx between consecutive elements in y.
dx (float, optional) – Spacing between elements of y. Only used if x is None.
axis (int, optional) – Specifies the axis to cumulate. Default is -1 (last axis).
initial (scalar, optional) – If given, insert this value at the beginning of the returned result. Typically this value should be 0. Default is None, which means no value at
x[0]is returned and res has one element less than y along the axis of integration.
- Returns:
res (ndarray) – The result of cumulative integration of y along axis. If initial is None, the shape is such that the axis of integration has one less value than y. If initial is given, the shape is equal to that of y.
Examples
>>> from quadax import cumulative_trapezoid >>> import jax.numpy as jnp >>> import matplotlib.pyplot as plt
>>> x = jnp.linspace(-2, 2, num=20) >>> y = x >>> y_int = cumulative_trapezoid(y, x, initial=0) >>> plt.plot(x, y_int, 'ro', x, y[0] + 0.5 * x**2, 'b-') >>> plt.show()