From: Matt Fig on
Is this what you are after? This is almost a direct translation from Numerical Recipes.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x, w] = Gauss_points(n)
% Generates the abscissa and weights for a Gauss-Legendre quadrature.
% Reference: Numerical Recipes in Fortran 77, Cornell press.
x = zeros(n,1); % Preallocations.
w = x;
m = (n+1)/2;
for ii=1:m
z = cos(pi*(ii-.25)/(n+.5)); % Initial estimate.
z1 = z+1;
while abs(z-z1)>eps
p1 = 1;
p2 = 0;
for jj = 1:n
p3 = p2;
p2 = p1;
p1 = ((2*jj-1)*z*p2-(jj-1)*p3)/jj; % The Legendre polynomial.
end
pp = n*(z*p1-p2)/(z^2-1); % The L.P. derivative.
z1 = z;
z = z1-p1/pp;
end
x(ii) = -z; % Build up the abscissas.
x(n+1-ii) = z;
w(ii) = 2/((1-z^2)*(pp^2)); % Build up the weights.
w(n+1-ii) = w(ii);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




Now from the command line:

>> [W,P] = Gauss_points(2)
W =
-0.57735
0.57735
P =
1
1
 | 
Pages: 1
Prev: complicated situation :'(
Next: hazard rate shape