Matlab → Simulation → Brownian Motion

The change in a variable following a Brownian motion during a small period of time is given by

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

And, the change in the value of from time 0 to is the sum of the changes in in time intervals of length , where

That is,

where 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 following a generalized Brown can be given as

Where and are constants. And, the discrete time model is given by

Similarly, the change in the value of from time 0 to is

__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 and ) 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')