Someone please help me, I have probability mass function as follwing, How can generate 100 random values of j from this probability mass function?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
mohammed elmenshawy
il 20 Ago 2020
Modificato: Bruno Luong
il 21 Ago 2020
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/348905/image.jpeg)
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
0 Commenti
Risposta accettata
Jeff Miller
il 21 Ago 2020
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)
Più risposte (2)
KSSV
il 20 Ago 2020
- DEfine alpha and lambda values.
- DEfine j value.
- WRite your formula and substitute those values.
6 Commenti
Bruno Luong
il 21 Ago 2020
Modificato: Bruno Luong
il 21 Ago 2020
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]);
0 Commenti
Vedere anche
Categorie
Scopri di più su Systems of Nonlinear Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!