%% Cumulative Integral of Vector with Unit Spacing
% Calculate the cumulative integral of a vector where the spacing between data points is 1.
%
% Create a numeric vector of data.

Y = [1 4 9 16 25];

% Y contains function values for f\left(x\right)=x^2 in the domain [1 5].
%
% Use cumtrapz to integrate the data with unit spacing.

Q = cumtrapz(Y)

% This approximate integration yields a final value of 42. In this case, the exact answer is a little less, 41\frac{1}{3}. The cumtrapz function overestimates the value of the integral because f(x) is concave up.
% Copyright 2012 The MathWorks, Inc.