Simpson's rule help
4 views (last 30 days)
Show older comments
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));
0 Comments
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!