[SciPy-Dev] Code review for trapz update
Eric Moore
ewm at redtetrahedron.org
Tue Mar 10 12:13:28 EDT 2015
> Trapz finds the area under a one-to-one association of y values with x
> values. If y(x) > 0, then the area bounded by [a, b] between y(x) and
> x=0 should always be positive.
You could write a trapz that does that, however np.trapz finds the integral
from a to b of y using the sampled data you provide. The "from" in there
is important. Since we are integrating samples, the a and b are
essentially the first and last points of the x input. Since a is x[0] and b
is x[-1], the x array is defining the path along which to integrate.
> The core property you have referenced
> above is the very property that should be used in order to achieve the
> equivalence with integrating along a negative path. Maintaining this
> separation preserves the equivalence of
> np.trapz(y,x) == np.trapz(y[::-1], x[::-1]), which I believe is an
> equivalence that should hold true.
>
This equivalence is false. For instance both of these results are
correct. Would they still be with your changes?
In [46]: x = np.exp(1j*np.pi*np.linspace(0,1,100))
In [47]: z = 1/x
In [48]: np.trapz(z, x)
Out[48]: (1.3244509217643717e-18+3.1410654163086975j)
In [49]: np.trapz(z[::-1], x[::-1])
Out[49]: (-1.3244509217643594e-18-3.1410654163086971j)
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150310/650fc67a/attachment.html>
More information about the SciPy-Dev
mailing list