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 along axis. If two or fewer points are provided along axis, Simpson’s integration is not possible and the result is calculated with cumulative_trapezoid.

  • x (array_like, optional) – The coordinate to integrate along. Must have the same shape as y or must be 1D with the same length as y along axis. x must also be strictly increasing along axis. If x is None (default), integration is performed using spacing dx between consecutive elements in y.

  • dx (scalar or array_like, optional) – Spacing between elements of y. Only used if x is None. Can either be a float, or an array with the same shape as y, but of length one along axis. Default is 1.0.

  • axis (int, optional) – Specifies the axis to integrate along. Default is -1 (last axis).

  • initial (scalar or array_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 at x[0] is returned and res has one element less than y along the axis of integration. Can either be a float, or an array with the same shape as y, but of length one along axis.

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.

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.