% I = hw6simpson(f,a,b,n)
%
% Integrate f from a to b by an n-panel composite Simpson rule.

function I = hw6simpson(f,a,b,n)

x = linspace(a,b,2*n+1)';
h = (b-a)/n;
wt = zeros(1,2*n+1);
wt(1:2:end) = h/3;
wt(2:2:end) = 2*h/3;
wt(1) = h/6;
wt(end) = h/6;
I = wt*f(x);