%trapezoidal rule
f=input('Enter the function f(x):');
x0=input('Enter the value of initial limit x0=');
xn=input('Enter the value of final limit xn=');
N=input('Enter the total number of subintervals N=');
h=(xn-x0)/N;
area=0;
while(x0<xn)
area=area+(h/2)*(f(x0)+f(x0+h));
x0=x0+h;
end
fprintf('Area by trapezoidal rule=%f\n',area);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: