Trapezoidal Estimator for the integral
Afficher commentaires plus anciens
I tried here to find a trapezoidal estimate of an area between different intervals(Delta_x); however, errors found are not correct numbers according to others solutions(I checked). I couldnt find my mistake.
Could you look at it?
clc; clear;
f1=@(x) 1+sin(pi*x/100)-sin(pi*x/25);
Area1_actual=integral(f1,0,100);
%%Trapezoidal estimator
c=0;
for Delta_x=[10 5 2.5 1 1/2.5 1/5 1/10];
x = 0:Delta_x:100;
for j=1:(length(x)-1)
Trap_area = Delta_x/2*(f1(x(j))+f1(x(j+1)));
mat_traparea_Tr(j,1) = Trap_area;
end
c=c+1;
Total_area_Tr(c,1) = sum(mat_traparea_Tr);
Error_Tr(c,1) = Total_area_Tr(c,1)-Area1_actual;
end
Delta_x=[10 5 2.5 1 1/2.5 1/5 1/10];
plot(Delta_x,abs(Error_Tr),'b-'); title('Trapezoidal estimator')
xlabel('DeltaX'), ylabel('Errors'); set(gca, 'XDir','reverse')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Analysis of Variance and Covariance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!