% matlab code (you have to also use lgwt.m) % use Gaussian Quadrature method for integration (look into numerical reciepes in C for more details) f=inline("cos(10*x)"); x0=-1; x1=1; N=4; dx=(x1-x0)/N; [x,w]=lgwt(N,x0,x1); % get the weights and sampling points for Gaussain quadratures S=0.0; for i=1:N S=S+w(i)*f(x(i)); end err=sin(10)/5-S;