Simpson's rule help

조회 수: 4 (최근 30일)
Christopher
Christopher 2016년 4월 6일
편집: Christopher 2016년 4월 6일
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));

답변 (1개)

Torsten
Torsten 2016년 4월 6일
편집: Torsten 2016년 4월 6일
Try Nsteps=999 (N must be a multiple of 3).
Best wishes
Torsten.
  댓글 수: 1
Christopher
Christopher 2016년 4월 6일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by