Consider two density functions
Generate random samples from a new density function for some constants and with .

2 件のコメント

Rik
Rik 2021 年 5 月 1 日
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
MD
MD 2021 年 5 月 4 日
編集済み: MD 2021 年 5 月 5 日
Now I even made the question clearer. The original question was missing some conditions.

サインインしてコメントする。

 採用された回答

James Tursa
James Tursa 2019 年 4 月 10 日
編集済み: James Tursa 2019 年 4 月 10 日

1 投票

r = rand(1,500);
Use the r values as an indicator of which distribution f or g to draw from. For those r < 0.4, generate normal random numbers from f, and generate the rest from g.
And since both f and g are normal with the same sigma of 1 but differing only in mu of 1, you could just do this (the rand( ) part simply adds a mu of 1 to those numbers to be drawn from f):
result = randn(1,500) + (rand(1,500) < 0.4);
In general, if you had two normal density functions f and g, and they had sigmas sf and sg and mus mf and mg, and you wanted to combine them with factors pf and pg (pf + pg = 1) and generate n random numbers, it would look something like this:
r = rand(1,n) < pf;
result = randn(1,n);
result(r) = result(r)*sf + mf;
result(~r) = result(~r)*sg + mg;
Or maybe someone out there knows of a function in the Statistics Toolbox that can do this.

1 件のコメント

James Tursa
James Tursa 2019 年 4 月 11 日
sf = just standard deviation, not sigma^2

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

MD
2019 年 4 月 10 日

編集済み:

MD
2021 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by