Trapezoidal Estimator for the integral
이전 댓글 표시
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')
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!