bundles / scipy latest / scipy / special / _orthogonal / roots_genlaguerre
function
scipy.special._orthogonal:roots_genlaguerre
source: build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py:680
Signature
def roots_genlaguerre(n, alpha, mu = False)Summary
Gauss-generalized Laguerre quadrature.
Extended Summary
Compute the sample points and weights for Gauss-generalized Laguerre quadrature. The sample points are the roots of the nth degree generalized Laguerre polynomial, . These sample points and weights correctly integrate polynomials of degree or less over the interval with weight function . See 22.3.9 in [AS] for details.
Parameters
n: intquadrature order
alpha: floatalpha must be > -1
mu: bool, optionalIf True, return the sum of the weights, optional.
Returns
x: ndarraySample points
w: ndarrayWeights
mu: floatSum of the weights
Examples
from scipy.special import roots_genlaguerre roots, weights = roots_genlaguerre(5, 1.5)✓
roots weights✗
array([0.396, 0.695, 0.223, 0.015, 0. ])Verify that the values in `roots` are roots of the generalized Laguerre polynomial :math:`L^{1.5}_5(x)`.
from scipy.special import eval_genlaguerre
✓eval_genlaguerre(5, 1.5, roots)
✗array([-0., -0., 0., -0., 0.])The values of :math:`L^{1.5}_5(x)` evaluated at the roots are indeed rather close to zero. The increasing values for larger roots can be explained by the increasing derivative of the generalized Laguerre polynomial at the roots. Verify that the sum of the weights equals the integral from 0 to :math:`\infty` of :math:`x^\alpha\exp(-x)` which for :math:`\alpha=1.5` evaluates to :math:`3\sqrt{\pi}/4`. There are two ways to obtain the sum of weights, both yielding the expected result within numerical precision.
sum(weights) roots, weights, sum_of_weights = roots_genlaguerre(5, 1.5, mu=True) sum_of_weights from math import pi, sqrt 0.75*sqrt(pi)✓
1.329340388179137Roots and weights obtained from the generalized Laguerre polynomial :math:`L^\alpha_n(x)` are used in Gauss-Laguerre quadrature where the integral from 0 to :math:`\infty` of :math:`f(x)x^\alpha\exp(-x)` is evaluated. Roots and weights for order :math:`n` are expected to yield the exact result for polynomials :math:`f(x)` of a maximal order of :math:`2n-1`.
f = lambda x: x**4 weights @ f(roots)✓
np.float64(287.88527781504445)This result agrees with the exact value of :math:`10395\sqrt{\pi}/64` within numerical precision.
(10395/64)*sqrt(pi)
✓287.88527781504433In general, Gauss-Laguerre quadrature will only yield an approximate value of the integral. Consider the integral from 0 to :math:`\infty` of :math:`\cos(x)x^{1.5}\exp(-x)`.
import numpy as np
✓weights @ np.cos(roots)
✗np.float64(-0.2005673177859365)Because of the small number of nodes, this result is rather imprecise.
from scipy.integrate import quad import numpy as np✓
quad(lambda x: np.cos(x) * x**1.5 * np.exp(-x), 0, np.inf)
✗(-0.2138889584997946, 1.4800383740780929e-08)Here, the first number refers to the result while the second one gives an estimate of the absolute error. A better result can be obtained by means of Gauss-Laguerre quadrature by choosing a larger number of nodes.
roots, weights = roots_genlaguerre(50, 1.5) weights @ np.cos(roots)✓
np.float64(-0.21388895849684425)
See also
Aliases
scipy.special.la_roots