>>> help(integrate) Methods for Integrating Functions given function object.
quad -- General purpose integration. dblquad -- General purpose double integration. tplquad -- General purpose triple integration. fixed_quad -- Integrate func(x) using Gaussian quadrature of order n. quadrature -- Integrate with given tolerance using Gaussian quadrature. romberg -- Integrate func using Romberg integration.
Methods for Integrating Functions given fixed samples.
trapz -- Use trapezoidal rule to compute integral from samples. cumtrapz -- Use trapezoidal rule to cumulatively compute integral. simps -- Use Simpson's rule to compute integral from samples. romb -- Use Romberg Integration to compute integral from (2**k + 1) evenly-spaced samples. See the special module's orthogonal polynomials (special) for Gaussian quadrature roots and weights for other weighting factors and regions.
Interface to numerical integrators of ODE systems.
odeint -- General integration of ordinary differential equations. ode -- Integrate ODE using VODE and ZVODE routines.
General integration (quad)
$$ I = \int_0^{4.5}f(x)dx $$
1 2 3 4
deff(x,y): pass # 可以用lambda函数补充其他参数。 result = integrate.quad(lambda x:f(x,19), 0, 4.5)
带参数积分
$$ I(a,b)=\int_0^1ax^2+bxdx $$
1 2 3 4 5 6 7 8 9
from scipy.integrate import quad def integrand(x, a, b): return a*x**2 + bx
a = 2 b = 1 I = quad(integrand, 0, 1, args=(a,b)) I (1.6666666666666667, 1.8503717077085944e-14)