# The walk and its continuum limit
In [[MATH310F26(Day 22) - Shrinking the Plinko board|Day 22]] we built a walker that, in each step of time $\Delta t$, moves right a distance $\Delta x$ with probability $P_R$, moves left with probability $P_L$, and stays put with probability $P_0 = 1 - P_R - P_L$. Keeping track of the proportion $u$ of walkers at each location gave the balance equation
$
u(x, t+\Delta t) = P_R\,u(x-\Delta x, t) + P_0\,u(x, t) + P_L\,u(x+\Delta x, t),
$
and in [[MATH310F26(Day 23) - Transport moves, diffusion spreads|Day 23]], squinting until $\Delta x$ and $\Delta t$ were small turned it into the diffusion–transport equation
$
\frac{\partial u}{\partial t} = \frac{D}{2}\,\frac{\partial^2 u}{\partial x^2} - c\,\frac{\partial u}{\partial x},
\qquad D = (P_R + P_L)\frac{\Delta x^2}{\Delta t},
\qquad c = (P_R - P_L)\frac{\Delta x}{\Delta t}.
$
The applets on this page put the walk and the equation side by side, so you can see where they agree, where they do not, and why.
## Three views of one walk
Every walker starts at $x = 0$. The applet shows three things at once.
- **The blue bars are the walkers.** Each one flips its own three-sided coin every step, so no two runs look the same.
- **The teal curve is the balance equation, run exactly on the lattice.** There is no randomness in it. It is what an endless crowd of walkers would do.
- **The dashed magenta curve is the PDE.** Starting from $u(x,0) = \delta(x)$ it predicts the bell
$
u(x,t) = \frac{1}{\sqrt{2\pi D t}}\;e^{-(x-ct)^2/(2Dt)},
$
with mean $ct$ and variance $Dt$.
The two small plots underneath follow the mean and the variance of the position as time runs, in the same three colours.
<div class="applet" data-applet="walk-to-pde" data-scaling="off"></div>
### What to check
**The mean comes out exact.** One step moves a walker $(P_R - P_L)\Delta x$ on average, so after $n = t/\Delta t$ steps the lattice mean is $n(P_R - P_L)\Delta x = ct$, with no approximation at all. Read the three means off the readout at a few different times.
**The variance does not quite.** One step has second moment $(P_R + P_L)\Delta x^2$ and mean $(P_R - P_L)\Delta x$, so its variance is the difference $(P_R + P_L)\Delta x^2 - (P_R - P_L)^2\Delta x^2$. The steps are independent, so after $n$ of them
$
\operatorname{Var} = n\left[(P_R + P_L) - (P_R - P_L)^2\right]\Delta x^2 = Dt - c^2\,\Delta t\,t .
$
The PDE keeps the first piece and drops the second. With the Day 22 settings the gap is small, 196 against 200 at $t = 400$. Press **strong bias** and it is large, 180 against 280. The teal and magenta lines in the variance plot pull apart. Which piece of the Day 22 derivation is responsible?
**A walker that never stays.** Press **never stays**. Now $P_0 = 0$, every walker changes from an even site to an odd one (or back) every step, and only every other site is occupied. The teal curve zigzags between zero and twice the bell. The bell still describes the walkers once neighbouring sites are averaged together, which is what the histogram bars do.
**How many walkers it takes.** Lower the number of walkers to 100 and run it a few times. The bars wander around the teal curve, and the walkers' variance lands somewhere different every run. Raise it to 5000 and they settle onto it.
## Doors at both ends
This is Ex 1 from Day 23. Now the walkers start spread across an interval $0 \le x \le L$ instead of at a point, and a walker that steps onto either end walks out the door and is never seen again. Here $\Delta x = \Delta t = 1$, and $L$ is counted in sites.
<div class="applet" data-applet="doors-interval"></div>
With no drift ($P_R = P_L$, so $c = 0$) the equation is $\partial u/\partial t = \tfrac{D}{2}\,\partial^2 u/\partial x^2$, and in class we argued from the sign. Where $u$ is concave down the second derivative is negative, so $u$ decreases there. On the lattice that argument is exact, not approximate. The change over one step is the Day 22 puzzle,
$
u(x,t+\Delta t) - u(x,t) = \tfrac12(P_R + P_L)\Big[u(x-\Delta x,t) - 2u(x,t) + u(x+\Delta x,t)\Big] - \tfrac12(P_R - P_L)\Big[u(x+\Delta x,t) - u(x-\Delta x,t)\Big],
$
and with no drift only the first bracket is left. That bracket is the second difference, so the change at every site has the sign of the curvature there. The **curvature** button colours the teal curve red where it is concave down and green where it is concave up, and **change in one step** draws that change as arrows, exaggerated so you can see them.
### What to check
**Two humps.** Start from two humps and step slowly. The peaks fall and the valley between them rises, even while the doors are draining walkers out of the ends. The readout counts the sites where the curvature and the change agree.
**Add drift.** Press **drift right** with two humps. The count of agreeing sites drops, because now the second bracket, the transport term, is moving the whole profile to the right at the same time.
**The slowest mode.** Let a run go for a while. On the log scale the fraction still inside settles onto a straight line, and the slope of that line is the decay rate of the slowest mode of the PDE,
$
\lambda = \frac{D}{2}\left(\frac{\pi}{L}\right)^2 + \frac{c^2}{2D}.
$
Compare "rate right now" in the readout with this number, starting from the bow and then from the off-centre bump. Then double $L$. What happens to the time scale $1/\lambda$?
**Walls instead of doors.** Switch the ends to walls. A walker that tries to step through a wall stays where it is, so nobody leaves, and the crowd settles to a profile that no longer changes. With no drift that profile is flat. With drift the walkers pile up against one wall, spreading pushes them back, and the balance between the two is the exponential profile $\propto e^{2cx/D}$. Start from the bow behind walls with no drift and read the readout carefully. The crowd settles faster than the slowest mode says it should, and the readout says why.
**Draw your own.** Choose **draw your own** and drag across the plot to set where the walkers start. Try a profile with a sharp corner in it, and watch what the curvature does to the corner in the first few steps.
## Shrinking the board
Day 23 came with a warning label. Both coefficients have $\Delta x$ and $\Delta t$ inside them, so when the two shrink, how fast each one shrinks decides what is left. The applet below is the first one again with one more row. **halve Δx** reruns the same walk on a finer board, down to $\Delta x = 1/16$, and keeps each finished run on the plot so you can compare them. The three buttons on that row choose how $\Delta t$, and the bias, follow $\Delta x$.
| scaling | $\Delta t$ when $\Delta x$ halves | bias $P_R - P_L$ | $D$ | $c$ | what is left |
|---|---|---|---|---|---|
| $\Delta t \propto \Delta x$ | halves | stays | halves | stays | transport only, a spike sliding at speed $c$ |
| $\Delta t \propto \Delta x^2$ | quarters | stays | stays | doubles | spreading, but any bias at all runs off the board |
| $\Delta t \propto \Delta x^2$, bias $\propto \Delta x$ | quarters | halves | stays | stays | both, the whole equation |
<div class="applet" data-applet="walk-to-pde"></div>
### What to check
**The first two scalings.** With the Day 22 settings, halve $\Delta x$ three times in each of the first two modes. In the first the bell narrows toward a spike that still sits at $x = ct$. In the second it keeps its width and runs off the right edge, twice as far each time.
**The third scaling.** Press **strong bias** and use the third mode. The finished runs stack onto one curve, and the variance gap $c^2\,\Delta t\,t$ in the readout drops by a factor of four every time $\Delta x$ halves. Notice what had to happen to the walk to get there. The coin has to get closer to fair as the board gets finer, with $P_R - P_L$ shrinking like $\Delta x$. This is one honest answer to "what does small mean here", and it is the scaling under which the walk and equation (1) agree.