function Ig = gauss_quad(f,n)
% Function to demonstrate Gauss Quadrature

% Set up cell array with integration points and associated weights
gausstable{1}=[0; 2];
gausstable{2}=[-1/sqrt(3), 1/sqrt(3); 1, 1];
gausstable{3}=[-sqrt(3/5), 0, sqrt(3/5); 5/9, 8/9, 5/9];
gausstable{4}=[-0.861136, -0.339981, 0.339981, 0.861136; 0.347855, 0.652145, 0.652145, 0.347855];
gausstable{5}=[-0.90618, -0.538469, 0, 0.538469, 0.90618; 0.236927, 0.478629, 0.568889, 0.478629, 0.236927];
gausstable{6}=[-0.93247, -0.661209, -0.238619, 0.238619, 0.661209, 0.93247; 0.171324, 0.360762, 0.467914, 0.467914, 0.360762, 0.171324];

Ig = 0;
for i=1:n
    Ig = Ig + gausstable{n}(2,i)*f(gausstable{n}(1,i));
end

