{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Statement\n\nLet $K$ be a [[field|04C5ZBG1WT]], let $n \\ge 0$, let $x_0, \\dots, x_n \\in K$ be pairwise distinct, and let $y_0, \\dots, y_n \\in K$.\nLet $p$ be the [[interpolation polynomial|SS1YMS2NPC]] of degree at most $n$ with $p(x_j) = y_j$ for all $j$.\nDefine the *barycentric weights* $w_j = \\prod_{k \\ne j} (x_j - x_k)^{-1}$ and let $\\ell(x) = \\prod_{k=0}^{n} (x - x_k)$.\nThen for every $x \\in K$ that is not a node:\n\n1. (first form) $\\displaystyle p(x) = \\ell(x) \\sum_{j=0}^{n} \\frac{w_j}{x - x_j} \\, y_j$;\n2. (second form) $\\displaystyle p(x) = \\frac{\\sum_{j=0}^{n} \\frac{w_j}{x - x_j} \\, y_j}{\\sum_{j=0}^{n} \\frac{w_j}{x - x_j}}$.\n\n## Remarks\n\nThe [[Lagrange basis polynomials|DA3CQJ5MJ6]] satisfy $\\ell_j(x) = \\ell(x) \\, w_j / (x - x_j)$, so the first form is the [[Lagrange formula|Y7KSGE97GK]] $p = \\sum_j y_j \\ell_j$ rewritten.\nApplying the first form to the constant data $y_j = 1$, whose interpolant is $1$, gives $1 = \\ell(x) \\sum_j w_j / (x - x_j)$.\nDividing the first form by this identity gives the second form.\n\nExample: nodes $0, 1$ have weights $w_0 = -1$ and $w_1 = 1$.\nThe second form gives $p(x) = \\dfrac{-y_0/x + y_1/(x - 1)}{-1/x + 1/(x - 1)} = y_0 (1 - x) + y_1 x$, the line through the data.\n\nOnce the weights are computed, in $O(n^2)$ operations, each evaluation costs $O(n)$ operations, and adding a new node updates the weights in $O(n)$ operations.\nThe weights do not depend on the data, so the same weights serve for many data sets.\n\n## Explanations\n\n### L1 human\n\nThe Lagrange formula is clear but slow to evaluate, because each basis polynomial is a long product.\nThe barycentric formula moves the common product out and keeps only simple fractions $w_j / (x - x_j)$.\nIn the second form the value $p(x)$ is a weighted average of the data, with weights that depend on $x$.\n\n### L2 human\n\nThe second form is the standard way to evaluate an interpolation polynomial in floating point arithmetic.\nFor good node families, such as [[Chebyshev nodes|HYK8J56PSH]], the weights have simple closed forms and the evaluation is numerically stable.\nUnlike the [[Newton form|9W77FPTM9E]], it needs no ordering of the nodes and no table of [[divided differences|N5ZHV4HWDC]].\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "about": [
      "Y7KSGE97GK"
    ],
    "kind": "statement",
    "msc": [
      "65D05",
      "41A05"
    ],
    "name": "Barycentric interpolation formula",
    "role": "proposition",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Lagrange_polynomial"
      }
    ],
    "tag": "TPRFJNZ7S2",
    "uses": [
      "DA3CQJ5MJ6",
      "Y7KSGE97GK",
      "SS1YMS2NPC",
      "04C5ZBG1WT"
    ]
  },
  "kind": "statement",
  "link": "https://tamnd.github.io/math2/node/TPRFJNZ7S2/",
  "links": [
    {
      "field": "about",
      "target": "Y7KSGE97GK"
    },
    {
      "field": "uses",
      "target": "DA3CQJ5MJ6"
    },
    {
      "field": "uses",
      "target": "Y7KSGE97GK"
    },
    {
      "field": "uses",
      "target": "SS1YMS2NPC"
    },
    {
      "field": "uses",
      "target": "04C5ZBG1WT"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/TPRFJNZ7S2.md",
  "msc": [
    "65D05",
    "41A05"
  ],
  "name": "Barycentric interpolation formula",
  "prov": null,
  "role": "proposition",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/TPR/TPRFJNZ7S2.md",
  "status": null,
  "tag": "TPRFJNZ7S2",
  "uri": "m2://TPRFJNZ7S2",
  "url": "https://tamnd.github.io/math2/wiki/barycentric-interpolation-formula/",
  "writing": {
    "tag": "TPRFJNZ7S2",
    "kind": "statement",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      },
      {
        "what": "a source with a locator",
        "have": 0,
        "want": 1
      }
    ]
  }
}
