How to use "poissrnd" function?
Mostrar comentarios más antiguos
Hello!
I'm trying to use "poissrnd" function in order to generate an arrival of task each minute. But i use a time frame in second.
lambda = 4;
v = poissrnd(lambda, 1, 3600);
with this command , i get an arrival each second, but i want the result "task/ min"
T=3600 and taux =1 s
lambda = 4 task/ min
i will be grateful if you could find me a solution! Thank you in advance
Respuestas (1)
lambda = 4
What is the unit of lambda ? Mean number of arrivals per minute ?
And you want to get a random vector for arrivals in each second ?
Note that the "3600" in the line
v = poissrnd(lambda, 1, 3600);
has nothing to do with time units (seconds in this case). It's only the number of random values "poissrnd" should return.
25 comentarios
Maria
el 4 de Oct. de 2022
But if lambda= 4 tasks/min, you get random number of arrivals within each minute.
Or do I misunderstand something ?
lambda = 4;
v = poissrnd(lambda,10,1)
For the first minute, you get 4 arrivals. For the next minute, you get 2 arrivals. And so on.
Maria
el 4 de Oct. de 2022
this is my first result : with lambda=1/10 task/second, now i want to change lambda in each 60 second.
Here you get numbers of random arrivals for the next 10 seconds:
lambda = 0.1;
v = poissrnd(lambda,10,1).'
Here you get numbers of random arrivals for the next 10 minutes:
lambda = 0.1*60;
v = poissrnd(lambda,10,1).'
If you want to compare both, you have to generate 10*60 random arrivals for lambda = 0.1 and sum every 60 values of the vector v. Both methods simulate the same process:
lambda = 0.1;
v = poissrnd(lambda,10*60,1);
for i=1:10
w(i) = sum(v((i-1)*60+1:60*i));
end
w
And what is the meaning of the 0's in between ? I can't make sense of it.
If the rate is 0.1 tasks/sec, then the 2,5,7 ... can be generated as
lambda = 0.1*60;
v = poissrnd(lambda,10,1);
v = cumsum(v)
This gives you a random vector of arrivals within the first minute, the first 2 minutes, the first 3 minutes,...,the first 10 minutes.
Torsten
el 4 de Oct. de 2022
because the arrival of tasks each 60 second so the interval between two 60s should get "0".
That's wrong. The arrivals happen within the time span of 60 seconds, not every 60 seconds.
Maria
el 4 de Oct. de 2022
I understand your point, but it's against the concept.
The v you obtain has not '0''s in between because the idea is that people not only arrive after 60 seconds, but every second. Thus an equivalent v for arrivals every second would be
lambda = 3/60;
v = poissrnd(lambda,1,3600)
Maria
el 4 de Oct. de 2022
Maria
el 4 de Oct. de 2022
v = [v;zeros(59,60)];
v = (v(:)).'
Maria
el 4 de Oct. de 2022
You start with a value at position 1, put 59 zeros. Then you are at position 60 with the last zero. The next value will be at position 61 and you put 59 zeros. You arrive at position 120. The next value will be at position 121 ...
v = rand(1,60);
v = [v;zeros(59,60)];
v = (v(:)).';
size(v)
Maria
el 4 de Oct. de 2022
And where is the third value ? If it were at position 119, it would be consistent because 60 - 1 = 119 - 60. If it were in position 120, the distance between second and first (59) compared to the distance between third and second (60) would be different.
But it's possible:
v = rand(1,60);
m = zeros(1,3600);
m(1) = v(1);
m((1:59)*60) = v(2:60);
The code
v = rand(1,60);
m = zeros(1,3600);
m(1) = v(1);
m((1:59)*60) = v(2:60);
writes v(1) in m(1), v(2) in m(60), v(3) in m(120), ..., v(60) in m(3540) as you wanted.
All other values of m are zeros.
Maria
el 4 de Oct. de 2022
You already used all 60 for the other positions.
If you want a value at position 3600, v must be of size 61:
v = rand(1,61);
m = zeros(1,3600);
m(1) = v(1);
m((1:60)*60) = v(2:61);
All this confusion is unnecessary. The usual way is to put values at positions 1, 61, 121, ..., 3541. Then the distance between the non-zero elements is the same throughout the vector (60) and v has the usual size 1x60.
Maria
el 5 de Oct. de 2022
Categorías
Más información sobre Poisson Distribution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!