# Why doesn't the Diffusion Equation with an initial condition of $u = x$ lead to an even distribution?

The key is the boundary conditions.

If you do have $u(0,t)=0$ and $u(L,t)=L$ (ignoring the incorrect units here) then indeed $u(x,t)=x$ solves this differential equation with the boundary conditions, and furthermore is a steady state solution so that $\partial u/\partial t=0$. Physically, in order to keep the boundary conditions you have to have fluxes that are just right, and these fluxes will keep the steady state distribution on the interval $[0,L]$ to be $u(x,t)=x$.

However, what if we had $u(x,0)=x$ over some interval $[0,L]$ (and $0$ elsewhere) with boundary conditions $u(-\infty,t)=u(\infty,t)=0$ instead? Then we would in fact have a time varying solution. Mathematically, the second derivative starts off non-zero$^*$ at $x=0$ and $x=L$ which kicks off the time dependence. Physically, this means that we will in fact have diffusion with the distribution "smoothing out" and becoming more uniform as the particles spread out over space. In contrast to the previous case, here the boundary conditions assume no fluxes that are moving particle to keep the set boundary conditions.

Boundary conditions are usually where confusions like these pop up. Physics students tend to be more familiar with initial conditions since they are required when looking at motion described by Newton's laws. However, the initial conditions are usually stated in the solutions themselves for the easy cases one originally encounters (think of $x_0$ and $v_0$ in your kinematic equations), so students often don't realize that the given solutions solve the differential equation *with the given initial condition*.

When we move into partial differential equations dealing with both time and space, we need to consider both initial and boundary conditions. It is not enough to say "this function satisfies the partial differential equation". You have to also specify/check the initial conditions as well as the boundary conditions. However, since typically we can't find a general solution where the boundary condition is stated in the solution, the issue is harder to conceal than in the example in the previous paragraph. Hence we get (really good) questions like yours here :)

$^*$Really it's discontinuous at these points, but we could always make it smooth and then take a limit.

To complement BioPhysicist's nice discussion of the mathematical resolution to your problem, I will revise my answer to provide a physical resolution.

The diffusion equation can be thought of in two parts. If $u(x,t)$ gives the concentration of particles at the point $x$ and time $t$, then there will be a net flux of particles given by $J(x,t) = -D \frac{\partial u}{\partial x}$. This is often referred to as Fick's first law of diffusion.

To understand the physical motivation for this, you can divide your space up into small regions and consider the number of particles in each region.

If the motion of the particles is random, then we would expect that the probability that any individual particle hops into the adjacent region would be the same. If this is the case, then the *net* flow of particles between two adjacent regions will be (i) from high concentration to low concentration, and (ii) proportional to the *difference* in concentrations between the two regions. That is,

$$J_{i\rightarrow i+1} = \alpha (u_i - u_{i+1})$$

for some constant $\alpha$ which essentially defines how mobile the particles are. Taking the limit as the regions get smaller and smaller leads to Fick's first law.

Fick's *second* law says that

$$\frac{\partial u}{\partial t} + \frac{\partial J}{\partial x} = 0 \iff \frac{\partial u}{\partial t} = -\frac{dJ}{dx}$$

You may recognize this as a continuity equation - this is to reflect the fact that particles may move from region to region, but there are no points within your space where particles disappear or pop out of nowhere (though they **can** flow in or out through the boundaries!). As a result, the rate of change of the concentration in a region is due entirely to the flow of particles to/from the neighboring regions:

$$\frac{\partial }{\partial t}u_i = -\big(J_{i\rightarrow i+1} + J_{i \rightarrow i-i}\big)$$

The minus sign reflects the fact that $J_{i\rightarrow j}$ is the net flow of particles *from* region $i$ *to* region $j$. Taking the limit as the regions get smaller again yields the continuity equation, as expected.

Putting these two ideas together, we have

- Particles flow from high concentration to low concentration, with a flux proportional to $\frac{\partial u}{\partial x}$
- No particles are lost or created in the process

Mathematically, these ideas yield the diffusion equation: $$\frac{\partial u}{\partial t} = \frac{\partial}{\partial x}\left( D \frac{\partial u}{\partial x}\right) = D \frac{\partial^2 u}{\partial x^2}$$

In the last equality I've assumed that $D$ is spatially constant, but this is not always true.

But this is apparently incorrect since we have uneven distribution across the space. e.g., u(x=0)=0,u(x=100)=100. It`s a linear increments instead of an even distribution.

If $u$ is a linear function of $x$, then $J$ will be *constant*. To understand this physically, again break your space up into regions. Recall that the net flow between adjacent regions depends on the **difference** in concentration between the regions. As a result, if each region has $N$ particles more than the region to its left, then these differences will all be the same.

The number of particles entering any individual region will be the same as the number of particles leaving it, which means that the concentration in each region will be constant in time. This configuration will be supported by a constant flow of particles through your space given by $J = -D \frac{\partial u}{\partial x}$.

In the context of the heat equation (which is exactly the same as the diffusion equation), this would model a rod whose ends are held at temperatures $T(0)=0$ and $T(L)=L$, corresponding a net heat flow to the left. In the context of the diffusion equation, this would model a tube whose left end is connected to a vacuum pump and whose right end is open to the atmosphere, again with a net flow of particles to the left.