bundles / scipy latest / scipy / integrate / _quadrature / cumulative_trapezoid
function
scipy.integrate._quadrature:cumulative_trapezoid
source: build-install/usr/lib/python3.14/site-packages/scipy/integrate/_quadrature.py:261
Signature
def cumulative_trapezoid(y, x = None, dx = 1.0, axis = -1, initial = None)Summary
Cumulatively integrate y(x) using the composite trapezoidal rule.
Parameters
y: array_likeValues to integrate.
x: array_like, optionalThe coordinate to integrate along. If None (default), use spacing
dxbetween consecutive elements iny.dx: float, optionalSpacing between elements of
y. Only used ifxis None.axis: int, optionalSpecifies the axis to cumulate. Default is -1 (last axis).
initial: scalar, optionalIf given, insert this value at the beginning of the returned result. 0 or None are the only values accepted. Default is None, which means res has one element less than
yalong the axis of integration.
Returns
res: ndarrayThe result of cumulative integration of
yalongaxis. 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.
Examples
from scipy import integrate import numpy as np import matplotlib.pyplot as plt✓
x = np.linspace(-2, 2, num=20) y = x y_int = integrate.cumulative_trapezoid(y, x, initial=0)✓
plt.plot(x, y_int, 'ro', x, y[0] + 0.5 * x**2, 'b-')
✗[<matplotlib.lines.Line2D object at 0x7f3f68269940>, <matplotlib.lines.Line2D object at 0x7f3f68268440>]
plt.show()
✓
See also
- cumulative_simpson
cumulative integration using Simpson's 1/3 rule
- dblquad
double integrals
- fixed_quad
fixed-order Gaussian quadrature
- numpy.cumprod
- numpy.cumsum
- quad
adaptive quadrature using QUADPACK
- romb
integrators for sampled data
- tplquad
triple integrals
Aliases
scipy.integrate.cumulative_trapezoid