quadax.cumulative_simpson
- quadax.cumulative_simpson(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 Simpson’s 1/3 rule.
The integral of the samples at every point is calculated by assuming a quadratic relationship between each point and the two adjacent points.
- Parameters:
y (
array_like) – Values to integrate. Requires at least one point alongaxis. If two or fewer points are provided alongaxis, Simpson’s integration is not possible and the result is calculated withcumulative_trapezoid.x (
array_like, optional) – The coordinate to integrate along. Must have the same shape asyor must be 1D with the same length asyalongaxis.xmust also be strictly increasing alongaxis. Ifxis None (default), integration is performed using spacingdxbetween consecutive elements iny.dx (
scalarorarray_like, optional) – Spacing between elements ofy. Only used ifxis None. Can either be a float, or an array with the same shape asy, but of length one alongaxis. Default is 1.0.axis (
int, optional) – Specifies the axis to integrate along. Default is -1 (last axis).initial (
scalarorarray_like, optional) – If given, insert this value at the beginning of the returned result, and add it to the rest of the result. Default is None, which means no value atx[0]is returned andreshas one element less thanyalong the axis of integration. Can either be a float, or an array with the same shape asy, but of length one alongaxis.
- Returns:
res (
ndarray) – The result of cumulative integration ofyalongaxis. Ifinitialis None, the shape is such that the axis of integration has one less value thany. Ifinitialis given, the shape is equal to that ofy.
Notes
For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less.