integral of f by Milne's method
2 views (last 30 days)
Show older comments
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 ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398674/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398664/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398669/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398674/image.png)
and ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398679/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398679/image.png)
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
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/398684/image.png)
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))
2 Comments
John D'Errico
on 31 Oct 2020
Edited: John D'Errico
on 31 Oct 2020
Is it correct? No.
For some reason, you seem to think you can use any kind of parens to index a vector, (), {}, or even no parens at all.
You will index a vector using (), unless the vector is a cell vector, then you use {}.
Accepted Answer
John D'Errico
on 31 Oct 2020
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.
More Answers (0)
See Also
Categories
Find more on Beamforming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!