|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.
Y is a vector,
trapz(Y) is the integral of
Y is a matrix,
trapz(Y) is a row vector with the integral over each column.
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.
X is a column vector and
Y an array whose first nonsingleton dimension is
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
The exact value of
To approximate this numerically on a uniformly spaced grid, use
A nonuniformly spaced example is generated by
The result is not as accurate as the uniformly spaced grid. One random sample produced