% INTEGRAL Evaluate numerical integral of f(x)
%   Computes the integral of the function f(x) given the data in vectors x
%   and f_x.
%

function y = integral(x, f_x)
    
	% Use extended Simpson's rule for the numerical integration
	%     N = length(x);
	%     y = 3/8*(f_x(1)+f_x(N)) + 7/6*(f_x(2)+f_x(N-1)) + 23/24*(f_x(3)+f_x(N-2));
	%     dx = x(2) - x(1);
	%     y = dx*(y + sum(f_x(4:(N-3))));
	%     %y = (y + sum(f_x(4:(N-3))));

	x = x(:)';
	f_x = f_x(:)';

	% Use Mastering MATLAB numerical integration
	% Download at http://www.eece.maine.edu/mm/MM6/tbx.html
	s = mmintgrl(x, f_x);
	y = s(end);
    
return

