function [nd,wd]=qnodes(n,type)
% qnodes - Gaussian quadrature nodes and weights over [-1,+1]
%
% [x,w]=qnodes(n,type)
%
% Input:  n - number of nodes
%         type - method
%               'c':  Chebyshev
%               'h':  Hermite
%               'a':  Laguerre
%               'l':  Legendre
%
% Output: x - nodes
%         w - weights
%
% (c) 2012 by Marco Maffezzoli. Ver. 3.0.1
%

if type=='c' % Chebyshev
    wd=ones(n,1)*pi/n;
    nd=-cos(((1:n)'-1/2)*(pi/n));
else
    m=(1:n-1)';
    switch type
        case 'h' % Hermite
            z=realsqrt(m/2);
            J=diag(z,1)+diag(z,-1);
            temp=realsqrt(pi);
        case 'a' % Laguerre
            z=[2.*m-1;2*n-1];
            J=diag(z)+diag(m,1)+diag(m,-1);
            temp=1;
        case 'l' % Legendre
            z=m./realsqrt(4*m.^2-1);
            J=diag(z,1)+diag(z,-1);
            temp=2;
    end
    [v,d]=eig(J);
    [nd,ind]=sort(diag(d));
    v=v(:,ind);
    wd=temp*v(1,:)'.^2;
end

end