How to generate numbers from probability mass function?
显示 更早的评论
Hallo,
Given a probability mass function defined as P(X=3)=0.2, P(X=7)=0.3 and P(X=10)=0.5, I want to generate randomly 30 numbers (values for X) with this probability mass function as base. But I really have no idea how and where to start.
Can somebody help me?
Thank you in advance
采纳的回答
更多回答(3 个)
Bruno Luong
2018-10-9
A more generic method:
p = [0.2 0.3 0.5];
v = [3 7 10];
n = 10000;
c = cumsum([0,p(:).']);
c = c/c(end); % make sur the cumulative is 1
[~,i] = histc(rand(1,n),c);
r = v(i); % map to v values
Jeff Miller
2018-10-20
0 个投票
3 个评论
Clarisha Nijman
2018-10-20
Jeff Miller
2018-10-20
Did you download the Cupid files (see the link in my answer)? These define the List class (which handles the cumulative distribution behind the scene). Do the other Cupid demos run correctly?
Well, Cupid may be overkill for your problem, but it does have a lot of flexibility.
Clarisha Nijman
2018-10-20
PARTHEEBAN R
2021-5-22
0 个投票
A random variable X has cdf F(x) = { 0 , if x < − 1 a(1 + x ) , if − 1 < < 1 1 , if x ≥ 1 . Find (1) the value of a, (2) P(X > 1/4 ) and P ( − 0 . 5 ≤ X ≤ 0 ) .
类别
在 帮助中心 和 File Exchange 中查找有关 Poisson Distribution 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!