# 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?

21 vues (au cours des 30 derniers jours)
Shamila le 4 Avr 2024
Commenté : Shamila le 8 Avr 2024
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 :-');
for h = 0.1 :-
disp(['Trapezoidal Rule: ',num2str(trph1), ', Error: ', num2str(trperh1)]);
Trapezoidal Rule: 0.88601, Error: 0.032634
disp(['Simpson''s 1/3 Rule: ', num2str(simp1h1), ', Error: ', num2str(simp1erh1)]);
Simpson's 1/3 Rule: 0.88629, Error: 5.2332e-05
disp(['Simpson''s 3/8 Rule: ', num2str(simp2h1), ', Error: ', num2str(simp2erh1)]);
Simpson's 3/8 Rule: 0.88629, Error: 0.00011653
% disp('for h = 0.01 :-');
disp(['Trapezoidal Rule: ', num2str(trph2), ', Error: ', num2str(trperh2)]);
Trapezoidal Rule: 0.88629, Error: 0.00045186
disp(['Simpson''s 1/3 Rule: ', num2str(simp1h2), ', Error: ', num2str(simp1erh2)]);
Simpson's 1/3 Rule: 0.88629, Error: 1.0133e-08
disp(['Simpson''s 3/8 Rule: ', num2str(simp2h2), ', Error: ', num2str(simp2erh2)]);
Simpson's 3/8 Rule: 0.88629, Error: 2.2795e-08
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### 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.
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Shamila le 8 Avr 2024
i heard that 3/8 is more accurate than 1/3

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by