bundles / scipy latest / scipy / special / _orthogonal / roots_chebys
function
scipy.special._orthogonal:roots_chebys
source: build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py:2787
Signature
def roots_chebys(n, mu = False)Summary
Gauss-Chebyshev (second kind) quadrature.
Extended Summary
Compute the sample points and weights for Gauss-Chebyshev quadrature. The sample points are the roots of the nth degree Chebyshev polynomial of the second kind, . These sample points and weights correctly integrate polynomials of degree or less over the interval with weight function . See 22.2.7 in [AS] for more details.
Parameters
n: intquadrature order
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_chebys roots, weights = roots_chebys(5)✓
roots weights✗
array([0.2618, 0.7854, 1.0472, 0.7854, 0.2618])Verify that the values in `roots` are roots of the Chebyshev polynomial of first kind :math:`S_5(x)`.
from scipy.special import eval_chebys
✓eval_chebys(5, roots)
✗array([-0., -0., 0., -0., 0.])The values of :math:`S_5(x)` evaluated at the roots are indeed very close to zero. Verify that the sum of the weights equals the integral from -2 to 2 of :math:`\sqrt{1-(x/2)^2}` which evaluates to :math:`\pi`. There are two ways to obtain the sum of weights, both resulting in :math:`\pi` within numerical precision.
sum(weights) roots, weights, sum_of_weights = roots_chebys(5, mu=True) sum_of_weights✓
3.141592653589793Roots and weights obtained from the Chebyshev polynomial of the second kind :math:`S_n(x)` are used in Gauss-Chebyshev quadrature where the integral from -2 to 2 of :math:`f(x)\sqrt{1-(x/2)^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(6.283185307179585)The exact result is :math:`2\pi`.
from math import pi 2*pi✓
6.283185307179586In general, Gauss-Chebyshev quadrature will only yield an approximate value of the integral. Consider the integral from -2 to 2 of :math:`\cos(x)\sqrt{1-(x/2)^2}`.
import numpy as np weights @ np.cos(roots)✓
np.float64(1.8118352216010754)Check against the result of `scipy.integrate.quad`.
from scipy.integrate import quad result, abserror = quad(lambda x: np.cos(x) * np.sqrt(1-(x/2)**2), -2, 2) result✓
1.8118344191919165The latter result has an estimated absolute error of
abserror
✓1.5300099409643053e-08
See also
Aliases
scipy.special.roots_chebys