Brownian motion and the heat equation

Brownian motion where initial position has standard normal distribution
Instantaneous mean a(t,x)=0
Instantaneous variance b(t,x)=(σ^2)
PDE for density f(t,x) at time t: ((∂f)/(∂t))=((σ^2)/2)(((∂^2)f)/(∂(x^2)))

sol=NDSolve[{D[f[t,x],t]==D[f[t,x],x,x]/2,f[0,x]==1/Sqrt[2Pi]Exp[-x^2/2],f[t,-10]==0,f[t,10]==0},f,{t,0,10},{x,-10,10}]; (* (σ^2)=1 *)
Plot3D[Evaluate[f[t,x]/.First[sol]],{t,0,10},{x,-10,10},PlotPoints->50,AxesLabel->{"t","x","f(t,x)"},PlotRange->All]

Show[Table[Plot[Evaluate[f[t,x]/.First[sol]/.t->tt],{x,-10,10},PlotRange->All,PlotStyle->ColorData["DarkRainbow",1-tt/10]],{tt,0,10}]]

Brownian motion with drift, where initial position has standard normal distribution
Instantaneous mean a(t,x)=μ
Instantaneous variance b(t,x)=(σ^2)
PDE for density f(t,x) at time t: ((∂f)/(∂t))=((σ^2)/2)(((∂^2)f)/(∂(x^2)))-μ((∂f)/(∂x))
(this is the “forward equation”, while what we derived in class was the “backward equation”, which is why there is a negative sign here on the drift term of the PDE)

sol=NDSolve[{D[f[t,x],t]==D[f[t,x],x,x]/2-D[f[t,x],x],f[0,x]==1/Sqrt[2Pi]Exp[-x^2/2],f[t,-10]==0,f[t,20]==0},f,{t,0,10},{x,-10,20}];(* μ=1, (σ^2)=1 *)
Plot3D[Evaluate[f[t,x]/.First[sol]],{t,0,10},{x,-10,20},PlotPoints->50,AxesLabel->{"t","x","f(t,x)"},PlotRange->All]

Show[Table[Plot[Evaluate[f[t,x]/.First[sol]/.t->tt],{x,-10,20},PlotRange->All,PlotStyle->ColorData["DarkRainbow",1-tt/10]],{tt,0,10}]]

Ornstein-Uhlenbeck process (tends to be pulled toward origin, strength of pull proportional to distance from origin), where initial position follows random normal distribution with mean 5
Instantaneous mean a(t,x)=-βx
Instantaneous variance b(t,x)=(σ^2)
PDE for density f(t,x) at time t: ((∂f)/(∂t))=((σ^2)/2)(((∂^2)f)/(∂(x^2)))+β(∂/(∂x))(xf)

sol=NDSolve[{D[f[t,x],t]==D[f[t,x],x,x]/2+f[t,x]+x D[f[t,x],x],f[0,x]==1/Sqrt[2Pi]Exp[-(x-5)^2/2],f[t,-10]==0,f[t,10]==0},f,{t,0,10},{x,-10,10}];
Plot3D[Evaluate[f[t,x]/.First[sol]],{t,0,10},{x,-10,10},PlotPoints->50,AxesLabel->{"t","x","f(t,x)"},PlotRange->All]

Show[Table[Plot[Evaluate[f[t,x]/.First[sol]/.t->tt],{x,-4,10},PlotRange->All,PlotStyle->ColorData["DarkRainbow",1-tt/10]],{tt,0,10}]]

Diffusion approximation to branching process with mean offspring μ=1.1
(Subscript[X, n]) is size of nth generation
Instantaneous mean a(t,x)=(μ-1)x
Instantaneous variance b(t,x)=(σ^2)x
PDE for density f(t,x) at time t: ((∂f)/(∂t))=((σ^2)/2)((∂^2)/(∂(x^2)))(xf) - (μ-1)(∂/(∂x))(xf)

sol=NDSolve[{D[f[t,x],t]==D[f[t,x],x,x]/2-0.1f[t,x]-0.1x D[f[t,x],x],f[0,x]==2/Sqrt[Pi/4]Exp[-(x-1)^2*2],f[t,0]==2/Sqrt[Pi/4]Exp[-2],f[t,20]==0},f,{t,0,10},{x,0,20}];
Plot3D[Evaluate[f[t,x]/.First[sol]],{t,0,10},{x,0,20},PlotPoints->50,AxesLabel->{"t","x","f(t,x)"},PlotRange->All]

Show[Table[Plot[Evaluate[f[t,x]/.First[sol]/.t->tt],{x,0,20},PlotRange->All,PlotStyle->ColorData["DarkRainbow",1-tt/10]],{tt,0,10}]]