{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sample points"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "w",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Weights"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "mu",
              "annotation": "float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Sum of the weights"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Gauss-Gegenbauer quadrature."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "n",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "quadrature order."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "alpha",
              "annotation": "float",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "alpha must be > -0.5."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "mu",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True, return the sum of the weights, optional."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the sample points and weights for Gauss-Gegenbauer quadrature. The sample points are the roots of the nth degree Gegenbauer polynomial, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "C^{\\alpha}_n(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". These sample points and weights correctly integrate polynomials of degree "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2n - 1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " or less over the interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[-1, 1]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with weight function "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w(x) = (1 - x^2)^{\\alpha - 1/2}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". See 22.2.3 in "
            },
            {
              "__type": "CitationReference",
              "__tag": 4063,
              "label": "AS"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for more details."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "build-install/usr/lib/python3.14/site-packages/scipy/special/_orthogonal.py",
  "item_line": 1938,
  "item_type": "function",
  "aliases": [
    "scipy.special.cg_roots"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "Special cases of Gauss-Gegenbauer quadrature are the Gauss-Chebyshev\nfirst kind quadrature (:math:`\\alpha=0`) and Gauss-Chebyshev second\nkind quadrature (:math:`\\alpha=1`). Therefore, roots and weights obtained\nfrom `roots_gegenbauer` should agree with those obtained from `roots_chebyt`\nand `roots_chebyu` for the appropriate values of :math:`\\alpha`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.special import roots_chebyt, roots_chebyu, roots_gegenbauer\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "roots_gegenbauer(5, 0)  # doctest: +NORMALIZE_WHITESPACE\nroots_chebyt(5)  # doctest: +NORMALIZE_WHITESPACE\n",
        "execution_status": "failure",
        "out": "(array([-0.951, -0.588,  0.   ,  0.588,  0.951]), array([0.628, 0.628, 0.628, 0.628, 0.628]))\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "roots_gegenbauer(5, 1)  # doctest: +NORMALIZE_WHITESPACE\nroots_chebyu(5)  # doctest: +NORMALIZE_WHITESPACE\n",
        "execution_status": "failure",
        "out": "(array([-0.866, -0.5  ,  0.   ,  0.5  ,  0.866]), array([0.131, 0.393, 0.524, 0.393, 0.131]))\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe sum of weights should equal the integral from -1 to 1 of\n:math:`(1-x^2)^{\\alpha-1/2}` which evaluates to\n:math:`\\sqrt{\\pi}\\Gamma(\\alpha+1/2)/\\Gamma(\\alpha+1)`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "alpha = 0.7\nroots, weights, sum_of_weights = roots_gegenbauer(5, alpha, mu=True)\nsum(weights)\nsum_of_weights\nfrom math import gamma, pi, sqrt\nsqrt(pi) * gamma(alpha+0.5) / gamma(alpha+1)\n",
        "execution_status": "success",
        "out": "1.7910437497388667\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nRoots and weights obtained from the Gegenbauer polynomial :math:`C^\\alpha_n(x)`\nare used in Gauss-Gegenbauer quadrature where the integral from -1 to 1 of\n:math:`f(x)(1-x^2)^{\\alpha-1/2}` is evaluated. Roots and weights for order\n:math:`n` are expected to yield the exact result for polynomials :math:`f(x)`\nof a maximal order of :math:`2n-1`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "f = lambda x: x**4\nweights @ f(roots)\n",
        "execution_status": "success",
        "out": "np.float64(0.29265420747367116)\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThis result is indeed very close to the exact value of\n:math:`3\\sqrt{\\pi}\\Gamma(\\alpha+1/2)/4\\Gamma(\\alpha+3)`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "(3*sqrt(pi)/4) * gamma(alpha+0.5) / gamma(alpha+3)\n",
        "execution_status": "success",
        "out": "0.2926542074736711\n"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nIn general, Gauss-Gegenbauer quadrature will only yield an approximate value of\nthe integral. Consider the integral from -1 to 1 of\n:math:`\\cos(x)(1-x^2)^{\\alpha-1/2}` which evaluates to\n:math:`2^\\alpha\\sqrt{\\pi}\\Gamma(\\alpha+1/2)J_\\alpha(1)` where :math:`J_\\alpha`\nis the Bessel function of first kind and order :math:`\\alpha`.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nweights @ np.cos(roots)\nfrom scipy.special import jv\n2**alpha * sqrt(pi) * gamma(alpha+0.5) *jv(alpha, 1)\n",
        "execution_status": "success",
        "out": "np.float64(1.5395778706293377)\n"
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "scipy.integrate.fixed_quad",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.integrate._quadrature:fixed_quad"
        },
        "kind": "module"
      },
      "descriptions": [],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "n",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "alpha",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "mu",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "roots_gegenbauer"
  },
  "references": [
    ".. [AS] Milton Abramowitz and Irene A. Stegun, eds.",
    "    Handbook of Mathematical Functions with Formulas,",
    "    Graphs, and Mathematical Tables. New York: Dover, 1972."
  ],
  "qa": "scipy.special._orthogonal:roots_gegenbauer",
  "arbitrary": [],
  "local_refs": [
    "alpha",
    "mu",
    "n",
    "w",
    "x"
  ]
}