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

X = 0:pi/5:pi;

%
% Calculate the sine of X.

Y = sin(X');

%
% Cumulatively integrate Y using cumtrapz. 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, cumtrapz(pi/5,Y) is the same as pi/5*cumtrapz(Y).

Q = cumtrapz(X,Y)

%
%
% Copyright 2012 The MathWorks, Inc.