% matlab code % use rectangular method for integration f=inline("cos(10*x)"); % define function to integrate x0=-1; %integral lower boundary x1=1; % integral upper boundary N=1000; % number of sub intervals dx=(x1-x0)/N; % witdh of each sub interval % integrate S=0.0; for i=0:N x=x0+dx*i; S=S+f(x)*dx; end % calculate the error for the case f(x)=cos(10 x) err=sin(10)/5-S;