`trapz`

performs numerical
integration via the trapezoidal method. This method approximates the
integration over an interval by breaking the area down into trapezoids
with more easily computable areas.

For an integration with `N+1`

evenly spaced
points, the approximation is

$$\begin{array}{c}{\displaystyle \underset{a}{\overset{b}{\int}}f\left(x\right)dx\text{\hspace{0.17em}}\text{\hspace{0.17em}}\approx \text{\hspace{0.17em}}\text{\hspace{0.17em}}}\frac{b-a}{2N}{\displaystyle \sum _{n=1}^{N}\left(f\left({x}_{n}\right)+f\left({x}_{n+1}\right)\right)}\\ =\frac{b-a}{2N}\left[f\left({x}_{1}\right)+2f\left({x}_{2}\right)+\mathrm{...}+2f\left({x}_{N}\right)+f\left({x}_{N+1}\right)\right]\text{\hspace{0.17em}}\text{\hspace{0.17em}},\end{array}$$

where the spacing between each point is equal to the scalar
value $$\frac{b-a}{N}$$.

If the spacing between the points is not constant, then the
formula generalizes to

$$\underset{a}{\overset{b}{\int}}f\left(x\right)dx\text{\hspace{0.17em}}\text{\hspace{0.17em}}\approx \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\frac{1}{2}{\displaystyle \sum _{n=1}^{N}\left({x}_{n+1}-{x}_{n}\right)}}\left[f\left({x}_{n}\right)+f\left({x}_{n+1}\right)\right]\text{\hspace{0.17em}},$$

where $$\left({x}_{n+1}-{x}_{n}\right)$$ is
the spacing between each consecutive pair of points.