Question: Composite Simpson's 3/8 Rule

I am trying to create a procedure that can solve integrals using the Composite Simpson's 3/8 rule. However when I test my procedure against maple's ApproximateInt I am getting the wrong results.

Here is my attempt:

restart;


f:= x -> exp(x)*sin(4*x); # function I am using

simp := proc(a, b, n)
  local h, sum, i, single:
  h := (b-a)/n:
  sum := 0:
  single := (3*h/8) * (f(a) + f(b)): # this is the end points
    for i from a+h by h to b-h do
       sum := sum + (3*h/8) * (3*f(i)):
    end do:
print(evalf(sum + single));
end proc:


simp(0,1,12);
                                                                                0.6224486445
evalf(Student:-Calculus1:-ApproximateInt(f(x), 0..1, method = simpson[3/8], partition=12));

                                                                                0.5323516717

 

As you can see my answer is not very close to the answer given by Maple. I am not sure why my procedure simp is wrong.

Please Wait...