In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
import scipy.integrate
See:
Example:
$$I = \int_{0}^{3} x^2 dx = \frac{1}{3} 3^3 = 9$$
In [ ]:
f = lambda x: np.power(x, 2)
result = scipy.integrate.quad(f, 0, 3)
result
The return value is a tuple, with the first element holding the estimated value of the integral and the second element holding an upper bound on the error.
In [ ]:
x = np.linspace(0., 3., 100)
y = f(x)
In [ ]:
plt.plot(x, y);
In case of arbitrary spaced samples, the two functions trapz and simps are available.
In [ ]:
result = scipy.integrate.simps(y, x)
result
In [ ]:
result = scipy.integrate.trapz(y, x)
result