Numerical integration

Trapezoid rule with interpolated boundaries

PyAstronomy.pyaC.ibtrapz(x, y, x0, x1, iaout=False, jne=False)

Use the trapezoid rule to integrate and interpolate boundary values.

Can be used for integration on tabled data, where the integration boundaries are not located on the grid. The values to use at the boundaries are determined using linear interpolation.


The data.

x0, x1float

The integration boundaries.

iaoutboolean, optional

If True, the arrays used internally for integration are also returned. The default is False.

jneboolean, optional

If True, a leave-one-out error estimate is produced for the value of the integral. In that case, the actual integral, the error estimate (standard deviation), and the individual jacknife estimates are returned.


The value of the resulting integral.

xi, yiarrays, optional

Internally used arrays for integration including the values derived at the boundaries. Only returned if iaout is set to True.


from __future__ import print_function
from PyAstronomy.pyaC import mtools
import numpy as np

x = np.arange(-2., 2.01, 0.1)
y = x**3 + 1.7

x0 = -1.375
x1 = +1.943

# Analytical value of integral
analyt = 0.25*(x1**4 - x0**4) + 1.7*(x1-x0)

print("Analytical value: ", analyt)
print("ibtrapz: ", mtools.ibtrapz(x, y, x0, x1))