Simpson's rule help

12 ビュー (過去 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 Center および File ExchangeNumerical 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