How do I generate a vector with random numbers based on a density function?

I'm looking for a way to generate a (1000 elements) vector of random numbers based on its density function. Here's the density function: f(x)=0.125(x-5) for 5<=x<=9 and 0 else.
Help is much appreciated!

 採用された回答

Torsten
Torsten 2016 年 6 月 1 日
編集済み: Torsten 2016 年 6 月 1 日

1 投票

v=5+4*sqrt(rand(1000,1));
gives you a vector v of 1000 random numbers based on the above density function.
Look up "Inverse Transform Technique" to see how to come up with this result.
Best wishes
Torsten.

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2016 年 6 月 1 日

コメント済み:

2016 年 6 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by