Simpson's rule help

4 Ansichten (letzte 30 Tage)
Christopher
Christopher am 6 Apr. 2016
Bearbeitet: Christopher am 6 Apr. 2016
Stated below I have two versions of Simpson's (3/8) rule . The correct value for the rule in this case is 1.4161. How ever only the second version of the rule yields the correct result. Can anyone explain to me the difference or what is wrong with the first version of the rule?
The second rule from what I can see should be the same as the first as it sets all the functions between Y(1) and Y(end) to 3*sum(Y(2:end-1)) and then subtracts sum(Y(4:3:end-2)) to produce what would have been 2*sum(Y(4:3:end-1) has seen in the first version of the rule.
Set lower and upper limits
Lowerlim = 0;
Upperlim = 2;
%Set number of steps
Nsteps = 1000;
%Define Delta X
Deltax = (Upperlim-Lowerlim)/Nsteps;
%Define X and Y variables
X = Lowerlim:Deltax:Upperlim;
Y = sin(X);
Simps2 = ((3*Deltax)/8)*(Y(1)+3*sum(Y(2:3:end-1))+3*sum(Y(3:3:end-1))+2*sum(Y(4:3:end-1)+Y(end)));
Simps2 = (3*Deltax)/8*(Y(1)+3*sum(Y(2:end-1))-sum(Y(4:3:end-2))+Y(end));

Antworten (1)

Torsten
Torsten am 6 Apr. 2016
Bearbeitet: Torsten am 6 Apr. 2016
Try Nsteps=999 (N must be a multiple of 3).
Best wishes
Torsten.
  1 Kommentar
Christopher
Christopher am 6 Apr. 2016
Thanks for the answer Torsten. I should have probably mentioned I'm using Simpsons "second" (3/8) rule setting the number of steps to 999 gives me a value of 1.8708 not 1.4161

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by