MATLAB: Integral of f by Milne’s method

milne's method

I need help.
I want to calculate the integral of f, by Milne's method, using the average of f on each subdivision.
let N be a multiple of 4, and be a subdivsion of
and
I knew F it is a vector of size N
Is this code correct:
%% My code
Milne=0;
for i = 1 : 4 : (N-4)
Milne = Milne + 7*F(i)+32*F(i+1)+12*F(i+2)+32*F(i+3)+7*F(i+4);
end;
Milne=2/45*Milne
err=abs(M-(exp(b)-1))
For f (x) = exp (x) on [0, 3] and for N = 120, I found the error equal to 0.25. However, when I use the Milne method (code below) I find for N = 12 the error is very small of order .
M=0;
for i =1 : 4 : (N-3)
M = M + 7*f(a+(i-1)*h)+32*f(a+i*h) +12*f(a+(i+1)*h) +32*f(a+(i+2)*h) +7*f(a+(i+3)*h);
end;
M = 2*h/45*M
err=abs(M-(exp(b)-1))

Best Answer

You are using what appears to be a closed form Newton Cotes rule, commonly known as Booles rule.
On that page, you would see a rule named for MIlne, but it is an open rule, and very different from what you used. So possibly someone gave you the wrong name. But if you really need to use some other rule, then what you did is incorrect.
Here is Milne's method:
Anyway, if you look at what you did do, even if this is supposed to be an implementation of Boole's rule, you still have a mistake. Read the page I gave you a link for. Do you see the result is multiplied by h?
On ANY integration rule, you will find that term in there, the multipler by h. This gets to the idea that an integral computes an AREA. Area is defined simply as height*width. If you do not multiply by the spacing, then you implicitly assume the stride in those points is 1.