function S = gauss234(a,b,n)
% Gaussian Quadrature for n = 2,3,4 pts
% User inputs function f and interval [a,b]
f = @(x) x.^5 + 5*x.^3 + 2*x + 3;
if (n == 2)
    gr = [-1/sqrt(3),1/sqrt(3)];
    wt = [1,1];
elseif (n == 3)
    gr = [-sqrt(3/5),0,sqrt(3/5)];
    wt = [5/9,8/9,5/9];
elseif (n == 4)
    tr = (2/7)*sqrt(6/5);
    tw = sqrt(30)/36;
    gr = [-sqrt((3/7)+tr),-sqrt((3/7)-tr),...
          sqrt((3/7)-tr),sqrt((3/7)+tr)];
    wt = [0.5-tw,0.5+tw,0.5+tw,0.5-tw];
else 
    S = fprintf('Selected n inappropriate');
    return
end
gx = ((b-a)*gr + (b+a))/2;
wx = wt*(b-a)/2;
S = sum(wx.*f(gx));
end

