Python | Scipy integrate.cumtrapz() method
Last Updated :
23 Jan, 2020
With the help of scipy.integrate.cumtrapz()
method, we can get the cumulative integrated value of y(x) using composite trapezoidal rule by using scipy.integrate.cumtrapz()
method.
Syntax : scipy.integrate.cumtrapz()
Return : Return the cumulative integrated value of y(x).
Example #1 :
In this example we can see that by using scipy.integrate.cumtrapz()
method, we are able to get the cumulative integration of y(x) using trapezoidal rule by using this method.
import numpy as np
from scipy import integrate
x = np.arange( 0 , 10 )
y = np.arange( 0 , 10 )
gfg = integrate.cumtrapz(y, x)
print (gfg)
|
Output :
[0.5 2. 4.5 8. 12.5 18. 24.5 32. 40.5]
Example #2 :
import numpy as np
from scipy import integrate
x = np.arange( 0 , 10 )
y = np.power(x, 2 )
gfg = integrate.cumtrapz(y, x)
print (gfg)
|
Output :
[0.5 3. 9.5 22. 42.5 73. 115.5 172. 244.5]
Share your thoughts in the comments
Please Login to comment...