{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Example\n\nWe look for the minimum of\n$$f(x) = (x - 1)^2 + (x - 3)^2$$\nover all real $x$.\nA naive [[decomposition|KEZPDNM2NH]] splits $f$ into its two terms and minimizes each term alone.\nWe follow it and see why the recombination fails.\n\n1. The term $(x - 1)^2$ has its minimum $0$ at $x = 1$.\n2. The term $(x - 3)^2$ has its minimum $0$ at $x = 3$.\n3. The two partial answers ask for two different values of the same variable $x$, so no single $x$ gives both minima.\n4. Adding the minima gives $0 + 0 = 0$, but $f(x) = 0$ would need $x = 1$ and $x = 3$ at once, so the value $0$ is never reached.\n\nThe correct solution treats $f$ as a whole.\n\n1. Expand: $f(x) = 2x^2 - 8x + 10$.\n2. [[Complete the square|XNCV97HTZ8]]: $f(x) = 2(x - 2)^2 + 2$.\n3. So $f(x) \\ge 2$ for all $x$, with equality exactly at $x = 2$.\n\nThe minimum is $2$, at $x = 2$, and neither partial answer is the minimizer.\n\n## Remarks\n\nThe decomposition fails because the pieces are coupled: both terms depend on the same variable.\nWhen the variables are separate, the same idea works.\nThe function $g(x, y) = (x - 1)^2 + (y - 3)^2$ has its minimum $0$ at $(1, 3)$, found term by term.\n\nThe sum of the partial minima is still useful as a lower bound, since in general $\\min (u + v) \\ge \\min u + \\min v$.\nHere the bound is $0$, below the true minimum $2$.\n\nThe midpoint $x = 2$ of the partial answers is the minimizer only because the two terms have equal weight.\nFor unequal weights the guess fails:\n$$h(x) = (x - 1)^2 + 4(x - 3)^2 = 5x^2 - 26x + 37$$\nhas its minimum at $x = \\frac{13}{5} = 2.6$, with value $3.2$.\nIn general $\\sum w_i (x - a_i)^2$ with positive weights has its minimum at the weighted mean $\\frac{\\sum w_i a_i}{\\sum w_i}$.\n\n## Explanations\n\n### L1 human\n\nTwo friends live at kilometer $1$ and kilometer $3$ of a straight road, and they want to meet.\nEach friend alone would choose to meet at home, so asking each friend alone gives two answers that cannot both be used.\nThere is one meeting point for both, so the problem must be solved as one problem.\nIf the cost is the sum of the squared distances, the best point is kilometer $2$.\n\n### L2 human\n\nBefore you split an objective into pieces, test whether the pieces are independent.\nWrite the objective as a sum $u + v$ and list the variables of each piece.\nIf $u$ depends only on $x$ and $v$ only on $y$, then the minimum of $u + v$ is $\\min u + \\min v$, reached at the pair of minimizers.\nIf the pieces share a variable, as here, the partial minimizers may disagree, and the split fails.\nThen solve the coupled problem as a whole, here by completing the square, and use $\\min u + \\min v$ only as a lower bound.\n\nThe partial answers $1$ and $3$ suggest the answer $2$, which is right here only because of the equal weights.\nWith the weights $1$ and $4$ the same guess gives $2$ again, but the minimizer is $2.6$.\n",
  "commit": "35d5da104f2b90e930cd762570f4d67e50027674",
  "front": {
    "audience": "ug1",
    "kind": "example",
    "msc": [
      "00A35",
      "26A06"
    ],
    "name": "Minimizing a sum of squares term by term",
    "not_instance_of": [
      {
        "note": "the two terms share the variable x, so the partial results (minimizers x = 1 and x = 3) cannot be recombined into a minimizer of the sum",
        "target": "KEZPDNM2NH"
      }
    ],
    "sources": [
      {
        "locator": "lead section",
        "url": "https://en.wikipedia.org/wiki/Completing_the_square"
      }
    ],
    "tag": "M347T41A7J",
    "topics": [
      "X1NSTVGDNQ"
    ],
    "uses": [
      "KEZPDNM2NH",
      "XNCV97HTZ8"
    ]
  },
  "kind": "example",
  "link": "https://math2.tamnd.com/node/M347T41A7J/",
  "links": [
    {
      "field": "not_instance_of",
      "target": "KEZPDNM2NH",
      "note": "note: the two terms share the variable x, so the partial results (minimizers x = 1 and x = 3) cannot be recombined into a minimizer of the sum."
    },
    {
      "field": "topics",
      "target": "X1NSTVGDNQ"
    },
    {
      "field": "uses",
      "target": "KEZPDNM2NH"
    },
    {
      "field": "uses",
      "target": "XNCV97HTZ8"
    }
  ],
  "markdown": "https://math2.tamnd.com/node/M347T41A7J.md",
  "msc": [
    "00A35",
    "26A06"
  ],
  "name": "Minimizing a sum of squares term by term",
  "prov": {
    "log": "https://github.com/tamnd/math2/blob/main/prov/M34/M347T41A7J.jsonl",
    "quarantine": null,
    "unchecked": null
  },
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/M34/M347T41A7J.md",
  "status": null,
  "tag": "M347T41A7J",
  "uri": "m2://M347T41A7J",
  "url": "https://math2.tamnd.com/wiki/minimizing-a-sum-of-squares-term-by-term/",
  "writing": {
    "tag": "M347T41A7J",
    "kind": "example",
    "level": "W0",
    "next": [
      {
        "what": "an inventory row",
        "note": "the row of the inventory that the node accounts for",
        "have": 0,
        "want": 1
      }
    ]
  }
}
