Contents Previous Next Subchapters Current Chapters-> trapz gaussq quad2d gaussq2d gaussleg quadint int2inf ode4rk expmat ode45rk odepade odestiff Parent Chapters-> Omatrix6 integration trapz Search Tools-> contents reference index search

Trapezoidal Approximation for Integrals
 Syntax `trapz(`y`)` `trapz(`x`, `y`)` `trapz(`y`, `d`)` `trapz(`x`, `y`, `d`)` See Also gaussq , quadint

Description
Computes the trapezoidal approximation for the integral ``` / x(N)           N-1 |                --- |   F(x) dx  ~=  >    [ x   -  x ] [ F(x ) + F(x  ) ] / 2 |                ---     i+1    i       i       i+1 / x(1)           i=1 ```where `N` is the length of the vector x. The arguments x, y and d are integer, real, double-precision, or complex. The return value has the type that results from coercion between the type of x and the type of y. ``` ```If the argument x is not present, the default value ```      x  =  i       i ```is used. The relationship between `F(x)`, `N`, and the arguments y, d, is defined below. ``` trapz(```y```) ```If y is a row vector, `N` is the column dimension of y and ```      y = F(i)       i ```If y is not a row vector, `N` is the row dimension of y and ```      [y    , ... , y  ] = F(i)        i,1          i,n ```where `n` is the column dimension of y. ``` trapz(```x`, `y```) ```If y is a row vector, `N` is the column dimension of y and ```      y = F(x )       i     i ```If y is not a row vector, `N` is the row dimension of y and ```      [y    , ... , y  ] = F(x )        i,1          i,n      i ```where `n` is the column dimension of y. ``` trapz(```y`, `d```) trapz(```x`, `y`, `d```) ```The argument d must be equal to one or two. If d is equal to one, `N` is the row dimension of y and ```      [y    , ... , y  ] = F(x )        i,1          i,n      i ```where `n` is the column dimension of y. If d is equal to two, `N` is the column dimension of y and ```                        T      [y    , ... , y  ]  = F(x )        i,1          i,n       i ```where `n` is the row dimension of y.

Example
The trapezoidal rule is exact for linear functions such as `F(x) = x`. In addition, ```           1      1   /         - = |  x  dx      2   /           0 ```If you enter ```      clear      x = linspace(0d0, 1d0, 5)      y = x      trapz(x, y) ``` O-Matrix will reply ```      0.5 ```
Reference
The arguments x and y each must have more than one element. This distinguishes them from the argument d in the syntax `trapz(`y`, `d`)`