random numbers uniformly distributed in log space
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 23 May 2012
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 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!