random numbers uniformly distributed in log space
5 ビュー (過去 30 日間)
古いコメントを表示
Is there a function that can return n random numbers uniformly distributed in logspace?
The best solution I thought of involves randsample with logarithmic probability weights, but this is hack-y and inefficient.
Is there some input I can feed to random or some function I could apply to rand that would achieve what I want? Or, is there a known file on the file exchange that achieves this? I have searched, but to no avail.
Thanks in advance for your help.
0 件のコメント
回答 (1 件)
Walter Roberson
2012 年 5 月 23 日
log10 or ln ?
Assuming that you want the natural log of the n points to be uniformly distributed in the range A to B then
exp(A + (B-A)*rand(1,n))
Use 10.^ instead of exp() if you want log10.
Note that here A and B are expressed in log. If it is more convenient to you to have original values (e.g. 1000 instead of 3) then
LA = log(A); LB = log(B);
exp(LA + (Lb-LA) * rand(1,n))
or correspondingly
LA = log10(A); LB = log10(B);
10.^(LA + (Lb-LA) * rand(1,n))
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!