%% Integrate Vector of Data with Nonunit Spacing
% Calculate the integral of a vector where the spacing between data points is uniform, but not equal to 1.
%
% Create a domain vector.

X = 0:pi/100:pi;

%
% Calculate the sine of X.

Y = sin(X);

%
% Integrate Y using trapz.

Q = trapz(X,Y)

% When the spacing between points is constant, but not equal to 1, an alternative to creating a vector for X is to specify the scalar spacing value. In that case, trapz(pi/100,Y) is the same as pi/100*trapz(Y).
% Copyright 2012 The MathWorks, Inc.