% matlab code % use trapezoidal method for integration f=inline("cos(10*x)"); x0=-1; x1=1; N=10000; dx=(x1-x0)/N; S=0.0; for i=1:N xx1=x0+dx*i; xx2=x0+dx*(i-1); S=S+0.5*(f(xx1)+f(xx2))*dx; end err=sin(10)/5-S;