function [x,w,varargout] = hermitequad(n)
%
% Generate nodes and weights for
% Hermite-Gauss quadrature.
% Note that x is a column vector
% and w is a row vector.
%
u = sqrt((1:n-1)/2); % upper diagonal of J
[V,Lambda] = eig(diag(u,1)+diag(u,-1));
[xx,i] = sort(diag(Lambda));
Vtop = V(1,:);
Vtop = Vtop(i);
ww = sqrt(pi)*Vtop.^2;
%
i = find(ww>0);
w = ww(i);
x = xx(i);
nw = length(i);
if nw < n
   fprintf('\n *** Of %g Hermite-Gauss weights, only %g are positive.\n\n',...
      n,nw)
end
if nargout==3
    varargout{1} = nw;
end