Gaussian quadrature using MATLAB

Determine the value of the following integral.

The Gaussian quadrature is done using the function planar(nx), where 3nx7 and one needs to use the global xoc and woc command. Planar(nx) computes the quadrature points and weights shown elsewhere (link). Then one uses the following commands.

global xoc woc
planar(nx)
area = 0;
for i=1:nx
x=xoc(i);
f=exp(-x)*sin(x);
area = area + f*woc(i);
end
area

The results are shown in the Table. Results obtained with only 7 points are as accurate as those obtained with the trapezoid rule and 201+401= 602 points and extrapolation (link).

Table. Integrals Calculated with Quassian Quadrature
nx area
3 0.24545083808398
4 0.24609643062368
5 0.24583487736505
6 0.24583700444292
7 0.24583700700700

Take Home Message: Clearly the Gaussian quadrature is very accurate.