how can I generate data mixture of 2 Normal distributions and has the form f(x) = 0.4X1 + 0.6X2 where X1 ~ N(0.4 ,0.15^2) and X2 ~ N(0.7 , 0.09^2)?
11 次查看(过去 30 天)
显示 更早的评论
i need help to generate data from two mixture normal distributions of the denstiy function f(x)=0.4*x1+0.6*x2 where x1~N(0.4,0.15^2) & x2~N(0.7,0.09^2)
1 个评论
the cyclist
2018-12-21
I interpreted what you wrote a little bit differently from the math you actually wrote. Did you mean that you want there to be 40% probability that the draw is from x1, and 60% that it is from x2? (That's what I assume you meant.)
采纳的回答
the cyclist
2018-12-21
编辑:the cyclist
2018-12-21
Here is one way:
% The number of random samples to generate
N = 10000;
% First, generate a binomial variable, which 40% of the time (on average) will be equal to 1,
% and 60% of the time (on average) will be equal to zero.
frac = rand(N,1) < 0.4;
% Generate the two normal distributions to sample from
norm1 = 0.4 + 0.15*randn(N,1);
norm2 = 0.7 + 0.09*randn(N,1);
% If "frac" is equal to 1, then the choice will be from the first normal.
% If "frac" is equal to 0, then the choice will be from the second normal.
d = frac.*norm1 + (1-frac).*norm2;
% Plot the resulting distribution
figure
histogram(d)
5 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!