function  retval = trap(x,y)
% usage: retval = trap(x,y)
% description: Returns trapezoidal method applied
% on interval [x(1),x(length(x))] using nodes from
% x and function values from y=f(x).
n = length(y);
if (length(x) ~= n)
  error('Mismatch of arguments');
end
retval = sum((y(1:n-1)+y(2:n))/2.*(x(2:n)-x(1:n-1)));
