Search code examples
matlabpoisson

Creating a simulation on matlab


enter image description here

I would like to write a matlab code by using this definition of poisson process

here, I want to simulate a poisson process, where n is chosen randomly between 1 and 10, lambda = 9 for 200 variates.

The codes that I wrote are totally wrong, so I cant post them, please give me a way or hint to do that. Thanks a lot.

My code is as follows:

n = randi ([1,10], 200);
lambda = 9;
t=1;
if P == (lambda * t)^n/factorial(n) * e(-lambda * t)
N = n

and

N_sum = cumsum(N);
disp(N_sum)

Solution

  • If you want to simulate the Poisson process, you can try the code below

    t = 0;
    T = 100;
    lambda = 9;
    arrTime = [];
    while true 
      t = t - log(rand)/lambda;
      if t <= T
        arrTime(end+1) = t; 
      else
        break
      end
    end 
    

    You will find the reference from https://transp-or.epfl.ch/courses/OptSim2012/slides/05b-poisson.pdf regarding how to simulate it.