Simulating a random walk

Oscar Nieves
4 min readJul 13, 2021

with the power of stochastic modelling and MATLAB.

Figure 1: Multiple independent random walks using a normal distribution

Prerequisites

In order to follow along this tutorial, you will need to be familiar with basic probability and statistics, and concepts such as mean, variance, standard deviation, random variables (discrete and/or continuous), and the notion of the normal distribution (e.g. Gaussian distribution). Some knowledge of programming (particularly in Matlab) is advised, but not entirely necessary.

Simple random walks

A random walk is one of the most basic types of stochastic processes we can simulate. Essentially, it is a discrete process by which the position of a particle or object, denoted by x in n -dimensional space; is updated by adding a random vector Δr. In simple words, we can numerically construct a random walk by using a recursive equation like this one:

Here, the term

Is a random variable sampled at each integer n. There are many forms which this variable can take, it could be a normal random variable or a Poisson variable or even a uniform random variable. The choice is up to us. However. we must choose what best suits our required application. For instance, if you want to model random walks that looks like what is called a “Brownian motion” (which is basically the zig-zaggy nature of a lot of stochastic processes in…

--

--

Oscar Nieves
Oscar Nieves

Written by Oscar Nieves

I write stories about applied math, physics and engineering.