# Simulating Brownian Motion in Matlab

Matlab → Simulation → Brownian Motion

The change in a variable $z$ following a Brownian motion during a small period of time $\Delta t$ is given by $\Delta z=\varepsilon\sqrt{\Delta t}$

where $\varepsilon$ has a standardized normal distribution with mean 0 and variance 1.

And, the change in the value of $z$ from time 0 to $t$ is the sum of the changes in $z$ in $n$ time intervals of length $\Delta t$, where $\Delta t=\frac{t}{n}$

That is, $z(t)-z(0)=\sum_{i=1}^{i=n}\varepsilon_i \sqrt{\Delta t}$

where $\varepsilon_i=(i=1,2,3,...,n)$ has a standardized normal distribution with mean 0 and variance 1.

Simulation of Brownian motion in Matlab
t=1; n=500; dt=t/n; z(1)=0; for i=1:n z(i+1)=z(i)+sqrt(dt)*randn; end plot([0:dt:t],z) Brownian motion can also be simulated using the cumsum command in Matlab.

t=1; n=500; dt=t/n; dz=sqrt(dt)*randn(1,n); z=cumsum(dz); plot([0:dt:t],[0,z])

Generalized Brownian Motion (Generalized Wiener Process)
A variable $x$ following a generalized Brown can be given as $dx=adt+bdz$

Where $a$ and $b$ are constants. And, the discrete time model is given by $\Delta x=a\Delta t+b\varepsilon\sqrt{\Delta t}$

Similarly, the change in the value of $x$ from time 0 to $t$ is $x(t)-x(0)=a\Delta t+b\sum_{i=0}^{i=n}\varepsilon_i\sqrt{\Delta t}$

Simulation of Generalized Brownian Motion (or Wiener Process) in Matlab
t=1; n=1000; dt=t/n; dz=sqrt(dt)*randn(1,n); dx=0.4*dt+1.8*dz; x=cumsum(dx); plot([0:dt:t],[0,x]) In the next example, Brownian motion and generalized Brownian motion (where $a=0.4$ and $b=1.8$) are plotted in the same graph.

Brownian Motion and Generalized Brownian Motion on the same graph, simulated using Matlab
t=1; n=1000; dt=t/n; dz=sqrt(dt)*randn(1,n); z=cumsum(dz); plot([0:dt:t],[0,z],'r') hold on dx=0.4*dt+1.8*dz; x=cumsum(dx); plot([0:dt:t],[0,x],'g') Posted