if number of steps is not multiple of 3 how to do simpsons 3/8 rule? why im getting more error in simpsons 3/8 rule than in simpsons 1/3 rule?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1659686/image.png)
Here, as dx is 0.1 and 0.01, n is not multiple of 3 for 3/8 rule.tried by making n same for all 3 rules. but error in 3/8 > error in 1/3. how to solve this issue?
% Define the function
f = @(x) 2-x+log(x);
% Define integration limits
a = 1;
b = 2;
% Exact integral value
og = integral(f,a,b);
%Step sizes
h1 =(b-a)/12;
h2 =(b-a)/102;
% Trapezoidal Rule
trph1 = h1/2 * (f(a) + f(b) + 2*sum(f(a+h1:h1:b-h1)));
trph2 = h2/2 * (f(a) + f(b) + 2*sum(f(a+h2:h2:b-h2)));
trperh1 = abs((trph1-og) / og) * 100;
trperh2 = abs((trph2-og) / og) * 100;
% Simpson's 1/3 Rule
simp1h1 = h1/3 * (f(a) + f(b) + 2*sum(f(a+2*h1:2*h1:b-2*h1)) + 4*sum(f(a+h1:2*h1:b-h1)));
simp1h2 = h2/3 * (f(a) + f(b) + 2*sum(f(a+2*h2:2*h2:b-2*h2)) + 4*sum(f(a+h2:2*h2:b-h2)));
simp1erh1 = abs((simp1h1 - og) / og) * 100;
simp1erh2 = abs((simp1h2 - og) / og) * 100;
% Simpson's 3/8 Rule
simp2h1 = (3*h1/8) * (f(a) +f(b) + 3*sum(f(a+h1:3*h1:b-2*h1)) + 3*sum(f(a+2*h1:3*h1:b-h1)) + 2*sum(f(a+3*h1:3*h1:b-3*h1)));
simp2h2 = (3*h2/8) * (f(a) +f(b) + 3*sum(f(a+h2:3*h2:b-2*h2)) + 3*sum(f(a+2*h2:3*h2:b-h2)) + 2*sum(f(a+3*h2:3*h2:b-3*h2)));
simp2erh1 = abs((simp2h1 - og) / og) * 100;
simp2erh2 = abs((simp2h2 - og) / og) * 100;
% Display results
disp('for h = 0.1 :-');
disp(['Trapezoidal Rule: ',num2str(trph1), ', Error: ', num2str(trperh1)]);
disp(['Simpson''s 1/3 Rule: ', num2str(simp1h1), ', Error: ', num2str(simp1erh1)]);
disp(['Simpson''s 3/8 Rule: ', num2str(simp2h1), ', Error: ', num2str(simp2erh1)]);
% disp('for h = 0.01 :-');
disp(['Trapezoidal Rule: ', num2str(trph2), ', Error: ', num2str(trperh2)]);
disp(['Simpson''s 1/3 Rule: ', num2str(simp1h2), ', Error: ', num2str(simp1erh2)]);
disp(['Simpson''s 3/8 Rule: ', num2str(simp2h2), ', Error: ', num2str(simp2erh2)]);
0 commentaires
Réponse acceptée
Torsten
le 4 Avr 2024
Déplacé(e) : Torsten
le 4 Avr 2024
if number of steps is not multiple of 3 how to do simpsons 3/8 rule?
The 1/3 rule can be used for the remaining subintervals without changing the order of the error term (conversely, the 3/8 rule can be used with a composite 1/3 rule for odd-numbered subintervals).
why im getting more error in simpsons 3/8 rule than in simpsons 1/3 rule?
Why do you think this should not be the case ? Both composite rules are of the same order as far as I know.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!