This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / special / _orthogonal / roots_sh_chebyt

function

scipy.special._orthogonal:roots_sh_chebyt

source: build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py:2986

Signature

def roots_sh_chebyt(n, mu = False)

Summary

Gauss-Chebyshev (first kind, shifted) quadrature.

Extended Summary

Compute the sample points and weights for Gauss-Chebyshev quadrature. The sample points are the roots of the nth degree shifted Chebyshev polynomial of the first kind, . These sample points and weights correctly integrate polynomials of degree or less over the interval with weight function . See 22.2.8 in [AS] for more details.

Parameters

n : int

quadrature order.

mu : bool, optional

If True, return the sum of the weights, optional.

Returns

x : ndarray

Sample points.

w : ndarray

Weights.

mu : float

Sum of the weights.

Examples

from scipy.special import roots_sh_chebyt
roots, weights = roots_sh_chebyt(5)
✓
roots
weights
✗
array([0.62832, 0.62832, 0.62832, 0.62832, 0.62832])
Verify that the values in `roots` are roots of the shifted Chebyshev polynomial of the first kind :math:`T^*_5(x)=T_5(2x-1)`.
from scipy.special import eval_chebyt, eval_sh_chebyt
✓
eval_chebyt(5, 2*roots-1)
eval_sh_chebyt(5, roots)
✗
array([0., 0., 0., 0., 0.])
The values of :math:`T_5(2x-1)` and of :math:`T^*_5(x)` evaluated at the roots are indeed zero or very close to it. Verify that the sum of the weights equals the integral from 0 to 1 of :math:`1/\sqrt{x-x^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_sh_chebyt(5, mu=True)
sum_of_weights
✓
3.141592653589793
Roots and weights obtained from the shifted Chebyshev polynomial of the first kind :math:`T^*_n(x)` are used in Gauss-Chebyshev quadrature where the integral from 0 to 1 of :math:`f(x)/\sqrt{x-x^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.8590292412159591)
The exact result is :math:`35\pi/128`.
from math import cos, pi
35*pi/128
✓
0.859029241215959
In general, Gauss-Chebyshev quadrature will only yield an approximate value of the integral. Consider the integral from 0 to 1 of :math:`\cos(x)/\sqrt{x-x^2}` which evaluates to :math:`\pi\cos(1/2) J_0(1/2)`, where :math:`J_0` is the Bessel function of first kind and order 0.
import numpy as np
weights @ np.cos(roots)
from scipy.special import jv
pi * cos(0.5) * jv(0, 0.5)
✓
np.float64(2.587367761551782)

See also

scipy.integrate.fixed_quad

Aliases

  • scipy.special.roots_sh_chebyt