1
function v = inttrap(x,y)
2
//inttrap Trapezoidal numerical integration.
3
//v = inttrap(x,y) computes the integral of y with respect to x using
4
//trapezoidal integration. x and y must be vectors of the same dimension
5
//v = inttrap(y) computes the trapezoidal integral of y assuming unit
6
//spacing between the data points.
12
v=sum(y(1:$-1) + y(2:$))/2;
14
if size(x,'*')<>size(y,'*') then
15
error('input vectors must have the same dimension');
18
v=(x(2:$)-x(1:$-1))'*(y(1:$-1) + y(2:$))/2;