My assignment was to code a composite simpsons rule where the exact value of the integral of xsin(x) from 0 to 1 is 0.301168678 but I keep getting 0.862149054988026 as the approximation and that is not within my error bound. Am I entering the composite simpsons rule wrong???
if true% EV = sin(1)-cos(1); %exact valuea=0; %starting pointb=1; %endpointf=@(x) x.*sin(x);%d=f(a);for j=0:6n=10^(j);h=(b-a)/n;Err_CS= 1/(36*(n)^4); %error boundCS=(1/3)*(f(a) + 2.*sum(f((a + 2*h):2*h:(b - 2*h)))+4.*sum(f((a + h):2*h:(b -h)) +f(b)))*h; %composite simpsons rulefprintf('%8.2e %14.8e %14.8e %14.8e\n', n, CS, abs(CS-EV), Err_CS)endend