{
  "aliases": null,
  "backlinks": null,
  "body": "\n## Example\n\nLet $\\xi_1, \\xi_2, \\dots$ be [[independent and identically distributed|00MRN0FARV]] random variables with $P(\\xi_n = 1) = P(\\xi_n = -1) = \\tfrac{1}{2}$.\nThe simple symmetric [[random walk|04VZE3FZXF]] on $\\Z$ is the solution of the stochastic difference equation\n$$S_{n+1} = S_n + \\xi_{n+1}, \\qquad S_0 = 0.$$\nIt has the form $X_{n+1} = f(X_n, \\xi_{n+1})$ with $f(x, e) = x + e$, so it is a [[stochastic difference equation|WPYG78BSD5]].\nSolving the recursion gives $S_n = \\xi_1 + \\cdots + \\xi_n$.\nTaking expectations in the equation gives the deterministic difference equation $E[S_{n+1}] = E[S_n]$, so $E[S_n] = 0$.\nSquaring gives $S_{n+1}^2 = S_n^2 + 2 S_n \\xi_{n+1} + 1$, and since $\\xi_{n+1}$ is independent of $S_n$ with mean $0$, $E[S_{n+1}^2] = E[S_n^2] + 1$, so $E[S_n^2] = n$.\n\nProbabilities of the walk also solve difference equations.\nFix an integer $N \\ge 1$ and let $p_j$ be the probability that the walk started at $j \\in \\set{0, \\dots, N}$ reaches $N$ before $0$.\nConditioning on the first step gives $p_j = \\tfrac{1}{2} p_{j+1} + \\tfrac{1}{2} p_{j-1}$ for $0 \u003c j \u003c N$, with $p_0 = 0$ and $p_N = 1$.\nThis linear recurrence has characteristic polynomial $(z - 1)^2$, so $p_j = a + bj$, and the boundary values give $p_j = j/N$.\n\n## Explanations\n\n### L1 human\n\nFlip a fair coin at each step and move one unit up for heads and one unit down for tails.\nYour position follows the rule: new position equals old position plus a random step.\nThat rule is a difference equation with a random term.\nIt tells you right away that you stay at $0$ on average while your typical distance grows like $\\sqrt{n}$.\nIt also gives the gambler's ruin rule: starting with $j$ euros and playing fair one-euro bets, you reach $N$ euros before going broke with probability $j/N$.\n",
  "commit": "ff8a40749dc16545e3d2fc637f6b0196e81d0bfa",
  "front": {
    "instance_of": [
      "WPYG78BSD5"
    ],
    "kind": "example",
    "msc": [
      "39A50",
      "60G50"
    ],
    "name": "Random walk as a difference equation",
    "sources": [
      {
        "url": "https://en.wikipedia.org/wiki/Random_walk"
      }
    ],
    "tag": "KA4MW1FRZ4",
    "uses": [
      "04VZE3FZXF",
      "00MRN0FARV"
    ]
  },
  "kind": "example",
  "link": "https://tamnd.github.io/math2/node/KA4MW1FRZ4/",
  "links": [
    {
      "field": "instance_of",
      "target": "WPYG78BSD5"
    },
    {
      "field": "uses",
      "target": "04VZE3FZXF"
    },
    {
      "field": "uses",
      "target": "00MRN0FARV"
    }
  ],
  "markdown": "https://tamnd.github.io/math2/node/KA4MW1FRZ4.md",
  "msc": [
    "39A50",
    "60G50"
  ],
  "name": "Random walk as a difference equation",
  "prov": null,
  "role": "",
  "source": "https://github.com/tamnd/math2/blob/main/nodes/KA4/KA4MW1FRZ4.md",
  "status": null,
  "tag": "KA4MW1FRZ4",
  "uri": "m2://KA4MW1FRZ4",
  "url": "https://tamnd.github.io/math2/wiki/random-walk-as-a-difference-equation/",
  "writing": {
    "tag": "KA4MW1FRZ4",
    "kind": "example",
    "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
      }
    ]
  }
}
