bundles / scipy latest / scipy / special / _orthogonal / roots_gegenbauer
function
scipy.special._orthogonal:roots_gegenbauer
source: build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py:1938
Signature
def roots_gegenbauer(n, alpha, mu = False)Summary
Gauss-Gegenbauer quadrature.
Extended Summary
Compute the sample points and weights for Gauss-Gegenbauer quadrature. The sample points are the roots of the nth degree Gegenbauer polynomial, . These sample points and weights correctly integrate polynomials of degree or less over the interval with weight function . See 22.2.3 in [AS] for more details.
Parameters
n: intquadrature order.
alpha: floatalpha must be > -0.5.
mu: bool, optionalIf True, return the sum of the weights, optional.
Returns
x: ndarraySample points
w: ndarrayWeights
mu: floatSum of the weights
Examples
Special cases of Gauss-Gegenbauer quadrature are the Gauss-Chebyshev first kind quadrature (:math:`\alpha=0`) and Gauss-Chebyshev second kind quadrature (:math:`\alpha=1`). Therefore, roots and weights obtained from `roots_gegenbauer` should agree with those obtained from `roots_chebyt` and `roots_chebyu` for the appropriate values of :math:`\alpha`.from scipy.special import roots_chebyt, roots_chebyu, roots_gegenbauer
✓roots_gegenbauer(5, 0) # doctest: +NORMALIZE_WHITESPACE roots_chebyt(5) # doctest: +NORMALIZE_WHITESPACE✗
(array([-0.951, -0.588, 0. , 0.588, 0.951]), array([0.628, 0.628, 0.628, 0.628, 0.628]))
roots_gegenbauer(5, 1) # doctest: +NORMALIZE_WHITESPACE roots_chebyu(5) # doctest: +NORMALIZE_WHITESPACE✗
(array([-0.866, -0.5 , 0. , 0.5 , 0.866]), array([0.131, 0.393, 0.524, 0.393, 0.131]))The sum of weights should equal the integral from -1 to 1 of :math:`(1-x^2)^{\alpha-1/2}` which evaluates to :math:`\sqrt{\pi}\Gamma(\alpha+1/2)/\Gamma(\alpha+1)`.
alpha = 0.7 roots, weights, sum_of_weights = roots_gegenbauer(5, alpha, mu=True) sum(weights) sum_of_weights from math import gamma, pi, sqrt sqrt(pi) * gamma(alpha+0.5) / gamma(alpha+1)✓
1.7910437497388667Roots and weights obtained from the Gegenbauer polynomial :math:`C^\alpha_n(x)` are used in Gauss-Gegenbauer quadrature where the integral from -1 to 1 of :math:`f(x)(1-x^2)^{\alpha-1/2}` 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(0.29265420747367116)This result is indeed very close to the exact value of :math:`3\sqrt{\pi}\Gamma(\alpha+1/2)/4\Gamma(\alpha+3)`.
(3*sqrt(pi)/4) * gamma(alpha+0.5) / gamma(alpha+3)
✓0.2926542074736711In general, Gauss-Gegenbauer quadrature will only yield an approximate value of the integral. Consider the integral from -1 to 1 of :math:`\cos(x)(1-x^2)^{\alpha-1/2}` which evaluates to :math:`2^\alpha\sqrt{\pi}\Gamma(\alpha+1/2)J_\alpha(1)` where :math:`J_\alpha` is the Bessel function of first kind and order :math:`\alpha`.
import numpy as np weights @ np.cos(roots) from scipy.special import jv 2**alpha * sqrt(pi) * gamma(alpha+0.5) *jv(alpha, 1)✓
np.float64(1.5395778706293377)
See also
Aliases
scipy.special.cg_roots