integral of f by Milne's method
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
John D'Errico
2020-10-31
编辑:John D'Errico
2020-10-31
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 {}.
采纳的回答
John D'Errico
2020-10-31
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Beamforming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!