% Unit 1 (MATLAB Course @ UAM)
% (c) Alexander Knebe
function [antideriv] = antiderivative(f,x)

% how many elements are there? note, length(f) should be length(x)
N = length(f);

% numerical integration gives the anti-derivative at x(2:N)
I = cumsum( (f(1:N-1)+f(2:N))./2 .* diff(x) );

% but we also want the anti-derivative at x(1) which is equal to 0
I = [0, I];

% this is what the function will return
antideriv = I;

end