MATLAB Function Reference Previous page   Next Page
trapz

Trapezoidal numerical integration

Syntax

Description

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. Input Y can be complex.

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. Inputs X and Y can be complex.

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).

Examples

Example 1

The exact value of

is 2.

To approximate this numerically on a uniformly spaced grid, use

Then both

and

produce

Example 2

A nonuniformly spaced example is generated by

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

Example 3

This example uses two complex inputs:

See Also

cumsum, cumtrapz


Previous page  trace treelayout Next page

© 1994-2005 The MathWorks, Inc.