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