Calculates the area of a series using the trapezoidal rule.

TRAPZ(series)

series |
- |
An interval or XY series, the input. |

TRAPZ(xseries, yseries)

xseries |
- |
A series, the X values. |

yseries |
- |
A series, the Y values. |

A scalar, the total area.

trapz(gsin(1000, 1/1000, 0.5))

returns 0.636618. For a sinusoid, the analytic computation is as follows:

With f = 0.5 and t = 1:

y1 = gnorm(1000, .001);

a1 = cumtrapz(y1);

a2 = trapz(y1);

Series a1 contains the cumulative area of y1 and scalar a2 contains the value of the total area of y1. Note that a1[end] == a2, the last point of the cumulative area equals the total area.

The trapezoidal rule fits a line between two data points and calculates the area under the resulting trapezoid such that:

where

See AREA to compute the total area using Simpson’s rule.

See CUMTRAPZ to compute the cumulative area using the trapezoidal rule.