function comp_trapez n=90; % the number of nodes. a=0; b=10; % the interval [a,b] h=(b-a)/n; % the step size %%%%% THE Composite Trapezoidal RULE %%%%% %%%%% TO CALCULATE \int_{a}^{b} f(x)dx %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% S=f(a); for i=1:1:n-1 S=S+2*f(a+i*h); end; S=S+f(b); S=(h/2)*S; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % compare to the exact integral S+(cos(b)-cos(a)) function y=f(x); y=sin(x);