%% Integrate Vector of Data with Unit Spacing
% Calculate the 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(x) = x^2 in the domain [1, 5].
%
% Use trapz to integrate the data with unit spacing.

Q = trapz(Y)

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