MATLAB Function Reference    

Trapezoidal numerical integration



Z = trapz(Y) computes an approximation of the integral of Y via the trapezoidal method (with unit spacing). To compute the integral for spacing other than one, multiply Z by the spacing increment.

If Y is a vector, trapz(Y) is the integral of Y.

If Y is a matrix,trapz(Y) is a row vector with the integral over each column.

If Y is a multidimensional array, trapz(Y) works across the first nonsingleton dimension.

Z = trapz(X,Y) computes the integral of Y with respect to X using trapezoidal integration.

If X is a column vector and Y an array whose first nonsingleton dimension is length(X), trapz(X,Y) operates across this dimension.

Z = trapz(...,dim) integrates across the dimension of Y specified by scalar dim. The length of X, if given, must be the same as size(Y,dim).


The exact value of

is 2.

To approximate this numerically on a uniformly spaced grid, use

Then both



A nonuniformly spaced example is generated by

The result is not as accurate as the uniformly spaced grid. One random sample produced

See Also

cumsum, cumtrapz

  trace treelayout