Someone please help me, I have probability mass function as follwing, How can generate 100 random values of j from this probability mass function?

Note: λ>0 and 0≤α≤1/2 and 0≤P(X=j)≤1. (Take initial valus for λ, α and p(X=j) from thir domain as you like as example)
I want to generate randomly 100 numbers (values for j) with this probability mass function . But I really have no idea how and where to start.
Can somebody help me?
Thank you in advance

 Akzeptierte Antwort

If you would like to generate 100 random j values, use the function KSSV gave you to generate the f values for the probability masses (they are not all 0's after the for loop, only before it). Then:
sump = cumsum(f);
r_unif = rand(100,1);
r_j = zeros(100,1);
for i=1:100
r_j(i) = find(sump>r_unif(i),1);
end
figure;
histogram(r_j)

Weitere Antworten (2)

  1. DEfine alpha and lambda values.
  2. DEfine j value.
  3. WRite your formula and substitute those values.

6 Kommentare

sorry, I ask about j value ?
Meanning, i have λ, α and f(j) and ask about j value ?
If possible, I will change the value of f(j) only "but in its range" to get a new value for j and so on until I get to 100 values of j.
i write this (a means α and ld means λ )
syms j;
a=0.3; ld=0.5;
f=((1-a)^j-(-a)^j)*ld^j* exp(ld*a)/(factorial(j)*(exp(ld)-1));
J=solve(f,j);
"i want solve it when f equal for example 0.8"
Hope you understood what I mean..thanks very much for your help
a = 0.3 ; ld = 0.5;
% f = 0.8 ;
f = zeros(1,100)
for j = 1:100
f(j) = ((1-a)^j-(-a)^j)*ld^j* exp(ld*a)/(factorial(j)*(exp(ld)-1)) ;
end
The result is all zeros, which is illogical here..
secondly, i want j value not f . "f is input and j which output"
Firs few values are significant..rest are very small. Can you share the reference where you have this formula?
Thank you very much for your cooperation.

Melden Sie sich an, um zu kommentieren.

alpha=0.01; lambda=0.99;
f=@(j) ((1-alpha).^j-(-alpha).^j).*lambda.^j*exp(lambda*alpha)./(factorial(j)*(exp(lambda)-1));
p=f(1:22); % f is practically 0 beyond 10
c=cumsum(p); c=c/c(end);
n = 100; % 1e6;
[~,j] = histc(rand(1,n),[0 c]);

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by