Q:

How Matlab knows the function that a vector is produced by to calculate cumtrapz?

I have maybe a silly question. 
When I write the following script in Matlab y=[1 4] and then when I use cumtrapz(y) I get [0 2.5]. I know cumtrapz thinks the deltaX=1 in this method.
My question is that how matlab knows the vector 1,4 is created by f(x)=x^2?
one could say it is created by f(x)=3x-2 by just identifying y vector values or many other type of functions. So How matlab knows which function has produced Y vector in order to approximate the integration of the function?
Thanks

A:

MATLAB has no idea where those value came from
a = [1 4 5 9]
s = cumtrapz(a)
s =
0.00000    2.50000    7.00000   14.00000

standard step is 1 so:
h = 1;
s(i) = s(i-1) + h*(a(i-1)+a(i))/2

A:

Matlab does not know that your vector had been created by f(x) = x^2. trapz computes a linear interpolation between each pair of values.
So cumtrapz simply computes a 2 by 2 moving sum and then divides the result by 2.
% Sample data
Y = [1 4 9 16 25];

% Using cumtrapz
Q1  = diff(cumtrapz(Y))
%Q1 = [2.5, 6.5, 12.5, 20.5]

% Using a moving sum
Q2  = conv(Y,ones(2,1),'valid')/2
%Q2 = [2.5, 6.5, 12.5, 20.5]

Graphical example with f(x) = sin(x):

cumtrapz simply applies cumsum the values of the intermediate points.

