/ proof-of-concept / plate-dynamics-lab-2
Sign in
proof-of-concept / plate-dynamics-lab-2
plate-dynamics-lab-2 / packages / core / src / m / plate_gauss_legendre.m
19 lines · 616 BBlameHistoryRaw
1function [x, w] = plate_gauss_legendre(n)
2% PLATE_GAUSS_LEGENDRE Nodes and weights of n-point Gauss-Legendre quadrature on [-1, 1].
3%
4% [x, w] = plate_gauss_legendre(n) returns row vectors, nodes ascending,
5% by the Golub-Welsch method: the nodes are the eigenvalues of the
6% symmetric tridiagonal Jacobi matrix of the Legendre recurrence and the
7% weights are twice the squared first components of its eigenvectors.
9if n == 1
10 x = 0; w = 2;
11 return
12end
13k = 1:n - 1;
14b = k ./ sqrt(4 * k.^2 - 1);
15J = diag(b, 1) + diag(b, -1);
16[V, D] = eig(J);
17[x, order] = sort(diag(D)');
18w = 2 * V(1, order).^2;
19end
↑↓ move↵openescclose