bundles / scipy latest / scipy / special / _orthogonal / roots_sh_chebyu
function
scipy.special._orthogonal:roots_sh_chebyu
source: build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py:3156
Signature
def roots_sh_chebyu(n, mu = False)Summary
Gauss-Chebyshev (second kind, shifted) quadrature.
Extended Summary
Computes the sample points and weights for Gauss-Chebyshev quadrature. The sample points are the roots of the nth degree shifted 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.9 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_sh_chebyu roots, weights = roots_sh_chebyu(5)✓
roots weights✗
array([0.03272, 0.09817, 0.1309 , 0.09817, 0.03272])Verify that the values in `roots` are roots of the shifted Chebyshev polynomial of the second kind :math:`U^*_5(x)=U_5(2x-1)`.
from scipy.special import eval_chebyu, eval_sh_chebyu
✓eval_chebyu(5, 2*roots-1) eval_sh_chebyu(5, roots)✗
array([-0., -0., 0., 0., 0.])The values of :math:`U_5(2x-1)` and :math:`U^*_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:`\sqrt{x-x^2}` which evaluates to :math:`\pi/8`. There are two ways to obtain the sum of weights, both resulting in :math:`\pi/8` within numerical precision.
sum(weights) roots, weights, sum_of_weights = roots_sh_chebyu(5, mu=True) sum_of_weights from math import pi pi/8✓
0.39269908169872414Roots and weights obtained from the shifted Chebyshev polynomial of the second kind :math:`U^*_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.06442719309119692)The exact result is :math:`21\pi/1024`.
21*pi/1024
✓0.06442719309119693In 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}`.
import numpy as np weights @ np.cos(roots) from scipy.integrate import quad quad(lambda x: np.cos(x) * np.sqrt(x-x*x), 0, 1)✓
(0.3339679082866854, 1.4951873072988064e-11)The two results agree better than the estimated absolute error, i.e. the second value in the last output.
See also
Aliases
scipy.special.roots_sh_chebyu