{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This method is a variant of Lagrange polynomial interpolation "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " based on "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Instead of using Lagrange's or Newton's formula, the polynomial is represented by the barycentric formula"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "p(x) =\n\\frac{\\sum_{i=1}^m\\ w_i y_i / (x - x_i)}{\\sum_{i=1}^m w_i / (x - x_i)},"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are the barycentric weights computed with the general formula"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "w_i = \\left( \\prod_{k \\neq i} x_i - x_k \\right)^{-1}."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is the same barycentric form used by "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "AAA",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.interpolate._bary_rational:AAA"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "FloaterHormannInterpolator",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.interpolate._bary_rational:FloaterHormannInterpolator"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". However, in contrast, the weights "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "w_i"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are defined such that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p(x)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a polynomial rather than a rational function."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The barycentric representation avoids many of the problems associated with polynomial interpolation caused by floating-point arithmetic. However, it does not avoid issues that are intrinsic to polynomial interpolation. Namely, if the x-coordinates are equally spaced, then the weights can be computed explicitly using the formula from "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "w_i = (-1)^i {n \\choose i},"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the number of x-coordinates. As noted in "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", this means that for large "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the weights vary by exponentially large factors, leading to the Runge phenomenon."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To avoid this ill-conditioning, the x-coordinates should be clustered at the endpoints of the interval. An excellent choice of points on the interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[a,b]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are Chebyshev points of the second kind"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "x_i = \\frac{a + b}{2} + \\frac{a - b}{2}\\cos(i\\pi/n)."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "in which case the weights can be computed explicitly as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "w_i = \\begin{cases}\n          (-1)^i/2 & i = 0,n \\\\\n          (-1)^i   & \\text{otherwise}\n      \\end{cases}."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "See "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for more infomation. Note that for large "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "n"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", computing the weights explicitly (see examples) will be faster than the generic formula."
            }
          ]
        }
      ],
      "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": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Barycentric (Lagrange with improved stability) interpolator (C∞ smooth)."
            }
          ]
        }
      ],
      "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": "xi",
              "annotation": "array_like, shape (npoints, )",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "1-D array of x-coordinates of the points the polynomial should pass through"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "yi",
              "annotation": "array_like, shape (..., npoints, ...), optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "N-D array of y-coordinates of the points the polynomial should pass through. If None, the y values will be supplied later via the "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "set_y",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method. The length of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "yi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " along the interpolation axis must be equal to the length of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "xi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Use the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " parameter to select correct axis."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "axis",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Axis in the yi array corresponding to the x-coordinate values. Defaults to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "axis=0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "wi",
              "annotation": "array_like, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The barycentric weights for the chosen interpolation points "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "xi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If absent or None, the weights will be computed from "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "xi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (default). This allows for the reuse of the weights "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "wi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " if several interpolants are being calculated using the same nodes "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "xi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", without re-computation. This also allows for computing the weights explicitly for some choices of "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "xi"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (see notes)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rng",
              "annotation": "{None, int, `numpy.random.Generator`}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is passed by keyword, types other than "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.Generator",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random._generator:Generator"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are passed to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "numpy.random.default_rng",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "numpy",
                        "version": "*",
                        "kind": "api",
                        "path": "numpy.random:default_rng"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to instantiate a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is already a "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "Generator"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " instance, then the provided instance is used. Specify "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "rng"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for repeatable interpolation."
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If this argument "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "random_state"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is passed by keyword, legacy behavior for the argument "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "random_state"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " applies:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is None (or "
                            },
                            {
                              "__type": "CrossRef",
                              "__tag": 4002,
                              "value": "numpy.random",
                              "reference": {
                                "__type": "RefInfo",
                                "__tag": 4000,
                                "module": "numpy",
                                "version": "*",
                                "kind": "api",
                                "path": "numpy.random"
                              },
                              "kind": "module"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "), the "
                            },
                            {
                              "__type": "CrossRef",
                              "__tag": 4002,
                              "value": "numpy.random.RandomState",
                              "reference": {
                                "__type": "RefInfo",
                                "__tag": 4000,
                                "module": "numpy",
                                "version": "*",
                                "kind": "api",
                                "path": "numpy.random.mtrand:RandomState"
                              },
                              "kind": "module"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "   singleton is used."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is an int, a new "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "RandomState"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " instance is used,   seeded with "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "If "
                            },
                            {
                              "__type": "ParamRef",
                              "__tag": 4071,
                              "name": "random_state"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " is already a "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "Generator"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " or "
                            },
                            {
                              "__type": "InlineCode",
                              "__tag": 4051,
                              "value": "RandomState"
                            },
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": " instance then   that instance is used."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionchanged",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionchanged 1.15.0"
                        }
                      ]
                    },
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "As part of the "
                        },
                        {
                          "__type": "Link",
                          "__tag": 4049,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "SPEC-007"
                            }
                          ],
                          "url": "https://scientific-python.org/specs/spec-0007/",
                          "title": ""
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " transition from use of "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.RandomState",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random.mtrand:RandomState"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "CrossRef",
                          "__tag": 4002,
                          "value": "numpy.random.Generator",
                          "reference": {
                            "__type": "RefInfo",
                            "__tag": 4000,
                            "module": "numpy",
                            "version": "*",
                            "kind": "api",
                            "path": "numpy.random._generator:Generator"
                          },
                          "kind": "module"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " this keyword was changed from "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " to "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": ". For an interim period, both keywords will continue to work (only specify one of them). After the interim period using the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keyword will emit warnings. The behavior of the "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "random_state"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " and "
                        },
                        {
                          "__type": "ParamRef",
                          "__tag": 4071,
                          "name": "rng"
                        },
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": " keywords is outlined above."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Constructs a polynomial that passes through a given set of points. Allows evaluation of the polynomial and all its derivatives, efficient changing of the y-values to be interpolated, and updating by adding more x- and y-values. For numerical stability, a barycentric representation is used rather than computing the coefficients of the polynomial directly."
            }
          ]
        }
      ],
      "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": "/scipy/interpolate/_polyint.py",
  "item_line": 537,
  "item_type": "class",
  "aliases": [
    "scipy.interpolate.BarycentricInterpolator"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "To produce a quintic barycentric interpolant approximating the function\n:math:`\\sin x`, and its first four derivatives, using six randomly-spaced\nnodes in :math:`(0, \\pi/2)`:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.interpolate import BarycentricInterpolator\nrng = np.random.default_rng()\nxi = rng.random(6) * np.pi/2\nf, f_d1, f_d2, f_d3, f_d4 = np.sin, np.cos, lambda x: -np.sin(x), lambda x: -np.cos(x), np.sin\nP = BarycentricInterpolator(xi, f(xi), random_state=rng)\nfig, axs = plt.subplots(5, 1, sharex=True, layout='constrained', figsize=(7,10))\nx = np.linspace(0, np.pi, 100)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "axs[0].plot(x, P(x), 'r:', x, f(x), 'k--', xi, f(xi), 'xk')\naxs[1].plot(x, P.derivative(x), 'r:', x, f_d1(x), 'k--', xi, f_d1(xi), 'xk')\naxs[2].plot(x, P.derivative(x, 2), 'r:', x, f_d2(x), 'k--', xi, f_d2(xi), 'xk')\naxs[3].plot(x, P.derivative(x, 3), 'r:', x, f_d3(x), 'k--', xi, f_d3(xi), 'xk')\naxs[4].plot(x, P.derivative(x, 4), 'r:', x, f_d4(x), 'k--', xi, f_d4(xi), 'xk')\naxs[0].set_xlim(0, np.pi)\naxs[4].set_xlabel(r\"$x$\")\naxs[4].set_xticks([i * np.pi / 4 for i in range(5)],\n                  [\"0\", r\"$\\frac{\\pi}{4}$\", r\"$\\frac{\\pi}{2}$\", r\"$\\frac{3\\pi}{4}$\", r\"$\\pi$\"])\nfor ax, label in zip(axs, (\"$f(x)$\", \"$f'(x)$\", \"$f''(x)$\", \"$f^{(3)}(x)$\", \"$f^{(4)}(x)$\")):\n    ax.set_ylabel(label)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "labels = ['Interpolation nodes', 'True function $f$', 'Barycentric interpolation']\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "axs[0].legend(axs[0].get_lines()[::-1], labels, bbox_to_anchor=(0., 1.02, 1., .102),\n              loc='lower left', ncols=3, mode=\"expand\", borderaxespad=0., frameon=False)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-a96c7e332af9a9b8.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nNext, we show how using Chebyshev points of the second kind avoids the\nRunge phenomenon. In this example, we also compute the weights explicitly.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "n = 20\ndef f(x): return np.abs(x) + 0.5*x - x**2\ni = np.arange(n)\nx_cheb = np.cos(i*np.pi/(n - 1))  # Chebyshev points on [-1, 1]\nw_i_cheb = (-1.)**i  # Explicit formula for weights of Chebyshev points\nw_i_cheb[[0, -1]] /= 2\np_cheb = BarycentricInterpolator(x_cheb, f(x_cheb), wi=w_i_cheb)\nx_equi = np.linspace(-1, 1, n)\np_equi = BarycentricInterpolator(x_equi, f(x_equi))\nxx = np.linspace(-1, 1, 1000)\nfig, ax = plt.subplots()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(xx, f(xx), label=\"Original Function\")\nax.plot(xx, p_cheb(xx), \"--\", label=\"Chebshev Points\")\nax.plot(xx, p_equi(xx), \"--\", label=\"Equally Spaced Points\")\nax.set(xlabel=\"$x$\", ylabel=\"$f(x)$\", xlim=[-1, 1])\nax.legend()\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-5109b4a02cb7e58b.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "xi",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "yi",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "axis",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "wi",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rng",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "random_state",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "BarycentricInterpolator"
  },
  "references": [
    ".. [1] https://en.wikipedia.org/wiki/Lagrange_polynomial",
    ".. [2] Jean-Paul Berrut and Lloyd N. Trefethen, \"Barycentric Lagrange",
    "       Interpolation\", SIAM Review 2004 46:3, 501-517",
    "       :doi:`10.1137/S0036144502417715`"
  ],
  "qa": "scipy.interpolate._polyint:BarycentricInterpolator",
  "arbitrary": [],
  "local_refs": [
    "axis",
    "rng",
    "wi",
    "xi",
    "yi"
  ]
}