
function Int = simpson(a,b,n)

%Composite Simpson's rule
% n must be an even number

XI0 = sin(a)+sin(b);
h = (b-a)/n;

XI1 = 0;
XI2 = 0;

for i = 1:n-1;

x = a+i*h;

if(mod(i,2) == 0)
XI2 = XI2+sin(x);
else
XI1 = XI1+sin(x);
end

end

Int = h/3*(XI0+4*XI1+2*XI2);
