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_jacobi

function

scipy.special._orthogonal:roots_sh_jacobi

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

Signature

def roots_sh_jacobi(n, p1, q1, mu = False)

Summary

Gauss-Jacobi (shifted) quadrature.

Extended Summary

Compute the sample points and weights for Gauss-Jacobi (shifted) quadrature. The sample points are the roots of the n-th degree shifted Jacobi polynomial

These sample points and weights correctly integrate polynomials of degree or less over the interval with weight function . See 22.2.2 in [AS] for details. Note that here, in contrast to roots_sh_legendre, roots_sh_chebyt, and roots_sh_chebyu, more than just the argument is shifted.

Parameters

n : int

quadrature order.

p1 : float

(p1 - q1) must be > -1.

q1 : float

q1 must be > 0.

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

The roots and weights obtained from the shifted Chebyshev polynomials of the first and second kind are special cases of those obtained from the shifted Jacobi polynomials for :math:`p=0, q=1/2` and :math:`p=2, q=3/2`, respectively.
from scipy.special import roots_sh_chebyt, roots_sh_chebyu, roots_sh_jacobi
✓
roots_sh_jacobi(5, 0, 0.5)  # doctest: +NORMALIZE_WHITESPACE
roots_sh_chebyt(5)  # doctest: +NORMALIZE_WHITESPACE
roots_sh_jacobi(5, 2, 1.5)  # doctest: +NORMALIZE_WHITESPACE
roots_sh_chebyu(5)  # doctest: +NORMALIZE_WHITESPACE
✗
(array([0.067, 0.25 , 0.5  , 0.75 , 0.933]), array([0.033, 0.098, 0.131, 0.098, 0.033]))
Consider the specific case :math:`p=2, q=0.5`.
p, q = 2, 0.5
roots, weights, sum_of_weights = roots_sh_jacobi(5, p, q, mu=True)
✓
Verify that the values in `roots` are roots of the shifted Jacobi polynomial :math:`G^{1.5, -0.5}_5(x)`.
from scipy.special import eval_sh_jacobi
✓
eval_sh_jacobi(5, p, q, roots)
✗
array([-0., -0., -0., -0., -0.])
All values are indeed very close to zero. The sum of the weights is given by the integral from 0 to 1 of :math:`(1-x)^{p-q}x^{q-1}` which evalutes to :math:`\Gamma(q)\Gamma(p-q+1)/\Gamma(p+1)`.
sum_of_weights
from math import gamma, pi
gamma(q) * gamma(p-q+1) / gamma(p+1)
✓
1.1780972450961726
Roots and weights obtained from the shifted Jacobi polynomial :math:`G^{p, q}_n(x)` are used in Gauss-Jacobi quadrature where the integral from 0 to 1 of :math:`f(x)(1-x)^{p-q}x^{q-1}` 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.02147573103039911)
The exact result is :math:`7\pi/1024`.
7*pi/1024
✓
0.021475731030398976
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)(1-x)^{p-q}x^{q-1}`.
import numpy as np
weights @ np.cos(roots)
from scipy.integrate import quad
quad(lambda x: np.cos(x) * (1-x)**(p-q) * x**(q-1), 0, 1)
✓
(1.1421634722898315, 6.314033740295599e-10)
The two result agree better than indicated by the estimated absolute error given by the second value in the last output.

See also

scipy.integrate.fixed_quad

Aliases

  • scipy.special.js_roots