scipy.integrate.simps¶
-
scipy.integrate.simps(y, x=None, dx=1, axis=- 1, even='avg')[source]¶ Integrate y(x) using samples along the given axis and the composite Simpson’s rule. If x is None, spacing of dx is assumed.
If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The parameter ‘even’ controls how this is handled.
- Parameters
- yarray_like
Array to be integrated.
- xarray_like, optional
If given, the points at which y is sampled.
- dxint, optional
Spacing of integration points along axis of x. Only used when x is None. Default is 1.
- axisint, optional
Axis along which to integrate. Default is the last axis.
- evenstr {‘avg’, ‘first’, ‘last’}, optional
- ‘avg’Average two results:1) use the first N-2 intervals with
a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval.
- ‘first’Use Simpson’s rule for the first N-2 intervals with
a trapezoidal rule on the last interval.
- ‘last’Use Simpson’s rule for the last N-2 intervals with a
trapezoidal rule on the first interval.
See also
quadadaptive quadrature using QUADPACK
rombergadaptive Romberg quadrature
quadratureadaptive Gaussian quadrature
fixed_quadfixed-order Gaussian quadrature
dblquaddouble integrals
tplquadtriple integrals
rombintegrators for sampled data
cumtrapzcumulative integration for sampled data
odeODE integrators
odeintODE integrators
Notes
For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less.
Examples
>>> from scipy import integrate >>> x = np.arange(0, 10) >>> y = np.arange(0, 10)
>>> integrate.simps(y, x) 40.5
>>> y = np.power(x, 3) >>> integrate.simps(y, x) 1642.5 >>> integrate.quad(lambda x: x**3, 0, 9)[0] 1640.25
>>> integrate.simps(y, x, even='first') 1644.5
