{ } Raw JSON

bundles / scipy latest / scipy / integrate / _quadrature / cumulative_trapezoid

function

scipy.integrate._quadrature:cumulative_trapezoid

source: /scipy/integrate/_quadrature.py :255

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_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. 0 or None are the only values accepted. Default is None, which means 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.

Notes

Array API Standard Support

cumulative_trapezoid has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ✅                   
PyTorch               ✅                     ✅                   
JAX                   ✅                     ✅                   
Dask                  ✅                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

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-')
plt.show()
fig-f443cbc4b61b6e6b.png

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

Referenced by