trapz

Numerical integration of discrete data using the trapezoid rule.

Syntax

area=trapz(y)

area=trapz(x,y)

area=trapz(...,dim)

Inputs

x
Values of the domain variable.
When omitted, a vector with unit increments is supplied.
Type: double
Dimension: vector
y
Values of the range variable.
Type: double
Dimension: vector | matrix
dim
The dimension on which to integrate.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar

Outputs

area
The estimated area.
Dimension: scalar | matrix

Example

x = [0:0.05:1]*pi; area = trapz(x,sin(x))
area = 1.99588597

Comments

trapz is appropriate for use with sampled data when the function is not available.