function [x, w] = plate_gauss_legendre(n) % PLATE_GAUSS_LEGENDRE Nodes and weights of n-point Gauss-Legendre quadrature on [-1, 1]. % % [x, w] = plate_gauss_legendre(n) returns row vectors, nodes ascending, % by the Golub-Welsch method: the nodes are the eigenvalues of the % symmetric tridiagonal Jacobi matrix of the Legendre recurrence and the % weights are twice the squared first components of its eigenvectors. if n == 1 x = 0; w = 2; return end k = 1:n - 1; b = k ./ sqrt(4 * k.^2 - 1); J = diag(b, 1) + diag(b, -1); [V, D] = eig(J); [x, order] = sort(diag(D)'); w = 2 * V(1, order).^2; end