Azzera filtri
Azzera filtri

integral of f by Milne's method

3 visualizzazioni (ultimi 30 giorni)
B.E.
B.E. il 31 Ott 2020
Commentato: B.E. il 31 Ott 2020
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))
  2 Commenti
John D'Errico
John D'Errico il 31 Ott 2020
Modificato: John D'Errico il 31 Ott 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 {}.
B.E.
B.E. il 31 Ott 2020
yes i used parentheses in my code, I corrected the code written above.

Accedi per commentare.

Risposta accettata

John D'Errico
John D'Errico il 31 Ott 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.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by