% matlab code % use Simpson's method for integration f=inline("cos(10*x)"); x0=-1; x1=1; N=1000; dx=(x1-x0)/N; S=0.0; for i=1:N/2 xx1=x0+dx*(2*i-2); xx2=x0+dx*(2*i-1); xx3=x0+dx*(2*i); S=S+1/3*(f(xx1)+4*f(xx2)+f(xx3))*dx; end err=sin(10)/5-S;